mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +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
|
* @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);
|
return;
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(ede);
|
}
|
||||||
|
|
||||||
if (ede.isCancelled()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
damage = ede.getDamage();
|
damage = damageEvent.getDamage();
|
||||||
}
|
}
|
||||||
|
|
||||||
target.damage(damage);
|
target.damage(damage);
|
||||||
|
Loading…
Reference in New Issue
Block a user