diff options
author | t00thpick1 <t00thpick1dirko@gmail.com> | 2014-06-19 14:38:45 -0400 |
---|---|---|
committer | Wesley Wolfe <wesley.d.wolfe+git@gmail.com> | 2014-06-22 15:23:16 -0500 |
commit | 6f21d3ca8fb02001dd10f49019cfb05ed914a873 (patch) | |
tree | 304ff9a4e85d2ba38a61e9b4ead339266ddbbbd6 /src/main/java/net/minecraft/server/Explosion.java | |
parent | bed3f7f8f54305c94356691d6b8ec9b65a1a5d4a (diff) | |
download | craftbukkit-6f21d3ca8fb02001dd10f49019cfb05ed914a873.tar craftbukkit-6f21d3ca8fb02001dd10f49019cfb05ed914a873.tar.gz craftbukkit-6f21d3ca8fb02001dd10f49019cfb05ed914a873.tar.lz craftbukkit-6f21d3ca8fb02001dd10f49019cfb05ed914a873.tar.xz craftbukkit-6f21d3ca8fb02001dd10f49019cfb05ed914a873.zip |
[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.
Diffstat (limited to 'src/main/java/net/minecraft/server/Explosion.java')
-rw-r--r-- | src/main/java/net/minecraft/server/Explosion.java | 65 |
1 files changed, 14 insertions, 51 deletions
diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java index 11007d40..56fa9998 100644 --- a/src/main/java/net/minecraft/server/Explosion.java +++ b/src/main/java/net/minecraft/server/Explosion.java @@ -9,10 +9,7 @@ import java.util.Map; import java.util.Random; // CraftBukkit start -import org.bukkit.Bukkit; -import org.bukkit.event.entity.EntityDamageByBlockEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.Location; // CraftBukkit end @@ -130,55 +127,21 @@ public class Explosion { double d9 = (double) this.world.a(vec3d, entity.boundingBox); double d10 = (1.0D - d7) * d9; - // CraftBukkit start - Explosion damage hook - org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity(); - float damageDone = (float) ((int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.size + 1.0D)); - - if (damagee == null) { - // nothing was hurt - } else if (this.source == null) { // Block explosion (without an entity source; bed etc.) - EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(null, damagee, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, damageDone); - Bukkit.getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - damagee.setLastDamageCause(event); - entity.damageEntity(DamageSource.explosion(this), (float) event.getDamage()); - double d11 = EnchantmentProtection.a(entity, d10); - - entity.motX += d0 * d11; - entity.motY += d1 * d11; - entity.motZ += d2 * d11; - if (entity instanceof EntityHuman) { - this.l.put((EntityHuman) entity, Vec3D.a(d0 * d10, d1 * d10, d2 * d10)); - } - } - } else { - final org.bukkit.entity.Entity damager = this.source.getBukkitEntity(); - final EntityDamageEvent.DamageCause damageCause; - - if (damager instanceof org.bukkit.entity.TNTPrimed) { - damageCause = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION; - } else { - damageCause = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION; - } - - EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, damageCause, damageDone); - Bukkit.getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - entity.getBukkitEntity().setLastDamageCause(event); - entity.damageEntity(DamageSource.explosion(this), (float) event.getDamage()); - double d11 = EnchantmentProtection.a(entity, d10); - - entity.motX += d0 * d11; - entity.motY += d1 * d11; - entity.motZ += d2 * d11; - if (entity instanceof EntityHuman) { - this.l.put((EntityHuman) entity, Vec3D.a(d0 * d10, d1 * d10, d2 * d10)); - } - } + // CraftBukkit start + CraftEventFactory.entityDamage = source; + if (!entity.damageEntity(DamageSource.explosion(this), (float) ((int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.size + 1.0D)))) { + CraftEventFactory.entityDamage = null; + continue; } // CraftBukkit end + double d11 = EnchantmentProtection.a(entity, d10); + + entity.motX += d0 * d11; + entity.motY += d1 * d11; + entity.motZ += d2 * d11; + if (entity instanceof EntityHuman) { + this.l.put((EntityHuman) entity, Vec3D.a(d0 * d10, d1 * d10, d2 * d10)); + } } } } |