Fixed being unable to set the disguise as a baby

This commit is contained in:
Andrew 2013-09-18 09:30:58 +12:00
parent 5fe3f03622
commit 30c6266749
5 changed files with 23 additions and 16 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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;

View File

@ -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() {

View File

@ -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();
}