This commit is contained in:
Gabriele C 2016-07-27 03:02:50 +02:00
parent 7fc195336f
commit 1e552ea4eb
2 changed files with 14 additions and 1 deletions

View File

@ -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);
}
}

View File

@ -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);
}