From 25df368e9a916c3e2c06198371734e2c4a1a38ec Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 3 Apr 2014 02:39:52 +1300 Subject: [PATCH] Added new config options to keep a disguise --- config.yml | 10 +++- .../disguise/DisguiseConfig.java | 27 ++++++++++ .../libraryaddict/disguise/LibsDisguises.java | 3 ++ .../disguise/disguisetypes/Disguise.java | 50 ++++++++++++++----- .../disguise/utilities/DisguiseUtilities.java | 16 +++--- 5 files changed, 84 insertions(+), 22 deletions(-) diff --git a/config.yml b/config.yml index 5e30ee11..7c6fa2e8 100644 --- a/config.yml +++ b/config.yml @@ -55,4 +55,12 @@ MonstersIgnoreDisguises: false # Works only for disguised players when attacked by a entity (arrow, monster. etc) # This will blow all disguises he has on him BlowDisguises: false -BlownDisguiseMessage: '&cYour disguise was blown!' \ No newline at end of file +BlownDisguiseMessage: '&cYour disguise was blown!' + +# This I don't really recommend turning on as it can make a memory leak.. +# These disguises, as normal will not persist after a server restart. +# There is also no EntityDeath option as entities do not revive after death. +KeepDisguises: + PlayerDeath: false + PlayerLogout: false + EntityDespawn: false \ No newline at end of file diff --git a/src/me/libraryaddict/disguise/DisguiseConfig.java b/src/me/libraryaddict/disguise/DisguiseConfig.java index a3b8858c..819f6ed4 100644 --- a/src/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/me/libraryaddict/disguise/DisguiseConfig.java @@ -9,6 +9,9 @@ public class DisguiseConfig { private static boolean hearSelfDisguise; private static boolean hidingArmor; private static boolean hidingHeldItem; + private static boolean keepDisguiseEntityDespawn; + private static boolean keepDisguisePlayerDeath; + private static boolean keepDisguisePlayerLogout; private static boolean modifyBoundingBox; private static boolean removeUnseenDisguises; private static boolean sendVelocity; @@ -47,6 +50,18 @@ public class DisguiseConfig { return hidingHeldItem; } + public static boolean isKeepDisguiseOnEntityDespawn() { + return keepDisguiseEntityDespawn; + } + + public static boolean isKeepDisguiseOnPlayerDeath() { + return keepDisguisePlayerDeath; + } + + public static boolean isKeepDisguiseOnPlayerLogout() { + return keepDisguisePlayerLogout; + } + public static boolean isModifyBoundingBox() { return modifyBoundingBox; } @@ -133,6 +148,18 @@ public class DisguiseConfig { } } + public static void setKeepDisguiseOnEntityDespawn(boolean keepDisguise) { + keepDisguiseEntityDespawn = keepDisguise; + } + + public static void setKeepDisguiseOnPlayerDeath(boolean keepDisguise) { + keepDisguisePlayerDeath = keepDisguise; + } + + public static void setKeepDisguiseOnPlayerLogout(boolean keepDisguise) { + keepDisguisePlayerLogout = keepDisguise; + } + public static void setModifyBoundingBox(boolean modifyBounding) { modifyBoundingBox = modifyBounding; } diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index ab318167..e0867d61 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -74,6 +74,9 @@ public class LibsDisguises extends JavaPlugin { DisguiseConfig.setDisguiseBlownOnAttack(getConfig().getBoolean("BlowDisguises")); DisguiseConfig.setDisguiseBlownMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("BlownDisguiseMessage"))); + DisguiseConfig.setKeepDisguiseOnPlayerDeath(getConfig().getBoolean("KeepDisguises.PlayerDeath")); + DisguiseConfig.setKeepDisguiseOnPlayerLogout(getConfig().getBoolean("KeepDisguises.PlayerLogout")); + DisguiseConfig.setKeepDisguiseOnEntityDespawn(getConfig().getBoolean("KeepDisguises.EntityDespawn")); 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/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index 95bf4037..b407a7e7 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -17,6 +17,7 @@ import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.DisguiseValues; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Horse.Variant; @@ -37,8 +38,10 @@ public abstract class Disguise { private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced(); private boolean hideArmorFromSelf = DisguiseConfig.isHidingArmorFromSelf(); private boolean hideHeldItemFromSelf = DisguiseConfig.isHidingHeldItemFromSelf(); + private boolean keepDisguiseEntityDespawn = DisguiseConfig.isKeepDisguiseOnEntityDespawn(); + private boolean keepDisguisePlayerDeath = DisguiseConfig.isKeepDisguiseOnPlayerDeath(); + private boolean keepDisguisePlayerLogout = DisguiseConfig.isKeepDisguiseOnPlayerLogout(); private boolean modifyBoundingBox = DisguiseConfig.isModifyBoundingBox(); - private boolean removeWhenInvalid = true; private boolean replaceSounds = DisguiseConfig.isSoundEnabled(); private BukkitRunnable velocityRunnable; private boolean velocitySent = DisguiseConfig.isVelocitySent(); @@ -186,7 +189,15 @@ public abstract class Disguise { public void run() { // If entity is no longer valid. Remove it. if (!getEntity().isValid()) { - if (isRemoveWhenInvalid()) { + + if (getEntity() instanceof Player ? + + (Bukkit.getPlayerExact(((Player) getEntity()).getName()) == null ? !isKeepDisguiseOnPlayerLogout() + : !isKeepDisguiseOnPlayerDeath()) + + : + + (!isKeepDisguiseOnEntityDespawn() || getEntity().isDead())) { removeDisguise(); } else { entity = null; @@ -327,6 +338,18 @@ public abstract class Disguise { return hideHeldItemFromSelf; } + public boolean isKeepDisguiseOnEntityDespawn() { + return this.keepDisguiseEntityDespawn; + } + + public boolean isKeepDisguiseOnPlayerDeath() { + return this.keepDisguisePlayerDeath; + } + + public boolean isKeepDisguiseOnPlayerLogout() { + return this.keepDisguisePlayerLogout; + } + public boolean isMiscDisguise() { return false; } @@ -343,13 +366,6 @@ public abstract class Disguise { return false; } - /** - * Is the disguise removed when the disguised entity is invalid? - */ - public boolean isRemoveWhenInvalid() { - return removeWhenInvalid; - } - public boolean isSelfDisguiseSoundsReplaced() { return hearSelfDisguise; } @@ -443,6 +459,18 @@ public abstract class Disguise { } } + public void setKeepDisguiseOnEntityDespawn(boolean keepDisguise) { + this.keepDisguiseEntityDespawn = keepDisguise; + } + + public void setKeepDisguiseOnPlayerDeath(boolean keepDisguise) { + this.keepDisguisePlayerDeath = keepDisguise; + } + + public void setKeepDisguiseOnPlayerLogout(boolean keepDisguise) { + this.keepDisguisePlayerLogout = keepDisguise; + } + public void setModifyBoundingBox(boolean modifyBox) { if (((TargetedDisguise) this).getDisguiseTarget() != TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) { throw new RuntimeException( @@ -456,10 +484,6 @@ public abstract class Disguise { } } - public void setRemoveDisguiseWhenInvalid(boolean removeWhenInvalid) { - this.removeWhenInvalid = removeWhenInvalid; - } - public void setReplaceSounds(boolean areSoundsReplaced) { replaceSounds = areSoundsReplaced; } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 9f3c9751..b97be734 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -37,20 +37,13 @@ import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedDataWatcher; public class DisguiseUtilities { + private static HashMap> futureDisguises = new HashMap>(); private static LibsDisguises libsDisguises; // A internal storage of fake entity ID's I can use. // Realistically I could probably use a ID like "4" for everyone, seeing as no one shares the ID private static HashMap selfDisguisesIds = new HashMap(); // Store the entity IDs instead of entitys because then I can disguise entitys even before they exist private static HashMap> targetedDisguises = new HashMap>(); - private static HashMap> futureDisguises = new HashMap>(); - - public static void addFutureDisguise(int entityId, TargetedDisguise disguise) { - if (!futureDisguises.containsKey(entityId)) { - futureDisguises.put(entityId, new HashSet()); - } - futureDisguises.get(entityId).add(disguise); - } public static void addDisguise(UUID entityId, TargetedDisguise disguise) { if (!getDisguises().containsKey(entityId)) { @@ -63,6 +56,13 @@ public class DisguiseUtilities { } } + public static void addFutureDisguise(int entityId, TargetedDisguise disguise) { + if (!futureDisguises.containsKey(entityId)) { + futureDisguises.put(entityId, new HashSet()); + } + futureDisguises.get(entityId).add(disguise); + } + /** * If name isn't null. Make sure that the name doesn't see any other disguise. Else if name is null. Make sure that the * observers in the disguise don't see any other disguise.