From 9d0ea520213227a39e346571c7c502f7a3a241c7 Mon Sep 17 00:00:00 2001 From: feildmaster Date: Sun, 25 Mar 2012 04:21:25 -0500 Subject: [PATCH] [Bleeding] Fixed potions throwing double events. Fixes BUKKIT-1332 --- .../java/net/minecraft/server/MobEffectList.java | 16 +++------------- .../craftbukkit/event/CraftEventFactory.java | 11 +++++++---- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/minecraft/server/MobEffectList.java b/src/main/java/net/minecraft/server/MobEffectList.java index 3b69deb999..78945bbc5f 100644 --- a/src/main/java/net/minecraft/server/MobEffectList.java +++ b/src/main/java/net/minecraft/server/MobEffectList.java @@ -1,13 +1,12 @@ package net.minecraft.server; // CraftBukkit start -import org.bukkit.Bukkit; -import org.bukkit.potion.PotionEffectType; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.potion.CraftPotionEffectType; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; +import org.bukkit.potion.PotionEffectType; // CraftBukkit end public class MobEffectList { @@ -86,7 +85,6 @@ public class MobEffectList { if (entityliving.getHealth() > 1) { // CraftBukkit start EntityDamageEvent event = CraftEventFactory.callEntityDamageEvent(null, entityliving, DamageCause.POISON, 1); - Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled() && event.getDamage() > 0) { entityliving.damageEntity(DamageSource.MAGIC, event.getDamage()); @@ -99,7 +97,6 @@ public class MobEffectList { if (this.id == HARM.id && !entityliving.aN() || this.id == HEAL.id && entityliving.aN()) { // CraftBukkit start EntityDamageEvent event = CraftEventFactory.callEntityDamageEvent(null, entityliving, DamageCause.MAGIC, 6 << i); - Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled() && event.getDamage() > 0) { entityliving.damageEntity(DamageSource.MAGIC, event.getDamage()); @@ -124,18 +121,11 @@ public class MobEffectList { if (this.id == HARM.id && !entityliving1.aN() || this.id == HEAL.id && entityliving1.aN()) { j = (int) (d0 * (double) (6 << i) + 0.5D); - // CraftBukkit start - EntityDamageEvent event = CraftEventFactory.callEntityDamageEvent(potion != null ? potion : entityliving, entityliving1, DamageCause.MAGIC, j); - j = event.getDamage(); - if (event.isCancelled() || j == 0) { - return; - } - // CraftBukkit end - if (entityliving == null) { entityliving1.damageEntity(DamageSource.MAGIC, j); } else { - entityliving1.damageEntity(DamageSource.b(entityliving1, entityliving), j); + // CraftBukkit - The "damager" needs to be the potion + entityliving1.damageEntity(DamageSource.b(potion != null ? potion : entityliving1, entityliving), j); } } } else { diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 91b60add35..bee08c37a2 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -364,14 +364,17 @@ public class CraftEventFactory { public static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSource source, int damage) { Entity damager = source.getEntity(); - EntityDamageEvent.DamageCause cause = EntityDamageEvent.DamageCause.ENTITY_ATTACK; + DamageCause cause = DamageCause.ENTITY_ATTACK; if (source instanceof EntityDamageSourceIndirect) { damager = ((EntityDamageSourceIndirect) source).getProximateDamageSource(); - if (damager.getBukkitEntity() instanceof Projectile) { - cause = EntityDamageEvent.DamageCause.PROJECTILE; - } // Else, magic..? + if (damager.getBukkitEntity() instanceof ThrownPotion) { + cause = DamageCause.MAGIC; + } else if (damager.getBukkitEntity() instanceof Projectile) { + cause = DamageCause.PROJECTILE; + } } + return callEntityDamageEvent(damager, entity, cause, damage); }