From 1e552ea4eb0713c5c99d9c6d1c5d6c14eac1fcdd Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Wed, 27 Jul 2016 03:02:50 +0200 Subject: [PATCH] Fix #877 --- .../xephi/authme/listener/AuthMeEntityListener.java | 4 ++++ .../fr/xephi/authme/listener/ListenerService.java | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) 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); }