SPIGOT-5309: Call cancelled EntityDamageEvent when damaging invisible armor stands

This commit is contained in:
jojokobi 2019-10-05 19:02:38 +02:00 committed by md_5
parent 46351e1783
commit 7deb3728e3
2 changed files with 33 additions and 10 deletions

View file

@ -64,9 +64,10 @@
+ // CraftBukkit end
+ this.killEntity(); // CraftBukkit - this.die() -> this.killEntity()
return false;
} else if (!this.isInvulnerable(damagesource) && !this.bD && !this.isMarker()) {
- } else if (!this.isInvulnerable(damagesource) && !this.bD && !this.isMarker()) {
+ } else if (!this.isInvulnerable(damagesource) && (true || !this.bD) && !this.isMarker()) { // CraftBukkit
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f)) {
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f, true, this.bD)) { // PAIL: armorStandInvisible
+ return false;
+ }
+ // CraftBukkit end

View file

@ -739,6 +739,10 @@ public class CraftEventFactory {
}
private static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSource source, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions) {
return handleEntityDamageEvent(entity, source, modifiers, modifierFunctions, false);
}
private static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSource source, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions, boolean cancelled) {
if (source.isExplosion()) {
DamageCause damageCause;
Entity damager = entityDamage;
@ -756,6 +760,7 @@ public class CraftEventFactory {
}
event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), entity.getBukkitEntity(), damageCause, modifiers, modifierFunctions);
}
event.setCancelled(cancelled);
callEvent(event);
@ -778,15 +783,19 @@ public class CraftEventFactory {
cause = DamageCause.THORNS;
}
return callEntityDamageEvent(damager, entity, cause, modifiers, modifierFunctions);
return callEntityDamageEvent(damager, entity, cause, modifiers, modifierFunctions, cancelled);
} else if (source == DamageSource.OUT_OF_WORLD) {
EntityDamageEvent event = callEvent(new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.VOID, modifiers, modifierFunctions));
EntityDamageEvent event = new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.VOID, modifiers, modifierFunctions);
event.setCancelled(cancelled);
callEvent(event);
if (!event.isCancelled()) {
event.getEntity().setLastDamageCause(event);
}
return event;
} else if (source == DamageSource.LAVA) {
EntityDamageEvent event = callEvent(new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.LAVA, modifiers, modifierFunctions));
EntityDamageEvent event = (new EntityDamageByBlockEvent(null, entity.getBukkitEntity(), DamageCause.LAVA, modifiers, modifierFunctions));
event.setCancelled(cancelled);
callEvent(event);
if (!event.isCancelled()) {
event.getEntity().setLastDamageCause(event);
}
@ -804,7 +813,9 @@ public class CraftEventFactory {
} else {
throw new IllegalStateException(String.format("Unhandled damage of %s by %s from %s", entity, damager, source.translationIndex));
}
EntityDamageEvent event = callEvent(new EntityDamageByBlockEvent(damager, entity.getBukkitEntity(), cause, modifiers, modifierFunctions));
EntityDamageEvent event = new EntityDamageByBlockEvent(damager, entity.getBukkitEntity(), cause, modifiers, modifierFunctions);
event.setCancelled(cancelled);
callEvent(event);
if (!event.isCancelled()) {
event.getEntity().setLastDamageCause(event);
}
@ -826,7 +837,9 @@ public class CraftEventFactory {
} else {
throw new IllegalStateException(String.format("Unhandled damage of %s by %s from %s", entity, damager.getHandle(), source.translationIndex));
}
EntityDamageEvent event = callEvent(new EntityDamageByEntityEvent(damager, entity.getBukkitEntity(), cause, modifiers, modifierFunctions));
EntityDamageEvent event = new EntityDamageByEntityEvent(damager, entity.getBukkitEntity(), cause, modifiers, modifierFunctions);
event.setCancelled(cancelled);
callEvent(event);
if (!event.isCancelled()) {
event.getEntity().setLastDamageCause(event);
}
@ -865,20 +878,24 @@ public class CraftEventFactory {
}
if (cause != null) {
return callEntityDamageEvent(null, entity, cause, modifiers, modifierFunctions);
return callEntityDamageEvent(null, entity, cause, modifiers, modifierFunctions, cancelled);
}
throw new IllegalStateException(String.format("Unhandled damage of %s from %s", entity, source.translationIndex));
}
private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions) {
return callEntityDamageEvent(damager, damagee, cause, modifiers, modifierFunctions, false);
}
private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions, boolean cancelled) {
EntityDamageEvent event;
if (damager != null) {
event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
} else {
event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
}
event.setCancelled(cancelled);
callEvent(event);
if (!event.isCancelled()) {
@ -920,6 +937,10 @@ public class CraftEventFactory {
}
public static boolean handleNonLivingEntityDamageEvent(Entity entity, DamageSource source, double damage, boolean cancelOnZeroDamage) {
return handleNonLivingEntityDamageEvent(entity, source, damage, cancelOnZeroDamage, false);
}
public static boolean handleNonLivingEntityDamageEvent(Entity entity, DamageSource source, double damage, boolean cancelOnZeroDamage, boolean cancelled) {
if (entity instanceof EntityEnderCrystal && !(source instanceof EntityDamageSource)) {
return false;
}
@ -930,7 +951,8 @@ public class CraftEventFactory {
modifiers.put(DamageModifier.BASE, damage);
functions.put(DamageModifier.BASE, ZERO);
final EntityDamageEvent event = handleEntityDamageEvent(entity, source, modifiers, functions);
final EntityDamageEvent event = handleEntityDamageEvent(entity, source, modifiers, functions, cancelled);
if (event == null) {
return false;
}