mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
Reduce code duplication. Also verify that our target is alive before trying to damage them.
Fixes #1403
This commit is contained in:
parent
df29306a1f
commit
73d0b377ae
@ -348,18 +348,7 @@ public final class CombatUtils {
|
||||
* @param damage Amount of damage to attempt to do
|
||||
*/
|
||||
public static void dealDamage(LivingEntity target, double damage) {
|
||||
if (Config.getInstance().getEventCallbackEnabled()) {
|
||||
EntityDamageEvent ede = new FakeEntityDamageEvent(target, DamageCause.CUSTOM, damage);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(ede);
|
||||
|
||||
if (ede.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
damage = ede.getDamage();
|
||||
}
|
||||
|
||||
target.damage(damage);
|
||||
dealDamage(target, damage, DamageCause.CUSTOM, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -381,15 +370,19 @@ public final class CombatUtils {
|
||||
* @param attacker Player to pass to event as damager
|
||||
*/
|
||||
public static void dealDamage(LivingEntity target, double damage, DamageCause cause, Entity attacker) {
|
||||
if (Config.getInstance().getEventCallbackEnabled()) {
|
||||
EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(attacker, target, cause, damage);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(ede);
|
||||
|
||||
if (ede.isCancelled()) {
|
||||
if (target.isDead()) {
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user