From c145ae5106c8d1c41d865e9820a92ae2404eba62 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 14 Jun 2014 20:27:48 +1200 Subject: [PATCH] Add new disguise option to remove disguises on world change --- config.yml | 3 +++ src/me/libraryaddict/disguise/DisguiseConfig.java | 10 ++++++++++ .../libraryaddict/disguise/DisguiseListener.java | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/config.yml b/config.yml index 7eade644..fffad774 100644 --- a/config.yml +++ b/config.yml @@ -86,6 +86,9 @@ MaxHealthDeterminedByEntity: true # This disables the Attributes packet, Non-living entities can still disguise as other non-living MiscDisguisesForLiving: true +# Turn this to true to have players undisguised when switching worlds +UndisguiseOnWorldChange: false + # This will help performance, especially with CPU # Due to safety reasons, self disguises can never have their packets disabled. PacketsEnabled: diff --git a/src/me/libraryaddict/disguise/DisguiseConfig.java b/src/me/libraryaddict/disguise/DisguiseConfig.java index 6220533e..de7074e4 100644 --- a/src/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/me/libraryaddict/disguise/DisguiseConfig.java @@ -34,6 +34,7 @@ public class DisguiseConfig { private static boolean showNameAboveHead; private static boolean showNameAboveHeadAlwaysVisible; private static boolean targetDisguises; + private static boolean undisguiseSwitchWorlds; private static boolean witherSkullEnabled; public static String getDisguiseBlownMessage() { @@ -85,6 +86,7 @@ public class DisguiseConfig { setMaxClonedDisguises(config.getInt("DisguiseCloneSize")); setSheepDyeable(config.getBoolean("DyeableSheep")); setWolfDyeable(config.getBoolean("DyeableWolf")); + setUndisguiseOnWorldChange(config.getBoolean("UndisguiseOnWorldChange")); } public static boolean isAnimationPacketsEnabled() { @@ -192,6 +194,10 @@ public class DisguiseConfig { return PacketsManager.isHearDisguisesEnabled(); } + public static boolean isUndisguiseOnWorldChange() { + return undisguiseSwitchWorlds; + } + /** * Is the velocity packets sent */ @@ -370,6 +376,10 @@ public class DisguiseConfig { PacketsManager.setHearDisguisesListener(isSoundsEnabled); } + public static void setUndisguiseOnWorldChange(boolean isUndisguise) { + undisguiseSwitchWorlds = isUndisguise; + } + /** * Disable velocity packets being sent for w/e reason. Maybe you want every ounce of performance you can get? */ diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index cafc4a1b..17eb09cf 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -21,6 +21,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.vehicle.VehicleEnterEvent; import org.bukkit.event.vehicle.VehicleExitEvent; @@ -189,8 +190,8 @@ public class DisguiseListener implements Listener { p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName + " as " + disguiseName + "!"); } else { - p.sendMessage(ChatColor.RED + "Failed to disguise " + (entity instanceof Player ? "" : "the ") + entityName - + " as " + disguiseName + "!"); + p.sendMessage(ChatColor.RED + "Failed to disguise " + (entity instanceof Player ? "" : "the ") + + entityName + " as " + disguiseName + "!"); } } } else { @@ -248,6 +249,15 @@ public class DisguiseListener implements Listener { } } + @EventHandler + public void onWorldSwitch(PlayerPortalEvent event) { + if (DisguiseConfig.isUndisguiseOnWorldChange() && event.getFrom().getWorld() != event.getTo().getWorld()) { + for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) { + disguise.removeDisguise(); + } + } + } + public void setDisguiseClone(final String player, Boolean[] options) { if (disguiseRunnable.containsKey(player)) { BukkitRunnable run = disguiseRunnable.remove(player);