Reduce code duplication. Also verify that our target is alive before trying to damage them.

Fixes #1403
This commit is contained in:
GJ 2013-08-28 11:29:30 -04:00
parent df29306a1f
commit 73d0b377ae

View File

@ -348,18 +348,7 @@ public final class CombatUtils {
* @param damage Amount of damage to attempt to do * @param damage Amount of damage to attempt to do
*/ */
public static void dealDamage(LivingEntity target, double damage) { public static void dealDamage(LivingEntity target, double damage) {
if (Config.getInstance().getEventCallbackEnabled()) { dealDamage(target, damage, DamageCause.CUSTOM, null);
EntityDamageEvent ede = new FakeEntityDamageEvent(target, DamageCause.CUSTOM, damage);
mcMMO.p.getServer().getPluginManager().callEvent(ede);
if (ede.isCancelled()) {
return;
}
damage = ede.getDamage();
}
target.damage(damage);
} }
/** /**
@ -381,15 +370,19 @@ public final class CombatUtils {
* @param attacker Player to pass to event as damager * @param attacker Player to pass to event as damager
*/ */
public static void dealDamage(LivingEntity target, double damage, DamageCause cause, Entity attacker) { public static void dealDamage(LivingEntity target, double damage, DamageCause cause, Entity attacker) {
if (Config.getInstance().getEventCallbackEnabled()) { if (target.isDead()) {
EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(attacker, target, cause, damage);
mcMMO.p.getServer().getPluginManager().callEvent(ede);
if (ede.isCancelled()) {
return; return;
} }
damage = ede.getDamage(); if (Config.getInstance().getEventCallbackEnabled()) {
EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, cause, damage) : new FakeEntityDamageByEntityEvent(attacker, target, cause, damage);
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
if (damageEvent.isCancelled()) {
return;
}
damage = damageEvent.getDamage();
} }
target.damage(damage); target.damage(damage);