From cc8f23f56f2814b69756b9a70b767427d5d4783d Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 31 Aug 2020 22:29:18 +0200 Subject: [PATCH] Exclude Citizens NPCs from player listener; resolves #874 --- .../dungeonsxl/player/DPlayerListener.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/de/erethon/dungeonsxl/player/DPlayerListener.java b/core/src/main/java/de/erethon/dungeonsxl/player/DPlayerListener.java index 08190705..c78cae88 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/player/DPlayerListener.java +++ b/core/src/main/java/de/erethon/dungeonsxl/player/DPlayerListener.java @@ -86,9 +86,16 @@ public class DPlayerListener implements Listener { @EventHandler public void onEntityDamage(EntityDamageEvent event) { + if (!(event.getEntity() instanceof LivingEntity)) { + return; + } + LivingEntity entity = ((LivingEntity) event.getEntity()); + if (isCitizensNPC(entity)) { + return; + } + World world = event.getEntity().getWorld(); GameWorld gameWorld = plugin.getGameWorld(world); - if (gameWorld == null) { return; } @@ -98,24 +105,20 @@ public class DPlayerListener implements Listener { event.setCancelled(true); } - if (!(event.getEntity() instanceof LivingEntity)) { - return; - } - - boolean dead = ((LivingEntity) event.getEntity()).getHealth() - event.getFinalDamage() <= 0; + boolean dead = entity.getHealth() - event.getFinalDamage() <= 0; if (!dead) { return; } - if (event.getEntity() instanceof Player && !gameWorld.getDungeon().getRules().getState(GameRule.DEATH_SCREEN)) { + if (entity instanceof Player && !gameWorld.getDungeon().getRules().getState(GameRule.DEATH_SCREEN)) { event.setDamage(0); - GamePlayer gamePlayer = plugin.getPlayerCache().getGamePlayer((Player) event.getEntity()); + GamePlayer gamePlayer = plugin.getPlayerCache().getGamePlayer((Player) entity); if (gamePlayer == null) { return; } ((DGamePlayer) gamePlayer).onDeath(null); } - if (plugin.getDungeonMob((LivingEntity) event.getEntity()) != null) { + if (plugin.getDungeonMob(entity) != null) { String killer = null; if (event instanceof EntityDamageByEntityEvent) {