Fixed being unable to set the disguise as a baby
This commit is contained in:
parent
5fe3f03622
commit
30c6266749
@ -42,11 +42,15 @@ public class Disguise {
|
|||||||
private boolean viewSelfDisguise = DisguiseAPI.isViewDisguises();
|
private boolean viewSelfDisguise = DisguiseAPI.isViewDisguises();
|
||||||
private FlagWatcher watcher;
|
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
|
// Set the disguise type
|
||||||
disguiseType = newType;
|
disguiseType = newType;
|
||||||
// Set the option to replace the sounds
|
// Set the option to replace the sounds
|
||||||
setReplaceSounds(doSounds);
|
setReplaceSounds(doSounds);
|
||||||
|
// Get if they are a adult now..
|
||||||
|
boolean isAdult = !(this instanceof MobDisguise && !((MobDisguise) this).isAdult());
|
||||||
try {
|
try {
|
||||||
// Construct the FlagWatcher from the stored class
|
// Construct the FlagWatcher from the stored class
|
||||||
setWatcher((FlagWatcher) getType().getWatcherClass().getConstructor(Disguise.class).newInstance(this));
|
setWatcher((FlagWatcher) getType().getWatcherClass().getConstructor(Disguise.class).newInstance(this));
|
||||||
@ -54,11 +58,12 @@ public class Disguise {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
// Set the disguise if its a baby or not
|
// Set the disguise if its a baby or not
|
||||||
if (this instanceof MobDisguise && !((MobDisguise) this).isAdult()) {
|
if (isAdult) {
|
||||||
if (getWatcher() instanceof AgeableWatcher)
|
if (getWatcher() instanceof AgeableWatcher) {
|
||||||
getWatcher().setValue(12, -24000);
|
((AgeableWatcher) getWatcher()).setAdult(false);
|
||||||
else if (getWatcher() instanceof ZombieWatcher)
|
} else if (getWatcher() instanceof ZombieWatcher) {
|
||||||
getWatcher().setValue(12, (byte) 1);
|
((ZombieWatcher) getWatcher()).setAdult(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// If the disguise type is a wither, set the flagwatcher value for the skeleton to a wither skeleton
|
// If the disguise type is a wither, set the flagwatcher value for the skeleton to a wither skeleton
|
||||||
if (getType() == DisguiseType.WITHER_SKELETON)
|
if (getType() == DisguiseType.WITHER_SKELETON)
|
||||||
@ -246,6 +251,7 @@ public class Disguise {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canHearSelfDisguise() {
|
public boolean canHearSelfDisguise() {
|
||||||
@ -253,7 +259,7 @@ public class Disguise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Disguise clone() {
|
public Disguise clone() {
|
||||||
Disguise disguise = new Disguise(getType(), replaceSounds());
|
Disguise disguise = new Disguise().createDisguise(getType(), replaceSounds());
|
||||||
disguise.setViewSelfDisguise(viewSelfDisguise());
|
disguise.setViewSelfDisguise(viewSelfDisguise());
|
||||||
return disguise;
|
return disguise;
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,13 @@ public class MiscDisguise extends Disguise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds, int id, int data) {
|
public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds, int id, int data) {
|
||||||
super(disguiseType, replaceSounds);
|
|
||||||
if (id == -1)
|
if (id == -1)
|
||||||
id = disguiseType.getDefaultId();
|
id = disguiseType.getDefaultId();
|
||||||
if (data == -1)
|
if (data == -1)
|
||||||
data = disguiseType.getDefaultData();
|
data = disguiseType.getDefaultData();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
createDisguise(disguiseType, replaceSounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MiscDisguise(DisguiseType disguiseType, int id, int data) {
|
public MiscDisguise(DisguiseType disguiseType, int id, int data) {
|
||||||
@ -40,13 +40,13 @@ public class MiscDisguise extends Disguise {
|
|||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public MiscDisguise(EntityType entityType, boolean replaceSounds, int id, int data) {
|
public MiscDisguise(EntityType entityType, boolean replaceSounds, int id, int data) {
|
||||||
super(DisguiseType.getType(entityType), replaceSounds);
|
|
||||||
if (id == -1)
|
if (id == -1)
|
||||||
id = DisguiseType.getType(entityType).getDefaultId();
|
id = DisguiseType.getType(entityType).getDefaultId();
|
||||||
if (data == -1)
|
if (data == -1)
|
||||||
data = DisguiseType.getType(entityType).getDefaultData();
|
data = DisguiseType.getType(entityType).getDefaultData();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
createDisguise(DisguiseType.getType(entityType), replaceSounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -18,8 +18,8 @@ public class MobDisguise extends Disguise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MobDisguise(DisguiseType disguiseType, boolean isAdult, boolean replaceSounds) {
|
public MobDisguise(DisguiseType disguiseType, boolean isAdult, boolean replaceSounds) {
|
||||||
super(disguiseType, replaceSounds);
|
|
||||||
this.isAdult = isAdult;
|
this.isAdult = isAdult;
|
||||||
|
createDisguise(disguiseType, replaceSounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -34,8 +34,8 @@ public class MobDisguise extends Disguise {
|
|||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public MobDisguise(EntityType entityType, boolean isAdult, boolean replaceSounds) {
|
public MobDisguise(EntityType entityType, boolean isAdult, boolean replaceSounds) {
|
||||||
super(DisguiseType.getType(entityType), replaceSounds);
|
|
||||||
this.isAdult = isAdult;
|
this.isAdult = isAdult;
|
||||||
|
createDisguise(DisguiseType.getType(entityType), replaceSounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MobDisguise clone() {
|
public MobDisguise clone() {
|
||||||
@ -58,7 +58,7 @@ public class MobDisguise extends Disguise {
|
|||||||
public boolean isAdult() {
|
public boolean isAdult() {
|
||||||
if (getWatcher() != null) {
|
if (getWatcher() != null) {
|
||||||
if (getWatcher() instanceof AgeableWatcher)
|
if (getWatcher() instanceof AgeableWatcher)
|
||||||
return true;
|
return ((AgeableWatcher) getWatcher()).isAdult();
|
||||||
else if (getWatcher() instanceof ZombieWatcher)
|
else if (getWatcher() instanceof ZombieWatcher)
|
||||||
return ((ZombieWatcher) getWatcher()).isAdult();
|
return ((ZombieWatcher) getWatcher()).isAdult();
|
||||||
return false;
|
return false;
|
||||||
|
@ -8,10 +8,10 @@ public class PlayerDisguise extends Disguise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PlayerDisguise(String name, boolean replaceSounds) {
|
public PlayerDisguise(String name, boolean replaceSounds) {
|
||||||
super(DisguiseType.PLAYER, replaceSounds);
|
|
||||||
if (name.length() > 16)
|
if (name.length() > 16)
|
||||||
name = name.substring(0, 16);
|
name = name.substring(0, 16);
|
||||||
playerName = name;
|
playerName = name;
|
||||||
|
createDisguise(DisguiseType.PLAYER, replaceSounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerDisguise clone() {
|
public PlayerDisguise clone() {
|
||||||
|
@ -126,12 +126,13 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
// There is no watcher for this entity, or a error was thrown.
|
// There is no watcher for this entity, or a error was thrown.
|
||||||
try {
|
try {
|
||||||
Class c = disguiseType.getEntityType().getEntityClass();
|
Class c = disguiseType.getEntityType().getEntityClass();
|
||||||
if (Ageable.class.isAssignableFrom(c))
|
if (Ageable.class.isAssignableFrom(c)) {
|
||||||
watcherClass = AgeableWatcher.class;
|
watcherClass = AgeableWatcher.class;
|
||||||
else if (LivingEntity.class.isAssignableFrom(c))
|
} else if (LivingEntity.class.isAssignableFrom(c)) {
|
||||||
watcherClass = LivingWatcher.class;
|
watcherClass = LivingWatcher.class;
|
||||||
else
|
} else {
|
||||||
watcherClass = FlagWatcher.class;
|
watcherClass = FlagWatcher.class;
|
||||||
|
}
|
||||||
} catch (Exception ex1) {
|
} catch (Exception ex1) {
|
||||||
ex1.printStackTrace();
|
ex1.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user