From 73cbfcb6b6816b487e1e9aa7c24fbeeba4efca1c Mon Sep 17 00:00:00 2001 From: Andrew Ardill Date: Tue, 18 Jan 2011 07:48:02 +0800 Subject: [PATCH] Fixing some entity damage events --- .../java/net/minecraft/server/EntityMobs.java | 8 ++++- .../net/minecraft/server/EntityPlayer.java | 9 +++-- .../java/net/minecraft/server/Explosion.java | 34 ++++++++++++------- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/minecraft/server/EntityMobs.java b/src/main/java/net/minecraft/server/EntityMobs.java index 8b1da90eaf..e55b488289 100644 --- a/src/main/java/net/minecraft/server/EntityMobs.java +++ b/src/main/java/net/minecraft/server/EntityMobs.java @@ -8,9 +8,11 @@ import org.bukkit.craftbukkit.entity.CraftLivingEntity; import org.bukkit.craftbukkit.entity.CraftMinecart; import org.bukkit.craftbukkit.entity.CraftMonster; import org.bukkit.craftbukkit.CraftServer; + import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //CraftBukkit end public class EntityMobs extends EntityCreature implements IMobs { @@ -73,8 +75,12 @@ public class EntityMobs extends EntityCreature implements IMobs { // CraftBukkit start if(entity instanceof EntityLiving) { CraftServer server = ((WorldServer) l).getServer(); + org.bukkit.entity.Entity damager = this.getBukkitEntity(); + org.bukkit.entity.Entity damagee = entity.getBukkitEntity(); + DamageCause damageType = EntityDamageEvent.DamageCause.ENTITY_ATTACK; + int damageDone = c; - EntityDamageByEntityEvent edbee = new EntityDamageByEntityEvent(entity.getBukkitEntity(), this.getBukkitEntity(), EntityDamageEvent.DamageCause.ENTITY_ATTACK, c); + EntityDamageByEntityEvent edbee = new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone); server.getPluginManager().callEvent(edbee); if (!edbee.isCancelled()){ diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index 39b6eef2e0..99a189143d 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -8,6 +8,7 @@ import org.bukkit.craftbukkit.CraftServer; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; // CraftBukkit end +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; public abstract class EntityPlayer extends EntityLiving { @@ -340,8 +341,12 @@ public abstract class EntityPlayer extends EntityLiving { // CraftBukkit start if(entity instanceof EntityLiving) { CraftServer server = ((WorldServer) l).getServer(); - - EntityDamageByEntityEvent edbee = new EntityDamageByEntityEvent(entity.getBukkitEntity(), this.getBukkitEntity(), EntityDamageEvent.DamageCause.ENTITY_ATTACK, i); + org.bukkit.entity.Entity damager = this.getBukkitEntity(); + org.bukkit.entity.Entity damagee = entity.getBukkitEntity(); + DamageCause damageType = EntityDamageEvent.DamageCause.ENTITY_ATTACK; + int damageDone = i; + + EntityDamageByEntityEvent edbee = new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone); server.getPluginManager().callEvent(edbee); if (!edbee.isCancelled()){ diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java index d48e3bc31f..68879d8a19 100644 --- a/src/main/java/net/minecraft/server/Explosion.java +++ b/src/main/java/net/minecraft/server/Explosion.java @@ -8,9 +8,13 @@ import org.bukkit.craftbukkit.CraftServer; import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; + import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.block.CraftBlock; + +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; + // CraftBukkit end import java.util.*; @@ -115,32 +119,36 @@ public class Explosion { double d14 = (1.0D - d11) * d13; // CraftBukkit start - explosion damage hook - int damage = (int) (((d14 * d14 + d14) / 2D) * 8D * (double) f + 1.0D); - CraftServer servr = ((WorldServer) i).getServer(); - CraftEntity damagee = null; - if (entity instanceof EntityPlayerMP) { - damagee = new CraftPlayer(servr, (EntityPlayerMP) entity); - } else if (entity instanceof EntityLiving) { - damagee = new CraftLivingEntity(servr, (EntityLiving) entity); + CraftServer server = ((WorldServer) i).getServer(); + org.bukkit.entity.Entity damagee = null; + DamageCause damageType; + int damageDone = (int) (((d14 * d14 + d14) / 2D) * 8D * (double) f + 1.0D); + + if(entity instanceof EntityLiving) { + damagee = entity.getBukkitEntity(); } if (e == null) { // Block explosion // Craftbukkit TODO: get the x/y/z of the tnt block? - EntityDamageByBlockEvent edbbe = new EntityDamageByBlockEvent(null, damagee, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, damage); - servr.getPluginManager().callEvent(edbbe); + damageType = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION; + EntityDamageByBlockEvent edbbe = new EntityDamageByBlockEvent(null, damagee, damageType, damageDone); + server.getPluginManager().callEvent(edbbe); if (!edbbe.isCancelled()) { entity.a(e, edbbe.getDamage()); } } else { CraftEntity damager = null; + //TODO org.bukkit.entity.Entity damager = e.getBukkitEntity(); if (e instanceof EntityPlayerMP) { // not possible in normal operations - damager = new CraftPlayer(servr, (EntityPlayerMP) e); + damager = new CraftPlayer(server, (EntityPlayerMP) e); } else if (e instanceof EntityLiving) { - damager = new CraftLivingEntity(servr, (EntityLiving) e); + damager = new CraftLivingEntity(server, (EntityLiving) e); } - EntityDamageByEntityEvent edbbe = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION, damage); - servr.getPluginManager().callEvent(edbbe); + damageType = EntityDamageEvent.DamageCause.ENTITY_ATTACK; + + EntityDamageByEntityEvent edbbe = new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone); + server.getPluginManager().callEvent(edbbe); if (!edbbe.isCancelled()) { entity.a(e, edbbe.getDamage());