From d84121c4eb3aa66a14e1602ac1e00e39af04ea91 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 6 Nov 2013 05:37:10 +1300 Subject: [PATCH] Fixed up the flagwatchers .clone and fixed playerdisguise not .clone working --- .../disguise/disguisetypes/FlagWatcher.java | 10 ++++++++-- .../disguise/disguisetypes/MiscDisguise.java | 3 ++- .../disguise/disguisetypes/MobDisguise.java | 3 ++- .../disguise/disguisetypes/PlayerDisguise.java | 7 +++++++ .../disguise/disguisetypes/watchers/LivingWatcher.java | 7 +++---- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 71491f5a..06f8d3c5 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -62,8 +62,14 @@ public class FlagWatcher { this.disguise = disguise; } - public FlagWatcher clone() { - FlagWatcher cloned = new FlagWatcher(disguise); + public FlagWatcher clone(Disguise disguise) { + FlagWatcher cloned = null; + try { + cloned = getClass().getConstructor(Disguise.class).newInstance(disguise); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } cloned.entityValues = (HashMap) entityValues.clone(); cloned.items = items.clone(); return cloned; diff --git a/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java b/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java index d6d50e8d..35f857e3 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java @@ -54,6 +54,7 @@ public class MiscDisguise extends Disguise { this(disguiseType, true, id, data); } + @Override public MiscDisguise clone() { MiscDisguise disguise = new MiscDisguise(getType(), replaceSounds(), getId(), getData()); disguise.setViewSelfDisguise(viewSelfDisguise()); @@ -61,7 +62,7 @@ public class MiscDisguise extends Disguise { disguise.setHideArmorFromSelf(isHidingArmorFromSelf()); disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf()); disguise.setVelocitySent(isVelocitySent()); - disguise.setWatcher(getWatcher().clone()); + disguise.setWatcher(getWatcher().clone(disguise)); return disguise; } diff --git a/src/me/libraryaddict/disguise/disguisetypes/MobDisguise.java b/src/me/libraryaddict/disguise/disguisetypes/MobDisguise.java index a757da81..4631d7ce 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/MobDisguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/MobDisguise.java @@ -38,6 +38,7 @@ public class MobDisguise extends Disguise { createDisguise(DisguiseType.getType(entityType), replaceSounds); } + @Override public MobDisguise clone() { MobDisguise disguise = new MobDisguise(getType(), isAdult(), replaceSounds()); disguise.setViewSelfDisguise(viewSelfDisguise()); @@ -45,7 +46,7 @@ public class MobDisguise extends Disguise { disguise.setHideArmorFromSelf(isHidingArmorFromSelf()); disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf()); disguise.setVelocitySent(isVelocitySent()); - disguise.setWatcher(getWatcher().clone()); + disguise.setWatcher(getWatcher().clone(disguise)); return disguise; } diff --git a/src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java b/src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java index 436f847e..71668cbb 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java @@ -14,8 +14,15 @@ public class PlayerDisguise extends Disguise { createDisguise(DisguiseType.PLAYER, replaceSounds); } + @Override public PlayerDisguise clone() { PlayerDisguise disguise = new PlayerDisguise(getName(), replaceSounds()); + disguise.setViewSelfDisguise(viewSelfDisguise()); + disguise.setHearSelfDisguise(canHearSelfDisguise()); + disguise.setHideArmorFromSelf(isHidingArmorFromSelf()); + disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf()); + disguise.setVelocitySent(isVelocitySent()); + disguise.setWatcher(getWatcher().clone(disguise)); return disguise; } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java index fe7b8892..4f5ac45b 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java @@ -11,8 +11,6 @@ import net.minecraft.server.v1_6_R3.PotionBrewer; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; - - public class LivingWatcher extends FlagWatcher { private HashSet potionEffects = new HashSet(); @@ -27,8 +25,9 @@ public class LivingWatcher extends FlagWatcher { sendPotionEffects(); } - public LivingWatcher clone() { - LivingWatcher clone = (LivingWatcher) super.clone(); + @Override + public LivingWatcher clone(Disguise disguise) { + LivingWatcher clone = (LivingWatcher) super.clone(disguise); clone.potionEffects = (HashSet) potionEffects.clone(); return clone; }