From 58ee6f37b751fb892f10443b62208072ccd6bc5e Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 20 Jan 2014 09:25:29 +1300 Subject: [PATCH] Add in the long awaited feature to have monsters ignore disguises --- config.yml | 5 ++++- pom.xml | 2 +- .../libraryaddict/disguise/DisguiseAPI.java | 20 +++++++++++++++++++ .../disguise/DisguiseListener.java | 10 ++++++++++ .../libraryaddict/disguise/LibsDisguises.java | 1 + 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/config.yml b/config.yml index 9ed19e88..5cd189da 100644 --- a/config.yml +++ b/config.yml @@ -44,4 +44,7 @@ NameAboveHeadAlwaysVisible: true # This modifys the bounding box, This is stuff like can a arrow hit them. # If you turn this to true, arrows will act like they hit the disguise in the right place! # So someone disguised as a enderdragon will easily get shot down by arrows! -ModifyBoundingBox: false \ No newline at end of file +# This may have conflicts with some plugins, such as nocheatplus +ModifyBoundingBox: false +# This prevents disguised players from being targeted by monsters. +MonstersIgnoreDisguises: false \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5595ecd1..6a631e34 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ 3.1.0 - 7.9.5 + 7.9.5-SNAPSHOT diff --git a/src/me/libraryaddict/disguise/DisguiseAPI.java b/src/me/libraryaddict/disguise/DisguiseAPI.java index 67fdcbf2..e2cd1594 100644 --- a/src/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/me/libraryaddict/disguise/DisguiseAPI.java @@ -14,6 +14,7 @@ import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.ReflectionManager; import org.bukkit.Bukkit; +import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -27,6 +28,7 @@ public class DisguiseAPI { private static boolean sendVelocity; private static boolean showNameAboveHead; private static boolean showNameAboveHeadAlwaysVisible; + private static boolean targetDisguises; @Deprecated public static boolean canHearSelfDisguise() { @@ -62,6 +64,16 @@ public class DisguiseAPI { DisguiseUtilities.refreshTrackers((TargetedDisguise) disguise); // If he is a player, then self disguise himself DisguiseUtilities.setupFakeDisguise(disguise); + // If the disguised is a player and you can't target disguised players.. + if (isMonstersIgnoreDisguises() && entity instanceof Player) { + for (Entity monster : entity.getWorld().getEntities()) { + if (monster instanceof Creature) { + if (((Creature) monster).getTarget() == entity) { + ((Creature) monster).setTarget(null); + } + } + } + } } public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List playersToNotSeeDisguise) { @@ -205,6 +217,10 @@ public class DisguiseAPI { return modifyBoundingBox; } + public static boolean isMonstersIgnoreDisguises() { + return targetDisguises; + } + public static boolean isNameAboveHeadAlwaysVisible() { return showNameAboveHeadAlwaysVisible; } @@ -279,6 +295,10 @@ public class DisguiseAPI { modifyBoundingBox = modifyBounding; } + public static void setMonstersIgnoreDisguises(boolean ignore) { + targetDisguises = ignore; + } + public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible) { showNameAboveHeadAlwaysVisible = alwaysVisible; } diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index fcdfdf6c..912035ad 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -14,6 +14,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -109,6 +111,14 @@ public class DisguiseListener implements Listener { } } + @EventHandler + public void onTarget(EntityTargetEvent event) { + if (DisguiseAPI.isMonstersIgnoreDisguises() && event.getReason() != TargetReason.CUSTOM && event.getTarget() != null + && event.getTarget() instanceof Player && DisguiseAPI.isDisguised(event.getTarget())) { + event.setCancelled(true); + } + } + @EventHandler(priority = EventPriority.MONITOR) public void onVechileEnter(VehicleEnterEvent event) { if (event.isCancelled()) diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 9780c5a4..f6cbd6e6 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -68,6 +68,7 @@ public class LibsDisguises extends JavaPlugin { DisguiseAPI.setNameOfPlayerShownAboveDisguise(getConfig().getBoolean("ShowNamesAboveDisguises")); DisguiseAPI.setNameAboveHeadAlwaysVisible(getConfig().getBoolean("NameAboveHeadAlwaysVisible")); DisguiseAPI.setModifyBoundingBox(getConfig().getBoolean("ModifyBoundingBox")); + DisguiseAPI.setMonstersIgnoreDisguises(getConfig().getBoolean("MonstersIgnoreDisguises")); try { // Here I use reflection to set the plugin for Disguise.. // Kind of stupid but I don't want open API calls for a commonly used object.