From 320b4e1cb7488787c2f9424cd76c8f29f1b5b985 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 14 Dec 2019 11:48:37 +1300 Subject: [PATCH] Add new disguise option for mobs to ignore selective disguises. Not usable through commands due to potential for abuse by simplistic permissions. --- .../disguise/DisguiseListener.java | 36 ++++++++++++------- .../disguise/disguisetypes/Disguise.java | 9 +++++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseListener.java b/src/main/java/me/libraryaddict/disguise/DisguiseListener.java index 71b42f77..2ea31766 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseListener.java @@ -556,18 +556,30 @@ public class DisguiseListener implements Listener { @EventHandler public void onTarget(EntityTargetEvent event) { - if (DisguiseConfig.isMonstersIgnoreDisguises() && event.getTarget() != null && - event.getTarget() instanceof Player && DisguiseAPI.isDisguised(event.getTarget())) { - switch (event.getReason()) { - case TARGET_ATTACKED_ENTITY: - case TARGET_ATTACKED_OWNER: - case OWNER_ATTACKED_TARGET: - case CUSTOM: - break; - default: - event.setCancelled(true); - break; - } + if (event.getTarget() == null) { + return; + } + + switch (event.getReason()) { + case TARGET_ATTACKED_ENTITY: + case TARGET_ATTACKED_OWNER: + case OWNER_ATTACKED_TARGET: + case CUSTOM: + return; + default: + break; + } + + Disguise disguise = DisguiseAPI.getDisguise(event.getTarget()); + + if (disguise == null) { + return; + } + + if (disguise.isMobsIgnoreDisguise()) { + event.setCancelled(true); + } else if (DisguiseConfig.isMonstersIgnoreDisguises() && event.getTarget() instanceof Player) { + event.setCancelled(true); } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index adcb6148..28040917 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -54,6 +54,7 @@ public abstract class Disguise { private boolean modifyBoundingBox = DisguiseConfig.isModifyBoundingBox(); private boolean playerHiddenFromTab = DisguiseConfig.isHideDisguisedPlayers(); private boolean replaceSounds = DisguiseConfig.isSoundEnabled(); + private boolean mobsIgnoreDisguise; private boolean showName; private transient BukkitTask task; private Runnable velocityRunnable; @@ -864,4 +865,12 @@ public abstract class Disguise { public boolean stopDisguise() { return removeDisguise(); } + + public boolean isMobsIgnoreDisguise() { + return mobsIgnoreDisguise; + } + + public void setMobsIgnoreDisguise(boolean mobsIgnoreDisguise) { + this.mobsIgnoreDisguise = mobsIgnoreDisguise; + } } \ No newline at end of file