From 30c626674948b742468c1148be78d06a9c2b98a8 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 18 Sep 2013 09:30:58 +1200 Subject: [PATCH] Fixed being unable to set the disguise as a baby --- .../disguise/DisguiseTypes/Disguise.java | 20 ++++++++++++------- .../disguise/DisguiseTypes/MiscDisguise.java | 4 ++-- .../disguise/DisguiseTypes/MobDisguise.java | 6 +++--- .../DisguiseTypes/PlayerDisguise.java | 2 +- .../libraryaddict/disguise/LibsDisguises.java | 7 ++++--- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Disguise.java b/src/me/libraryaddict/disguise/DisguiseTypes/Disguise.java index b656d25b..8c6b171f 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Disguise.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Disguise.java @@ -42,11 +42,15 @@ public class Disguise { private boolean viewSelfDisguise = DisguiseAPI.isViewDisguises(); private FlagWatcher watcher; - protected Disguise(DisguiseType newType, boolean doSounds) { + protected Disguise createDisguise(DisguiseType newType, boolean doSounds) { + if (getWatcher() != null) + return this; // Set the disguise type disguiseType = newType; // Set the option to replace the sounds setReplaceSounds(doSounds); + // Get if they are a adult now.. + boolean isAdult = !(this instanceof MobDisguise && !((MobDisguise) this).isAdult()); try { // Construct the FlagWatcher from the stored class setWatcher((FlagWatcher) getType().getWatcherClass().getConstructor(Disguise.class).newInstance(this)); @@ -54,11 +58,12 @@ public class Disguise { e.printStackTrace(); } // Set the disguise if its a baby or not - if (this instanceof MobDisguise && !((MobDisguise) this).isAdult()) { - if (getWatcher() instanceof AgeableWatcher) - getWatcher().setValue(12, -24000); - else if (getWatcher() instanceof ZombieWatcher) - getWatcher().setValue(12, (byte) 1); + if (isAdult) { + if (getWatcher() instanceof AgeableWatcher) { + ((AgeableWatcher) getWatcher()).setAdult(false); + } else if (getWatcher() instanceof ZombieWatcher) { + ((ZombieWatcher) getWatcher()).setAdult(false); + } } // If the disguise type is a wither, set the flagwatcher value for the skeleton to a wither skeleton if (getType() == DisguiseType.WITHER_SKELETON) @@ -246,6 +251,7 @@ public class Disguise { } } }; + return this; } public boolean canHearSelfDisguise() { @@ -253,7 +259,7 @@ public class Disguise { } public Disguise clone() { - Disguise disguise = new Disguise(getType(), replaceSounds()); + Disguise disguise = new Disguise().createDisguise(getType(), replaceSounds()); disguise.setViewSelfDisguise(viewSelfDisguise()); return disguise; } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/MiscDisguise.java b/src/me/libraryaddict/disguise/DisguiseTypes/MiscDisguise.java index b1404785..bbf0ae93 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/MiscDisguise.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/MiscDisguise.java @@ -15,13 +15,13 @@ public class MiscDisguise extends Disguise { } public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds, int id, int data) { - super(disguiseType, replaceSounds); if (id == -1) id = disguiseType.getDefaultId(); if (data == -1) data = disguiseType.getDefaultData(); this.id = id; this.data = data; + createDisguise(disguiseType, replaceSounds); } public MiscDisguise(DisguiseType disguiseType, int id, int data) { @@ -40,13 +40,13 @@ public class MiscDisguise extends Disguise { @Deprecated public MiscDisguise(EntityType entityType, boolean replaceSounds, int id, int data) { - super(DisguiseType.getType(entityType), replaceSounds); if (id == -1) id = DisguiseType.getType(entityType).getDefaultId(); if (data == -1) data = DisguiseType.getType(entityType).getDefaultData(); this.id = id; this.data = data; + createDisguise(DisguiseType.getType(entityType), replaceSounds); } @Deprecated diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/MobDisguise.java b/src/me/libraryaddict/disguise/DisguiseTypes/MobDisguise.java index 4989ed97..850a2eb8 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/MobDisguise.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/MobDisguise.java @@ -18,8 +18,8 @@ public class MobDisguise extends Disguise { } public MobDisguise(DisguiseType disguiseType, boolean isAdult, boolean replaceSounds) { - super(disguiseType, replaceSounds); this.isAdult = isAdult; + createDisguise(disguiseType, replaceSounds); } @Deprecated @@ -34,8 +34,8 @@ public class MobDisguise extends Disguise { @Deprecated public MobDisguise(EntityType entityType, boolean isAdult, boolean replaceSounds) { - super(DisguiseType.getType(entityType), replaceSounds); this.isAdult = isAdult; + createDisguise(DisguiseType.getType(entityType), replaceSounds); } public MobDisguise clone() { @@ -58,7 +58,7 @@ public class MobDisguise extends Disguise { public boolean isAdult() { if (getWatcher() != null) { if (getWatcher() instanceof AgeableWatcher) - return true; + return ((AgeableWatcher) getWatcher()).isAdult(); else if (getWatcher() instanceof ZombieWatcher) return ((ZombieWatcher) getWatcher()).isAdult(); return false; diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/PlayerDisguise.java b/src/me/libraryaddict/disguise/DisguiseTypes/PlayerDisguise.java index a7daa2b6..d122ddaa 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/PlayerDisguise.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/PlayerDisguise.java @@ -8,10 +8,10 @@ public class PlayerDisguise extends Disguise { } public PlayerDisguise(String name, boolean replaceSounds) { - super(DisguiseType.PLAYER, replaceSounds); if (name.length() > 16) name = name.substring(0, 16); playerName = name; + createDisguise(DisguiseType.PLAYER, replaceSounds); } public PlayerDisguise clone() { diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 0ec62656..c2dec8e2 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -126,12 +126,13 @@ public class LibsDisguises extends JavaPlugin { // There is no watcher for this entity, or a error was thrown. try { Class c = disguiseType.getEntityType().getEntityClass(); - if (Ageable.class.isAssignableFrom(c)) + if (Ageable.class.isAssignableFrom(c)) { watcherClass = AgeableWatcher.class; - else if (LivingEntity.class.isAssignableFrom(c)) + } else if (LivingEntity.class.isAssignableFrom(c)) { watcherClass = LivingWatcher.class; - else + } else { watcherClass = FlagWatcher.class; + } } catch (Exception ex1) { ex1.printStackTrace(); }