Improved the cloning of flagwatcher, and now saves backups as a backup value

This commit is contained in:
Andrew 2013-11-06 03:54:57 +13:00
parent fb5dc6836a
commit 941f536f5c
2 changed files with 19 additions and 4 deletions

@ -464,12 +464,12 @@ public class Disguise {
continue; continue;
// If the disguise has this, but not the entity. Then better set it! // If the disguise has this, but not the entity. Then better set it!
if (!entityValues.containsKey(dataNo) && disguiseValues.containsKey(dataNo)) { if (!entityValues.containsKey(dataNo) && disguiseValues.containsKey(dataNo)) {
getWatcher().setValue(dataNo, disguiseValues.get(dataNo)); getWatcher().setBackupValue(dataNo, disguiseValues.get(dataNo));
continue; continue;
} }
// Else if the disguise doesn't have it. But the entity does. Better remove it! // Else if the disguise doesn't have it. But the entity does. Better remove it!
if (entityValues.containsKey(dataNo) && !disguiseValues.containsKey(dataNo)) { if (entityValues.containsKey(dataNo) && !disguiseValues.containsKey(dataNo)) {
getWatcher().setValue(dataNo, null); getWatcher().setBackupValue(dataNo, null);
continue; continue;
} }
// Since they both share it. Time to check if its from something they extend. // Since they both share it. Time to check if its from something they extend.
@ -512,7 +512,7 @@ public class Disguise {
continue; continue;
// Well I can't find a reason I should leave it alone. They will probably conflict. // 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! // Time to set the value to the disguises value so no conflicts!
getWatcher().setValue(dataNo, disguiseValues.get(dataNo)); getWatcher().setBackupValue(dataNo, disguiseValues.get(dataNo));
} }
} }

@ -51,6 +51,10 @@ public class FlagWatcher {
} }
private Disguise disguise; private Disguise disguise;
private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>(); private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>();
/**
* This is the entity values I need to add else it could crash them..
*/
private HashMap<Integer, Object> backupEntityValues = new HashMap<Integer, Object>();
private boolean hasDied; private boolean hasDied;
private org.bukkit.inventory.ItemStack[] items = new org.bukkit.inventory.ItemStack[5]; 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! // I send my custom values if I see this!
if (dataType == 1) if (dataType == 1)
sendAllCustom = true; sendAllCustom = true;
Object value = null;
if (entityValues.containsKey(dataType)) { if (entityValues.containsKey(dataType)) {
if (entityValues.get(dataType) == null) if (entityValues.get(dataType) == null)
continue; 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(); boolean doD = watch.d();
watch = new WatchableObject(classTypes.get(value.getClass()), dataType, value); watch = new WatchableObject(classTypes.get(value.getClass()), dataType, value);
if (!doD) if (!doD)
@ -307,4 +318,8 @@ public class FlagWatcher {
entityValues.put(no, value); entityValues.put(no, value);
} }
protected void setBackupValue(int no, Object value) {
backupEntityValues.put(no, value);
}
} }