diff options
author | Andrew Ardill <andrew.ardill@gmail.com> | 2011-11-29 18:10:05 +1100 |
---|---|---|
committer | Andrew Ardill <andrew.ardill@gmail.com> | 2011-11-29 18:20:21 +1100 |
commit | 3da00ee41adf0ecfc31d5c330c281a8d5fe8a7b1 (patch) | |
tree | f9fff4196425ff33ceccd6c29a79df97ce253c91 /src/main/java/net/minecraft/server | |
parent | 0c88f05c0da5e5f4a4dbd9be3ccbe2482e7b2f79 (diff) | |
download | craftbukkit-3da00ee41adf0ecfc31d5c330c281a8d5fe8a7b1.tar craftbukkit-3da00ee41adf0ecfc31d5c330c281a8d5fe8a7b1.tar.gz craftbukkit-3da00ee41adf0ecfc31d5c330c281a8d5fe8a7b1.tar.lz craftbukkit-3da00ee41adf0ecfc31d5c330c281a8d5fe8a7b1.tar.xz craftbukkit-3da00ee41adf0ecfc31d5c330c281a8d5fe8a7b1.zip |
Implementation of reworked EntityCombustEvents
Also includes some extra comments, and a refactoring of the
PaintingBreakByEntity event that is raised when lighting strikes a painting.
Diffstat (limited to 'src/main/java/net/minecraft/server')
5 files changed, 46 insertions, 34 deletions
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 512afdca..8cf70538 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -8,7 +8,11 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.block.BlockFace; import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Painting; import org.bukkit.entity.Vehicle; +import org.bukkit.event.entity.EntityCombustByBlockEvent; +import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.painting.PaintingBreakByEntityEvent; import org.bukkit.event.vehicle.VehicleBlockCollisionEvent; import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.craftbukkit.entity.CraftPlayer; @@ -16,6 +20,7 @@ import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.plugin.PluginManager; // CraftBukkit end public abstract class Entity { @@ -300,7 +305,7 @@ public abstract class Entity { protected void av() { if (!this.fireProof) { - // CraftBukkit start - TODO: this event spams! + // CraftBukkit start - fallen in lava TODO: this event spams! if (this instanceof EntityLiving) { org.bukkit.Server server = this.world.getServer(); @@ -317,18 +322,19 @@ public abstract class Entity { if (this.fireTicks <= 0) { // not on fire yet - EntityCombustEvent combustEvent = new EntityCombustEvent(damagee); + EntityCombustEvent combustEvent = new EntityCombustByBlockEvent(damager, damagee, 15); server.getPluginManager().callEvent(combustEvent); if (!combustEvent.isCancelled()) { - this.j(15); + this.j(combustEvent.getDuration()); } } else { + // This will be called every single tick the entity is in lava, so don't throw an event. this.j(15); } return; } - // CraftBukkit end + // CraftBukkit end - we also don't throw an event unless the object in lava is living, to save on some event calls this.damageEntity(DamageSource.LAVA, 4); this.j(15); @@ -620,12 +626,12 @@ public abstract class Entity { if (!flag2) { ++this.fireTicks; // CraftBukkit start - not on fire yet - if (this.fireTicks <= 0) { - EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity()); + if (this.fireTicks <= 0) { // only throw events on the first combust, otherwise it spams + EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), 8); this.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { - this.j(8); + this.j(event.getDuration()); } } else { // CraftBukkit end @@ -1299,8 +1305,21 @@ public abstract class Entity { public void a(EntityWeatherStorm entityweatherstorm) { // CraftBukkit start - EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(entityweatherstorm.getBukkitEntity(), this.getBukkitEntity(), EntityDamageEvent.DamageCause.LIGHTNING, 5); - Bukkit.getServer().getPluginManager().callEvent(event); + final org.bukkit.entity.Entity thisBukkitEntity = this.getBukkitEntity(); + final org.bukkit.entity.Entity stormBukkitEntity = entityweatherstorm.getBukkitEntity(); + final PluginManager pluginManager = Bukkit.getServer().getPluginManager(); + + if (thisBukkitEntity instanceof Painting) { + PaintingBreakByEntityEvent event = new PaintingBreakByEntityEvent((Painting) thisBukkitEntity, stormBukkitEntity); + pluginManager.callEvent(event); + + if (event.isCancelled()) { + return; + } + } + + EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(stormBukkitEntity, thisBukkitEntity, EntityDamageEvent.DamageCause.LIGHTNING, 5); + pluginManager.callEvent(event); if (event.isCancelled()) { return; @@ -1311,7 +1330,13 @@ public abstract class Entity { ++this.fireTicks; if (this.fireTicks == 0) { - this.j(8); + // CraftBukkit start - raise a combust event when lightning strikes + EntityCombustByEntityEvent entityCombustEvent = new EntityCombustByEntityEvent(stormBukkitEntity, thisBukkitEntity, 8); + pluginManager.callEvent(entityCombustEvent); + if (!entityCombustEvent.isCancelled()) { + this.j(entityCombustEvent.getDuration()); + } + // CraftBukkit end } } diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java index 0688632d..4c127148 100644 --- a/src/main/java/net/minecraft/server/EntityHuman.java +++ b/src/main/java/net/minecraft/server/EntityHuman.java @@ -8,6 +8,7 @@ import org.bukkit.craftbukkit.entity.CraftItem; import org.bukkit.craftbukkit.TrigMath; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; +import org.bukkit.event.entity.EntityCombustByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityTargetEvent; @@ -838,7 +839,12 @@ public abstract class EntityHuman extends EntityLiving { int l = EnchantmentManager.c(this.inventory, (EntityLiving) entity); if (l > 0) { - entity.j(l * 4); + // CraftBukkit start - raise a combust event when somebody hits with a fire enchanted item + EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), l*4); + if (!combustEvent.isCancelled()) { + entity.j(combustEvent.getDuration()); + } + // CraftBukkit end } } diff --git a/src/main/java/net/minecraft/server/EntityPainting.java b/src/main/java/net/minecraft/server/EntityPainting.java index 7ab4def7..3a6edd7d 100644 --- a/src/main/java/net/minecraft/server/EntityPainting.java +++ b/src/main/java/net/minecraft/server/EntityPainting.java @@ -245,25 +245,6 @@ public class EntityPainting extends Entity { return true; } - // CraftBukkit start - copy of a method in Entity except for the CraftBukkit-specific code - // TODO: Better way? - public void a(EntityWeatherStorm entityweatherstorm) { - // CraftBukkit start - PaintingBreakByEntityEvent event = new PaintingBreakByEntityEvent((Painting) this.getBukkitEntity(), entityweatherstorm.getBukkitEntity()); - Bukkit.getServer().getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return; - } - // CraftBukkit end - - ++this.fireTicks; - if (this.fireTicks == 0) { - this.j(8); - } - } - // CraftBukkit end - public void b(NBTTagCompound nbttagcompound) { nbttagcompound.a("Dir", (byte) this.a); nbttagcompound.setString("Motive", this.e.A); diff --git a/src/main/java/net/minecraft/server/EntitySkeleton.java b/src/main/java/net/minecraft/server/EntitySkeleton.java index 0f159efd..82c2081c 100644 --- a/src/main/java/net/minecraft/server/EntitySkeleton.java +++ b/src/main/java/net/minecraft/server/EntitySkeleton.java @@ -53,11 +53,11 @@ public class EntitySkeleton extends EntityMonster { if (f > 0.5F && this.world.isChunkLoaded(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)) && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F) { // CraftBukkit start - EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity()); + EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), 8); this.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { - this.j(8); + this.j(event.getDuration()); } // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/EntityZombie.java b/src/main/java/net/minecraft/server/EntityZombie.java index 4a2f5136..6d78407f 100644 --- a/src/main/java/net/minecraft/server/EntityZombie.java +++ b/src/main/java/net/minecraft/server/EntityZombie.java @@ -25,11 +25,11 @@ public class EntityZombie extends EntityMonster { if (f > 0.5F && this.world.isChunkLoaded(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)) && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F) { // CraftBukkit start - EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity()); + EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), 8); this.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { - this.j(8); + this.j(event.getDuration()); } // CraftBukkit end } |