From 319c987f9432c4e878a7c26568c76693abd93af3 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 9 Dec 2013 04:44:02 +1300 Subject: [PATCH] Added 2 config options to show names above disguised players head --- config.yml | 11 +++++++++- .../libraryaddict/disguise/DisguiseAPI.java | 22 ++++++++++++++----- .../disguise/DisguiseListener.java | 10 +++++++++ .../libraryaddict/disguise/LibsDisguises.java | 6 ++--- .../disguise/commands/DisguiseCommand.java | 9 ++++++++ .../commands/DisguisePlayerCommand.java | 9 ++++++++ .../commands/DisguiseRadiusCommand.java | 10 +++++++++ .../disguise/utilities/PacketsManager.java | 1 - 8 files changed, 66 insertions(+), 12 deletions(-) diff --git a/config.yml b/config.yml index 32293f0d..9427d2e4 100644 --- a/config.yml +++ b/config.yml @@ -31,4 +31,13 @@ AddEntityAnimations: true # If all players who can see a targeted disguise (Only advalible to plugins) have quit. # Does the plugin remove that disguise from valid disguises? If your plugin handles this. Then thats good. # Else its a memory leak. This loops through all disguise to see if anyone else is online who can see that disguise. -RemoveUnusedDisguises: true \ No newline at end of file +RemoveUnusedDisguises: true +# This is only called into action when the disguise is constructed using the commands. +# And when the disguise supports that. This will not be used at all for plugins constructing the disguises for instance. +# Such as prophunt. Its also false because its kind of a retarded feature. +# This is pretty simple. It shows the players displayname (Name as it appears in chat) above their head. +# This also overrides any custom name they have set in their disguise options. +ShowNamesAboveDisguises: false +# This supports the above option. +# If this is true, then the name shown above the head appears regardless of if you are looking at the disguise directly or not. +NameAboveHeadAlwaysVisible: true \ No newline at end of file diff --git a/src/me/libraryaddict/disguise/DisguiseAPI.java b/src/me/libraryaddict/disguise/DisguiseAPI.java index 34637388..ba9a2b3e 100644 --- a/src/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/me/libraryaddict/disguise/DisguiseAPI.java @@ -24,6 +24,8 @@ public class DisguiseAPI { private static boolean isEntityAnimationsAdded; private static boolean removeUnseenDisguises; private static boolean sendVelocity; + private static boolean showNameAboveHead; + private static boolean showNameAboveHeadAlwaysVisible; @Deprecated public static boolean canHearSelfDisguise() { @@ -189,8 +191,12 @@ public class DisguiseAPI { return hidingHeldItem; } - public static boolean isInventoryListenerEnabled() { - return PacketsManager.isInventoryListenerEnabled(); + public static boolean isNameAboveHeadAlwaysVisible() { + return showNameAboveHeadAlwaysVisible; + } + + public static boolean isNameOfPlayerShownAboveDisguise() { + return showNameAboveHead; } public static boolean isSelfDisguisesSoundsReplaced() { @@ -241,6 +247,7 @@ public class DisguiseAPI { public static void setHideArmorFromSelf(boolean hideArmor) { if (hidingArmor != hideArmor) { hidingArmor = hideArmor; + PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf()); } } @@ -250,13 +257,16 @@ public class DisguiseAPI { public static void setHideHeldItemFromSelf(boolean hideHelditem) { if (hidingHeldItem != hideHelditem) { hidingHeldItem = hideHelditem; + PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf()); } } - public static void setInventoryListenerEnabled(boolean inventoryListenerEnabled) { - if (PacketsManager.isInventoryListenerEnabled() != inventoryListenerEnabled) { - PacketsManager.setInventoryListenerEnabled(inventoryListenerEnabled); - } + public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible) { + showNameAboveHeadAlwaysVisible = alwaysVisible; + } + + public static void setNameOfPlayerShownAboveDisguise(boolean showNames) { + showNameAboveHead = showNames; } /** diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index ba27fbeb..be0871ee 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -4,6 +4,7 @@ import java.util.HashMap; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; +import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.UpdateChecker; @@ -85,6 +86,15 @@ public class DisguiseListener implements Listener { disguiseRunnable.remove(event.getPlayer().getName()).cancel(); String entityName = event.getRightClicked().getType().name().toLowerCase().replace("_", " "); if (disguise != null) { + if (event.getRightClicked() instanceof Player && DisguiseAPI.isNameOfPlayerShownAboveDisguise()) { + if (disguise.getWatcher() instanceof LivingWatcher) { + ((LivingWatcher) disguise.getWatcher()) + .setCustomName(((Player) event.getRightClicked()).getDisplayName()); + if (DisguiseAPI.isNameAboveHeadAlwaysVisible()) { + ((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true); + } + } + } DisguiseAPI.disguiseToAll(event.getRightClicked(), disguise); event.getPlayer().sendMessage( ChatColor.RED + "Disguised the " + entityName + " as a " diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 5a3cdda0..3f033f17 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -64,10 +64,8 @@ public class LibsDisguises extends JavaPlugin { DisguiseAPI.setHideArmorFromSelf(getConfig().getBoolean("RemoveArmor")); DisguiseAPI.setHideHeldItemFromSelf(getConfig().getBoolean("RemoveHeldItem")); DisguiseAPI.setAddEntityAnimations(getConfig().getBoolean("AddEntityAnimations")); - DisguiseAPI.setUnusedDisguisesRemoved(getConfig().getBoolean("RemoveUnusedDisguises")); - if (DisguiseAPI.isHidingArmorFromSelf() || DisguiseAPI.isHidingHeldItemFromSelf()) { - DisguiseAPI.setInventoryListenerEnabled(true); - } + DisguiseAPI.setNameOfPlayerShownAboveDisguise(getConfig().getBoolean("ShowNamesAboveDisguises")); + DisguiseAPI.setNameAboveHeadAlwaysVisible(getConfig().getBoolean("NameAboveHeadAlwaysVisible")); 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. diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java index c71244b3..ef05a279 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java @@ -3,6 +3,7 @@ package me.libraryaddict.disguise.commands; import java.util.ArrayList; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.BaseDisguiseCommand; import org.apache.commons.lang.StringUtils; @@ -30,6 +31,14 @@ public class DisguiseCommand extends BaseDisguiseCommand { } return true; } + if (DisguiseAPI.isNameOfPlayerShownAboveDisguise()) { + if (disguise.getWatcher() instanceof LivingWatcher) { + ((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) sender).getDisplayName()); + if (DisguiseAPI.isNameAboveHeadAlwaysVisible()) { + ((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true); + } + } + } DisguiseAPI.disguiseToAll((Player) sender, disguise); sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable()); return true; diff --git a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index 4618a970..7130272d 100644 --- a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -3,6 +3,7 @@ package me.libraryaddict.disguise.commands; import java.util.ArrayList; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.BaseDisguiseCommand; import org.apache.commons.lang.StringUtils; @@ -49,6 +50,14 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand { } return true; } + if (DisguiseAPI.isNameOfPlayerShownAboveDisguise()) { + if (disguise.getWatcher() instanceof LivingWatcher) { + ((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) player).getDisplayName()); + if (DisguiseAPI.isNameAboveHeadAlwaysVisible()) { + ((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true); + } + } + } DisguiseAPI.disguiseToAll(player, disguise); sender.sendMessage(ChatColor.RED + "Successfully disguised " + player.getName() + " as a " + disguise.getType().toReadable() + "!"); diff --git a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java index 178daeb6..c1f885c5 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java @@ -3,6 +3,7 @@ package me.libraryaddict.disguise.commands; import java.util.ArrayList; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.BaseDisguiseCommand; import org.apache.commons.lang.StringUtils; @@ -66,6 +67,15 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand { for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { if (entity == sender) continue; + disguise = disguise.clone(); + if (entity instanceof Player && DisguiseAPI.isNameOfPlayerShownAboveDisguise()) { + if (disguise.getWatcher() instanceof LivingWatcher) { + ((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) entity).getDisplayName()); + if (DisguiseAPI.isNameAboveHeadAlwaysVisible()) { + ((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true); + } + } + } DisguiseAPI.disguiseToAll(entity, disguise); disguisedEntitys++; } diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 98835e47..f2653097 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -2,7 +2,6 @@ package me.libraryaddict.disguise.utilities; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Random;