diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java index ce8afa408..95e1d164e 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java @@ -59,6 +59,10 @@ public class AuthMeEntityListener implements Listener { public void onDamage(EntityDamageByEntityEvent event) { if (listenerService.shouldCancelEvent(event)) { event.setCancelled(true); + return; + } + if (listenerService.shouldCancelEvent(event.getDamager())) { + event.setCancelled(true); } } diff --git a/src/main/java/fr/xephi/authme/listener/ListenerService.java b/src/main/java/fr/xephi/authme/listener/ListenerService.java index 8427431c1..6c09bd2e5 100644 --- a/src/main/java/fr/xephi/authme/listener/ListenerService.java +++ b/src/main/java/fr/xephi/authme/listener/ListenerService.java @@ -44,10 +44,19 @@ class ListenerService implements SettingsDependent { */ public boolean shouldCancelEvent(EntityEvent event) { Entity entity = event.getEntity(); + return shouldCancelEvent(entity); + } + + /** + * Returns, based on the entity associated with the event, whether or not the event should be canceled. + * + * @param entity the player entity to verify + * @return true if the associated event should be canceled, false otherwise + */ + public boolean shouldCancelEvent(Entity entity) { if (entity == null || !(entity instanceof Player)) { return false; } - Player player = (Player) entity; return shouldCancelEvent(player); }