From 6f21d3ca8fb02001dd10f49019cfb05ed914a873 Mon Sep 17 00:00:00 2001 From: t00thpick1 Date: Thu, 19 Jun 2014 14:38:45 -0400 Subject: [Bleeding] Implement new damage api. Fixes BUKKIT-5326, BUKKIT-3878. This commit centralizes event handling to where damage is actually applied to the entity to avoid bugs that have resulted from nodamageticks, modifications to damage after the event has been called, and similar mishaps. This also implements new API for getting and setting of modifications made to the damage amount actually applied to the entity. This is done by storing the change in the damage amount as each modifier is applied by vanilla code. The method that actually damages the armor worn by an entity has been relocated beneath the event called as to not apply durability loss when the event has been cancelled. --- src/main/java/net/minecraft/server/Entity.java | 35 ++++++++++---------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'src/main/java/net/minecraft/server/Entity.java') diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 04f5bc68..7b975767 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -24,9 +24,8 @@ import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.event.entity.EntityCombustEvent; -import org.bukkit.event.entity.EntityDamageByBlockEvent; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityPortalEvent; import org.bukkit.plugin.PluginManager; // CraftBukkit end @@ -349,26 +348,17 @@ public abstract class Entity { protected void D() { if (!this.fireProof) { + this.damageEntity(DamageSource.LAVA, 4); + // CraftBukkit start - Fallen in lava TODO: this event spams! if (this instanceof EntityLiving) { - Server server = this.world.getServer(); - - // TODO: shouldn't be sending null for the block. - org.bukkit.block.Block damager = null; // ((WorldServer) this.l).getWorld().getBlockAt(i, j, k); - org.bukkit.entity.Entity damagee = this.getBukkitEntity(); - - EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(damager, damagee, EntityDamageEvent.DamageCause.LAVA, 4D); - server.getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - damagee.setLastDamageCause(event); - this.damageEntity(DamageSource.LAVA, (float) event.getDamage()); - } - if (this.fireTicks <= 0) { // not on fire yet + // TODO: shouldn't be sending null for the block. + org.bukkit.block.Block damager = null; // ((WorldServer) this.l).getWorld().getBlockAt(i, j, k); + org.bukkit.entity.Entity damagee = this.getBukkitEntity(); EntityCombustEvent combustEvent = new org.bukkit.event.entity.EntityCombustByBlockEvent(damager, damagee, 15); - server.getPluginManager().callEvent(combustEvent); + this.world.getServer().getPluginManager().callEvent(combustEvent); if (!combustEvent.isCancelled()) { this.setOnFire(combustEvent.getDuration()); @@ -381,7 +371,6 @@ public abstract class Entity { } // 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.setOnFire(15); } } @@ -1617,12 +1606,14 @@ public abstract class Entity { } } - EntityDamageEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDamageEvent(entitylightning, this, EntityDamageEvent.DamageCause.LIGHTNING, 5D); - if (event.isCancelled()) { + if (this.fireProof) { + return; + } + CraftEventFactory.entityDamage = entitylightning; + if (!this.damageEntity(DamageSource.FIRE, 5.0F)) { + CraftEventFactory.entityDamage = null; return; } - - this.burn((float) event.getDamage()); // CraftBukkit end ++this.fireTicks; -- cgit v1.2.3