From 941f536f5c6327302726a9c3324dd282b62e0cfc Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 6 Nov 2013 03:54:57 +1300 Subject: [PATCH] Improved the cloning of flagwatcher, and now saves backups as a backup value --- .../disguise/disguisetypes/Disguise.java | 6 +++--- .../disguise/disguisetypes/FlagWatcher.java | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index 3c7fc5a5..05362782 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -464,12 +464,12 @@ public class Disguise { continue; // If the disguise has this, but not the entity. Then better set it! if (!entityValues.containsKey(dataNo) && disguiseValues.containsKey(dataNo)) { - getWatcher().setValue(dataNo, disguiseValues.get(dataNo)); + getWatcher().setBackupValue(dataNo, disguiseValues.get(dataNo)); continue; } // Else if the disguise doesn't have it. But the entity does. Better remove it! if (entityValues.containsKey(dataNo) && !disguiseValues.containsKey(dataNo)) { - getWatcher().setValue(dataNo, null); + getWatcher().setBackupValue(dataNo, null); continue; } // Since they both share it. Time to check if its from something they extend. @@ -512,7 +512,7 @@ public class Disguise { continue; // Well I can't find a reason I should leave it alone. They will probably conflict. // Time to set the value to the disguises value so no conflicts! - getWatcher().setValue(dataNo, disguiseValues.get(dataNo)); + getWatcher().setBackupValue(dataNo, disguiseValues.get(dataNo)); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index eb2741ab..76546342 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -51,6 +51,10 @@ public class FlagWatcher { } private Disguise disguise; private HashMap entityValues = new HashMap(); + /** + * This is the entity values I need to add else it could crash them.. + */ + private HashMap backupEntityValues = new HashMap(); private boolean hasDied; private org.bukkit.inventory.ItemStack[] items = new org.bukkit.inventory.ItemStack[5]; @@ -78,10 +82,17 @@ public class FlagWatcher { // I send my custom values if I see this! if (dataType == 1) sendAllCustom = true; + Object value = null; if (entityValues.containsKey(dataType)) { if (entityValues.get(dataType) == null) continue; - Object value = entityValues.get(dataType); + value = entityValues.get(dataType); + } else if (backupEntityValues.containsKey(dataType)) { + if (backupEntityValues.get(dataType) == null) + continue; + value = backupEntityValues.get(dataType); + } + if (value != null) { boolean doD = watch.d(); watch = new WatchableObject(classTypes.get(value.getClass()), dataType, value); if (!doD) @@ -307,4 +318,8 @@ public class FlagWatcher { entityValues.put(no, value); } + protected void setBackupValue(int no, Object value) { + backupEntityValues.put(no, value); + } + }