diff options
author | feildmaster <admin@feildmaster.com> | 2012-07-01 05:04:06 -0500 |
---|---|---|
committer | feildmaster <admin@feildmaster.com> | 2012-07-02 22:22:03 -0500 |
commit | 00efc8c464d5af5b2d3d36be839ba0533af34484 (patch) | |
tree | c9aa3a6abb8cc9bdd1d1e61d95dfd59515cbf0fc /src | |
parent | e4e994f710f21c660a892c02a1973d1db490110c (diff) | |
download | craftbukkit-00efc8c464d5af5b2d3d36be839ba0533af34484.tar craftbukkit-00efc8c464d5af5b2d3d36be839ba0533af34484.tar.gz craftbukkit-00efc8c464d5af5b2d3d36be839ba0533af34484.tar.lz craftbukkit-00efc8c464d5af5b2d3d36be839ba0533af34484.tar.xz craftbukkit-00efc8c464d5af5b2d3d36be839ba0533af34484.zip |
Apply setLastDamageCause after processing events and the event has not been canceled. Fixes BUKKIT-1881
This allows previous causes to be available during the event, as well as making the damage cause a valid one. If EntityDamageEvent is canceled, then it's not the last DamageCause.
Also prevents setting DamageCause involuntarily through construction.
Diffstat (limited to 'src')
7 files changed, 20 insertions, 1 deletions
diff --git a/src/main/java/net/minecraft/server/BlockCactus.java b/src/main/java/net/minecraft/server/BlockCactus.java index c7235365..5d1da1bd 100644 --- a/src/main/java/net/minecraft/server/BlockCactus.java +++ b/src/main/java/net/minecraft/server/BlockCactus.java @@ -94,6 +94,7 @@ public class BlockCactus extends Block { world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { + damagee.setLastDamageCause(event); entity.damageEntity(DamageSource.CACTUS, event.getDamage()); } return; diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 144dc63c..a925d5e3 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -346,6 +346,7 @@ public abstract class Entity { this.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { + event.getEntity().setLastDamageCause(event); this.damageEntity(DamageSource.BURN, event.getDamage()); } } else { @@ -390,6 +391,7 @@ public abstract class Entity { server.getPluginManager().callEvent(event); if (!event.isCancelled()) { + damagee.setLastDamageCause(event); this.damageEntity(DamageSource.LAVA, event.getDamage()); } diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java index ea1fd3e7..bebac89b 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -274,6 +274,7 @@ public abstract class EntityLiving extends Entity { this.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { + event.getEntity().setLastDamageCause(event); this.damageEntity(DamageSource.STUCK, event.getDamage()); } // CraftBukkit end @@ -301,6 +302,7 @@ public abstract class EntityLiving extends Entity { this.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled() && event.getDamage() != 0) { + event.getEntity().setLastDamageCause(event); this.damageEntity(DamageSource.DROWN, event.getDamage()); } // CraftBukkit end @@ -1362,6 +1364,7 @@ public abstract class EntityLiving extends Entity { return; } + event.getEntity().setLastDamageCause(event); this.damageEntity(DamageSource.OUT_OF_WORLD, event.getDamage()); // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/EntitySnowman.java b/src/main/java/net/minecraft/server/EntitySnowman.java index 457cb03b..518f2532 100644 --- a/src/main/java/net/minecraft/server/EntitySnowman.java +++ b/src/main/java/net/minecraft/server/EntitySnowman.java @@ -33,24 +33,30 @@ public class EntitySnowman extends EntityGolem { public void e() { super.e(); if (this.aT()) { + // CraftBukkit start EntityDamageEvent event = new EntityDamageEvent(this.getBukkitEntity(), EntityDamageEvent.DamageCause.DROWNING, 1); this.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { + event.getEntity().setLastDamageCause(event); this.damageEntity(DamageSource.DROWN, event.getDamage()); } + // CraftBukkit end } int i = MathHelper.floor(this.locX); int j = MathHelper.floor(this.locZ); if (this.world.getBiome(i, j).i() > 1.0F) { + // CraftBukkit start EntityDamageEvent event = new EntityDamageEvent(this.getBukkitEntity(), EntityDamageEvent.DamageCause.MELTING, 1); this.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { + event.getEntity().setLastDamageCause(event); this.damageEntity(DamageSource.BURN, event.getDamage()); } + // CraftBukkit end } for (i = 0; i < 4; ++i) { diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java index c1582f66..ebf4a478 100644 --- a/src/main/java/net/minecraft/server/Explosion.java +++ b/src/main/java/net/minecraft/server/Explosion.java @@ -144,6 +144,7 @@ public class Explosion { Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { + damagee.setLastDamageCause(event); entity.damageEntity(DamageSource.EXPLOSION, event.getDamage()); entity.motX += d0 * d10; entity.motY += d1 * d10; diff --git a/src/main/java/net/minecraft/server/FoodMetaData.java b/src/main/java/net/minecraft/server/FoodMetaData.java index 10cafd99..3c10b06d 100644 --- a/src/main/java/net/minecraft/server/FoodMetaData.java +++ b/src/main/java/net/minecraft/server/FoodMetaData.java @@ -58,6 +58,7 @@ public class FoodMetaData { entityhuman.world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { + event.getEntity().setLastDamageCause(event); entityhuman.damageEntity(DamageSource.STARVE, event.getDamage()); } // CraftBukkit end diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 6134d118..370980ed 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -360,7 +360,12 @@ public class CraftEventFactory { } else { event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, damage); } - Bukkit.getPluginManager().callEvent(event); + + callEvent(event); + + if (!event.isCancelled()) { + event.getEntity().setLastDamageCause(event); + } return event; } |