|
| 1 | +package org.kunlab.scenamatica.nms.types.entity; |
| 2 | + |
| 3 | +import javax.annotation.Nullable; |
| 4 | +import lombok.Getter; |
| 5 | +import org.bukkit.entity.Arrow; |
| 6 | +import org.bukkit.entity.Entity; |
| 7 | +import org.bukkit.entity.Fireball; |
| 8 | +import org.bukkit.entity.Firework; |
| 9 | +import org.bukkit.entity.HumanEntity; |
| 10 | +import org.bukkit.entity.LivingEntity; |
| 11 | +import org.bukkit.entity.Player; |
| 12 | +import org.bukkit.entity.WitherSkull; |
| 13 | +import org.bukkit.util.Vector; |
| 14 | +import org.kunlab.scenamatica.nms.NMSElement; |
| 15 | + |
| 16 | +/** |
| 17 | + * NMSコンテキストにおけるダメージソースを表します。 |
| 18 | + * このインターフェースは、ダメージソースの様々なプロパティを操作およびクエリするためのメソッドを提供します。 |
| 19 | + */ |
| 20 | +@Getter |
| 21 | +public class NMSDamageSource implements NMSElement |
| 22 | +{ |
| 23 | + public static final String ARROW_TYPE = "arrow"; |
| 24 | + public static final String CACTUS_TYPE = "cactus"; |
| 25 | + public static final String CRAMMING_TYPE = "cramming"; |
| 26 | + public static final String DRAGON_BREATH_TYPE = "dragonBreath"; |
| 27 | + public static final String DROWN_TYPE = "drown"; |
| 28 | + public static final String DRYOUT_TYPE = "dryout"; |
| 29 | + public static final String EXPLOSION_PLAYER_TYPE = "explosion.player"; |
| 30 | + public static final String EXPLOSION_TYPE = "explosion"; |
| 31 | + public static final String FALL_TYPE = "fall"; |
| 32 | + public static final String FALLING_BLOCK_TYPE = "fallingBlock"; |
| 33 | + public static final String FALLING_STALACTITE_TYPE = "fallingStalactite"; |
| 34 | + public static final String FIREBALL_TYPE = "fireball"; |
| 35 | + public static final String FIREWORKS_TYPE = "fireworks"; |
| 36 | + public static final String FLY_INTO_WALL_TYPE = "flyIntoWall"; |
| 37 | + public static final String FREEZE_TYPE = "freeze"; |
| 38 | + public static final String GENERIC_TYPE = "generic"; |
| 39 | + public static final String HOT_FLOOR_TYPE = "hotFloor"; |
| 40 | + public static final String IN_FIRE_TYPE = "inFire"; |
| 41 | + public static final String IN_WALL_TYPE = "inWall"; |
| 42 | + public static final String INDIRECT_MAGIC_TYPE = "indirectMagic"; |
| 43 | + public static final String LAVA_TYPE = "lava"; |
| 44 | + public static final String LIGHTNING_BOLT_TYPE = "lightningBolt"; |
| 45 | + public static final String MAGIC_TYPE = "magic"; |
| 46 | + public static final String MOB_TYPE = "mob"; |
| 47 | + public static final String ON_FIRE_TYPE = "onFire"; |
| 48 | + public static final String OUT_OF_WORLD_TYPE = "outOfWorld"; |
| 49 | + public static final String PLAYER_TYPE = "player"; |
| 50 | + public static final String STALAGMITE_TYPE = "stalagmite"; |
| 51 | + public static final String STARVE_TYPE = "starve"; |
| 52 | + public static final String STING_TYPE = "sting"; |
| 53 | + public static final String SWEET_BERRY_BUSH_TYPE = "sweetBerryBush"; |
| 54 | + public static final String THORNS_TYPE = "thorns"; |
| 55 | + public static final String THROWN_TYPE = "thrown"; |
| 56 | + public static final String TRIDENT_TYPE = "trident"; |
| 57 | + public static final String WITHER_SKULL_TYPE = "witherSkull"; |
| 58 | + public static final String WITHER_TYPE = "wither"; |
| 59 | + |
| 60 | + public static final NMSDamageSource CACTUS = new NMSDamageSource(CACTUS_TYPE); |
| 61 | + public static final NMSDamageSource CRAMMING = new NMSDamageSource(CRAMMING_TYPE); |
| 62 | + public static final NMSDamageSource DRAGON_BREATH = new NMSDamageSource(DRAGON_BREATH_TYPE).bypassArmor().bypassMagic(); |
| 63 | + public static final NMSDamageSource DROWN = new NMSDamageSource(DROWN_TYPE); |
| 64 | + public static final NMSDamageSource DRYOUT = new NMSDamageSource(DRYOUT_TYPE); |
| 65 | + public static final NMSDamageSource FALL = new NMSDamageSource(FALL_TYPE).isFall(); |
| 66 | + public static final NMSDamageSource FALLING_BLOCK = new NMSDamageSource(FALLING_BLOCK_TYPE); |
| 67 | + public static final NMSDamageSource FALLING_STALACTITE = new NMSDamageSource(FALLING_STALACTITE_TYPE).isFall(); |
| 68 | + public static final NMSDamageSource FLY_INTO_WALL = new NMSDamageSource(FLY_INTO_WALL_TYPE); |
| 69 | + public static final NMSDamageSource FREEZE = new NMSDamageSource(FREEZE_TYPE).bypassArmor().bypassMagic(); |
| 70 | + public static final NMSDamageSource GENERIC = new NMSDamageSource(GENERIC_TYPE); |
| 71 | + public static final NMSDamageSource HOT_FLOOR = new NMSDamageSource(HOT_FLOOR_TYPE).isFire(); |
| 72 | + public static final NMSDamageSource IN_FIRE = new NMSDamageSource(IN_FIRE_TYPE).isFire(); |
| 73 | + public static final NMSDamageSource IN_WALL = new NMSDamageSource(IN_WALL_TYPE); |
| 74 | + public static final NMSDamageSource LAVA = new NMSDamageSource(LAVA_TYPE).isFire(); |
| 75 | + public static final NMSDamageSource LIGHTNING_BOLT = new NMSDamageSource(LIGHTNING_BOLT_TYPE); |
| 76 | + public static final NMSDamageSource MAGIC = new NMSDamageSource(MAGIC_TYPE).bypassArmor().bypassMagic(); |
| 77 | + public static final NMSDamageSource ON_FIRE = new NMSDamageSource(ON_FIRE_TYPE).isFire(); |
| 78 | + public static final NMSDamageSource OUT_OF_WORLD = new NMSDamageSource(OUT_OF_WORLD_TYPE).bypassArmor().bypassInvul(); |
| 79 | + public static final NMSDamageSource STALAGMITE = new NMSDamageSource(STALAGMITE_TYPE).isFall(); |
| 80 | + public static final NMSDamageSource STARVE = new NMSDamageSource(STARVE_TYPE).bypassArmor().bypassMagic(); |
| 81 | + public static final NMSDamageSource SWEET_BERRY_BUSH = new NMSDamageSource(SWEET_BERRY_BUSH_TYPE); |
| 82 | + public static final NMSDamageSource WITHER = new NMSDamageSource(WITHER_TYPE).bypassArmor().bypassMagic(); |
| 83 | + |
| 84 | + private final String damageType; |
| 85 | + |
| 86 | + private boolean damageHelmet; |
| 87 | + private boolean bypassArmor; |
| 88 | + private boolean bypassInvul; |
| 89 | + private boolean bypassMagic; |
| 90 | + private float exhaustion = 0.1F; |
| 91 | + private boolean isFireSource; |
| 92 | + private boolean isProjectile; |
| 93 | + private boolean scalesWithDifficulty; |
| 94 | + private boolean isMagic; |
| 95 | + private boolean isExplosion; |
| 96 | + private boolean isFall; |
| 97 | + private boolean noAggro; |
| 98 | + private Entity directEntity; |
| 99 | + private Entity entity; |
| 100 | + private Vector sourcePosition; |
| 101 | + |
| 102 | + public NMSDamageSource(String damageType) |
| 103 | + { |
| 104 | + this.damageType = damageType; |
| 105 | + } |
| 106 | + |
| 107 | + public static NMSDamageSource arrow(Arrow arrow, @Nullable Entity shooter) |
| 108 | + { |
| 109 | + return new NMSDamageSource(ARROW_TYPE).entity(arrow).directEntity(shooter).projectile(); |
| 110 | + } |
| 111 | + |
| 112 | + public static NMSDamageSource explosion(@Nullable LivingEntity entity) |
| 113 | + { |
| 114 | + return entity != null ? new NMSDamageSource(EXPLOSION_PLAYER_TYPE).entity(entity).scalesWithDifficulty().explosion(): new NMSDamageSource(EXPLOSION_TYPE).scalesWithDifficulty().explosion(); |
| 115 | + } |
| 116 | + |
| 117 | + public static NMSDamageSource fireball(Fireball fireball, @Nullable Entity shooter) |
| 118 | + { |
| 119 | + return new NMSDamageSource(FIREBALL_TYPE).entity(fireball).directEntity(shooter).isFire().projectile(); |
| 120 | + } |
| 121 | + |
| 122 | + public static NMSDamageSource fireworks(Firework firework, @Nullable Entity shooter) |
| 123 | + { |
| 124 | + return new NMSDamageSource(FIREWORKS_TYPE).entity(firework).directEntity(shooter).explosion(); |
| 125 | + } |
| 126 | + |
| 127 | + public static NMSDamageSource indirectMagic(Entity magic, @Nullable Entity shooter) |
| 128 | + { |
| 129 | + return new NMSDamageSource(INDIRECT_MAGIC_TYPE).entity(magic).directEntity(shooter).bypassArmor().magic(); |
| 130 | + } |
| 131 | + |
| 132 | + public static NMSDamageSource indirectMobAttack(Entity entity, @Nullable LivingEntity indirectEntity) |
| 133 | + { |
| 134 | + return new NMSDamageSource(MOB_TYPE).entity(entity).directEntity(indirectEntity); |
| 135 | + } |
| 136 | + |
| 137 | + public static NMSDamageSource mobAttack(LivingEntity entity) |
| 138 | + { |
| 139 | + return new NMSDamageSource(MOB_TYPE).entity(entity); |
| 140 | + } |
| 141 | + |
| 142 | + public static NMSDamageSource playerAttack(Player player) |
| 143 | + { |
| 144 | + return new NMSDamageSource(PLAYER_TYPE).entity(player); |
| 145 | + } |
| 146 | + |
| 147 | + public static NMSDamageSource anyEntityAttack(Entity entity) |
| 148 | + { |
| 149 | + if (entity instanceof HumanEntity) |
| 150 | + return playerAttack((Player) entity); |
| 151 | + else if (entity instanceof LivingEntity) |
| 152 | + return mobAttack((LivingEntity) entity); |
| 153 | + else |
| 154 | + return new NMSDamageSource(GENERIC_TYPE).entity(entity); |
| 155 | + } |
| 156 | + |
| 157 | + public static NMSDamageSource sting(LivingEntity entity) |
| 158 | + { |
| 159 | + return new NMSDamageSource(STING_TYPE).entity(entity); |
| 160 | + } |
| 161 | + |
| 162 | + public static NMSDamageSource thorns(Entity entity) |
| 163 | + { |
| 164 | + return new NMSDamageSource(THORNS_TYPE).entity(entity).magic(); |
| 165 | + } |
| 166 | + |
| 167 | + public static NMSDamageSource thrown(Entity thrown, @Nullable Entity shooter) |
| 168 | + { |
| 169 | + return new NMSDamageSource(THROWN_TYPE).entity(thrown).directEntity(shooter).projectile(); |
| 170 | + } |
| 171 | + |
| 172 | + public static NMSDamageSource trident(Entity trident, @Nullable Entity shooter) |
| 173 | + { |
| 174 | + return new NMSDamageSource(TRIDENT_TYPE).entity(trident).directEntity(shooter).projectile(); |
| 175 | + } |
| 176 | + |
| 177 | + public static NMSDamageSource witherSkull(WitherSkull witherSkull, Entity shooter) |
| 178 | + { |
| 179 | + return new NMSDamageSource(WITHER_SKULL_TYPE).entity(witherSkull).directEntity(shooter).projectile(); |
| 180 | + } |
| 181 | + |
| 182 | + public NMSDamageSource damageHelmet() |
| 183 | + { |
| 184 | + this.damageHelmet = true; |
| 185 | + return this; |
| 186 | + } |
| 187 | + |
| 188 | + public NMSDamageSource bypassArmor() |
| 189 | + { |
| 190 | + this.bypassArmor = true; |
| 191 | + this.exhaustion = 0.0F; |
| 192 | + return this; |
| 193 | + } |
| 194 | + |
| 195 | + public NMSDamageSource bypassInvul() |
| 196 | + { |
| 197 | + this.bypassInvul = true; |
| 198 | + return this; |
| 199 | + } |
| 200 | + |
| 201 | + public NMSDamageSource bypassMagic() |
| 202 | + { |
| 203 | + this.bypassMagic = true; |
| 204 | + this.exhaustion = 0.0F; |
| 205 | + return this; |
| 206 | + } |
| 207 | + |
| 208 | + public NMSDamageSource isFire() |
| 209 | + { |
| 210 | + this.isFireSource = true; |
| 211 | + return this; |
| 212 | + } |
| 213 | + |
| 214 | + public NMSDamageSource projectile() |
| 215 | + { |
| 216 | + this.isProjectile = true; |
| 217 | + return this; |
| 218 | + } |
| 219 | + |
| 220 | + public NMSDamageSource explosion() |
| 221 | + { |
| 222 | + this.isExplosion = true; |
| 223 | + return this; |
| 224 | + } |
| 225 | + |
| 226 | + public NMSDamageSource isFall() |
| 227 | + { |
| 228 | + this.isFall = true; |
| 229 | + return this; |
| 230 | + } |
| 231 | + |
| 232 | + public NMSDamageSource noAggro() |
| 233 | + { |
| 234 | + this.noAggro = true; |
| 235 | + return this; |
| 236 | + } |
| 237 | + |
| 238 | + public NMSDamageSource scalesWithDifficulty() |
| 239 | + { |
| 240 | + this.scalesWithDifficulty = true; |
| 241 | + return this; |
| 242 | + } |
| 243 | + |
| 244 | + public NMSDamageSource magic() |
| 245 | + { |
| 246 | + this.isMagic = true; |
| 247 | + return this; |
| 248 | + } |
| 249 | + |
| 250 | + public NMSDamageSource directEntity(Entity directEntity) |
| 251 | + { |
| 252 | + this.directEntity = directEntity; |
| 253 | + return this; |
| 254 | + } |
| 255 | + |
| 256 | + public NMSDamageSource entity(Entity entity) |
| 257 | + { |
| 258 | + this.entity = entity; |
| 259 | + return this; |
| 260 | + } |
| 261 | + |
| 262 | + public NMSDamageSource sourcePosition(Vector sourcePosition) |
| 263 | + { |
| 264 | + this.sourcePosition = sourcePosition; |
| 265 | + return this; |
| 266 | + } |
| 267 | + |
| 268 | + @Nullable |
| 269 | + public Entity getDirectEntity() |
| 270 | + { |
| 271 | + return this.directEntity; |
| 272 | + } |
| 273 | + |
| 274 | + @Nullable |
| 275 | + public Entity getEntity() |
| 276 | + { |
| 277 | + return this.entity; |
| 278 | + } |
| 279 | + |
| 280 | + @Nullable |
| 281 | + public Vector getSourcePosition() |
| 282 | + { |
| 283 | + return this.sourcePosition; |
| 284 | + } |
| 285 | +} |
0 commit comments