SPIGOT-6639: During an EntityDamageEvent with damage from blocks, damaging any entity throws an error

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
CraftBukkit/Spigot 2022-01-23 09:06:06 +11:00
parent a8b86ea421
commit cf4feec6b5

View File

@ -893,7 +893,12 @@ public class CraftEventFactory {
} else if (source == DamageSource.LAVA) {
EntityDamageEvent event = (new EntityDamageByBlockEvent(blockDamage, entity.getBukkitEntity(), DamageCause.LAVA, modifiers, modifierFunctions));
event.setCancelled(cancelled);
Block damager = blockDamage;
blockDamage = null; // SPIGOT-6639: Clear blockDamage to allow other entity damage during event call
callEvent(event);
blockDamage = damager; // SPIGOT-6639: Re-set blockDamage so that other entities which are also getting damaged have the right cause
if (!event.isCancelled()) {
event.getEntity().setLastDamageCause(event);
} else {
@ -916,7 +921,11 @@ public class CraftEventFactory {
}
EntityDamageEvent event = new EntityDamageByBlockEvent(damager, entity.getBukkitEntity(), cause, modifiers, modifierFunctions);
event.setCancelled(cancelled);
blockDamage = null; // SPIGOT-6639: Clear blockDamage to allow other entity damage during event call
callEvent(event);
blockDamage = damager; // SPIGOT-6639: Re-set blockDamage so that other entities which are also getting damaged have the right cause
if (!event.isCancelled()) {
event.getEntity().setLastDamageCause(event);
} else {