Skip to content

Commit

Permalink
Fixed EntityDamageEvent is not called in some cases (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Nov 22, 2024
1 parent 217d78e commit 1588b56
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,24 @@ public void handleEntityDamage(EntityDamageEvent e) {
handleEntityDamage(e, false);
}

private static void recallDamageEvent(EntityDamageEvent damageEvent) {
BiHandlerList entityDamageHandlerList = (BiHandlerList) EntityDamageEvent.getHandlerList();
try {
entityDamageHandlerList.setMode(BiHandlerList.Mode.ORIGINAL);
// Call the event again.
Bukkit.getPluginManager().callEvent(damageEvent);
} finally {
entityDamageHandlerList.setMode(BiHandlerList.Mode.NEW);
}
}

private void handleEntityDamage(EntityDamageEvent damageEvent, boolean fromDeathEvent) {
// Making sure the entity is stackable
if (!plugin.getSettings().entitiesStackingEnabled || !EntityUtils.isStackable(damageEvent.getEntity()))
if (!plugin.getSettings().entitiesStackingEnabled || !EntityUtils.isStackable(damageEvent.getEntity())) {
// If not, we still want to re-call the damage event
recallDamageEvent(damageEvent);
return;
}

LivingEntity livingEntity = (LivingEntity) damageEvent.getEntity();
StackedEntity stackedEntity = WStackedEntity.of(livingEntity);
Expand All @@ -232,14 +246,7 @@ private void handleEntityDamage(EntityDamageEvent damageEvent, boolean fromDeath
if (!fromDeathEvent) {
damageEvent.setCancelled(true);
entityDamageData = new EntityDamageData(damageEvent);
BiHandlerList entityDamageHandlerList = (BiHandlerList) EntityDamageEvent.getHandlerList();
try {
entityDamageHandlerList.setMode(BiHandlerList.Mode.ORIGINAL);
// Call the event again.
Bukkit.getPluginManager().callEvent(damageEvent);
} finally {
entityDamageHandlerList.setMode(BiHandlerList.Mode.NEW);
}
recallDamageEvent(damageEvent);
}

if (!damageEvent.isCancelled())
Expand Down

0 comments on commit 1588b56

Please sign in to comment.