Fixed up the flagwatchers .clone and fixed playerdisguise not .clone working

This commit is contained in:
Andrew 2013-11-06 05:37:10 +13:00
parent fb38bcd99f
commit d84121c4eb
5 changed files with 22 additions and 8 deletions

@ -62,8 +62,14 @@ public class FlagWatcher {
this.disguise = disguise; this.disguise = disguise;
} }
public FlagWatcher clone() { public FlagWatcher clone(Disguise disguise) {
FlagWatcher cloned = new FlagWatcher(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<Integer, Object>) entityValues.clone(); cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
cloned.items = items.clone(); cloned.items = items.clone();
return cloned; return cloned;

@ -54,6 +54,7 @@ public class MiscDisguise extends Disguise {
this(disguiseType, true, id, data); this(disguiseType, true, id, data);
} }
@Override
public MiscDisguise clone() { public MiscDisguise clone() {
MiscDisguise disguise = new MiscDisguise(getType(), replaceSounds(), getId(), getData()); MiscDisguise disguise = new MiscDisguise(getType(), replaceSounds(), getId(), getData());
disguise.setViewSelfDisguise(viewSelfDisguise()); disguise.setViewSelfDisguise(viewSelfDisguise());
@ -61,7 +62,7 @@ public class MiscDisguise extends Disguise {
disguise.setHideArmorFromSelf(isHidingArmorFromSelf()); disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf()); disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
disguise.setVelocitySent(isVelocitySent()); disguise.setVelocitySent(isVelocitySent());
disguise.setWatcher(getWatcher().clone()); disguise.setWatcher(getWatcher().clone(disguise));
return disguise; return disguise;
} }

@ -38,6 +38,7 @@ public class MobDisguise extends Disguise {
createDisguise(DisguiseType.getType(entityType), replaceSounds); createDisguise(DisguiseType.getType(entityType), replaceSounds);
} }
@Override
public MobDisguise clone() { public MobDisguise clone() {
MobDisguise disguise = new MobDisguise(getType(), isAdult(), replaceSounds()); MobDisguise disguise = new MobDisguise(getType(), isAdult(), replaceSounds());
disguise.setViewSelfDisguise(viewSelfDisguise()); disguise.setViewSelfDisguise(viewSelfDisguise());
@ -45,7 +46,7 @@ public class MobDisguise extends Disguise {
disguise.setHideArmorFromSelf(isHidingArmorFromSelf()); disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf()); disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
disguise.setVelocitySent(isVelocitySent()); disguise.setVelocitySent(isVelocitySent());
disguise.setWatcher(getWatcher().clone()); disguise.setWatcher(getWatcher().clone(disguise));
return disguise; return disguise;
} }

@ -14,8 +14,15 @@ public class PlayerDisguise extends Disguise {
createDisguise(DisguiseType.PLAYER, replaceSounds); createDisguise(DisguiseType.PLAYER, replaceSounds);
} }
@Override
public PlayerDisguise clone() { public PlayerDisguise clone() {
PlayerDisguise disguise = new PlayerDisguise(getName(), replaceSounds()); 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; return disguise;
} }

@ -11,8 +11,6 @@ import net.minecraft.server.v1_6_R3.PotionBrewer;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
public class LivingWatcher extends FlagWatcher { public class LivingWatcher extends FlagWatcher {
private HashSet<MobEffect> potionEffects = new HashSet<MobEffect>(); private HashSet<MobEffect> potionEffects = new HashSet<MobEffect>();
@ -27,8 +25,9 @@ public class LivingWatcher extends FlagWatcher {
sendPotionEffects(); sendPotionEffects();
} }
public LivingWatcher clone() { @Override
LivingWatcher clone = (LivingWatcher) super.clone(); public LivingWatcher clone(Disguise disguise) {
LivingWatcher clone = (LivingWatcher) super.clone(disguise);
clone.potionEffects = (HashSet<MobEffect>) potionEffects.clone(); clone.potionEffects = (HashSet<MobEffect>) potionEffects.clone();
return clone; return clone;
} }