Update dynamic name for non-player disguises

This commit is contained in:
libraryaddict 2020-05-11 15:22:02 +12:00
parent 0fe54d6683
commit f6eb0f14b7
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
2 changed files with 25 additions and 7 deletions

View File

@ -102,6 +102,9 @@ public abstract class Disguise {
private boolean tallDisguisesVisible = DisguiseConfig.isTallSelfDisguises(); private boolean tallDisguisesVisible = DisguiseConfig.isTallSelfDisguises();
private String[] multiName = new String[0]; private String[] multiName = new String[0];
private transient int[] armorstandIds = new int[0]; private transient int[] armorstandIds = new int[0];
@Getter
@Setter
private boolean dynamicName;
public Disguise(DisguiseType disguiseType) { public Disguise(DisguiseType disguiseType) {
this.disguiseType = disguiseType; this.disguiseType = disguiseType;
@ -126,6 +129,10 @@ public abstract class Disguise {
String[] oldName = multiName; String[] oldName = multiName;
multiName = name; multiName = name;
if (Arrays.equals(oldName, name)) {
return;
}
if (!isDisguiseInUse()) { if (!isDisguiseInUse()) {
return; return;
} }
@ -192,6 +199,7 @@ public abstract class Disguise {
disguise.setVelocitySent(isVelocitySent()); disguise.setVelocitySent(isVelocitySent());
disguise.setModifyBoundingBox(isModifyBoundingBox()); disguise.setModifyBoundingBox(isModifyBoundingBox());
disguise.multiName = Arrays.copyOf(multiName, multiName.length); disguise.multiName = Arrays.copyOf(multiName, multiName.length);
disguise.setDynamicName(isDynamicName());
if (getWatcher() != null) { if (getWatcher() != null) {
disguise.setWatcher(getWatcher().clone(disguise)); disguise.setWatcher(getWatcher().clone(disguise));
@ -367,15 +375,19 @@ public abstract class Disguise {
new ComponentBuilder(LibsMsg.ACTION_BAR_MESSAGE.get(getDisguiseName())).create()); new ComponentBuilder(LibsMsg.ACTION_BAR_MESSAGE.get(getDisguiseName())).create());
} }
if (Disguise.this instanceof PlayerDisguise && ((PlayerDisguise) Disguise.this).isDynamicName()) { if (isDynamicName()) {
String name = getEntity().getCustomName(); String name = getEntity().getCustomName();
if (name == null) { if (name == null) {
name = ""; name = "";
} }
if (!((PlayerDisguise) Disguise.this).getName().equals(name)) { if (isPlayerDisguise()) {
((PlayerDisguise) Disguise.this).setName(name); if (!((PlayerDisguise) Disguise.this).getName().equals(name)) {
((PlayerDisguise) Disguise.this).setName(name);
}
} else {
getWatcher().setCustomName(name);
} }
} }
} }
@ -1161,6 +1173,16 @@ public abstract class Disguise {
System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(330)); System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(330));
} }
if (isDynamicName() && !isPlayerDisguise()) {
String name = getEntity().getCustomName();
if (name == null) {
name = "";
}
getWatcher().setCustomName(name);
}
makeBossBar(); makeBossBar();
return true; return true;

View File

@ -31,9 +31,6 @@ public class PlayerDisguise extends TargetedDisguise {
*/ */
private boolean explicitNameVisible = false; private boolean explicitNameVisible = false;
private UUID uuid = UUID.randomUUID(); private UUID uuid = UUID.randomUUID();
@Getter
@Setter
private boolean dynamicName;
private volatile DisguiseUtilities.DScoreTeam scoreboardName; private volatile DisguiseUtilities.DScoreTeam scoreboardName;
@Getter @Getter
private boolean upsideDown; private boolean upsideDown;
@ -226,7 +223,6 @@ public class PlayerDisguise extends TargetedDisguise {
disguise.setName(getName()); disguise.setName(getName());
disguise.nameVisible = isNameVisible(); disguise.nameVisible = isNameVisible();
disguise.explicitNameVisible = explicitNameVisible; disguise.explicitNameVisible = explicitNameVisible;
disguise.setDynamicName(isDynamicName());
disguise.setUpsideDown(isUpsideDown()); disguise.setUpsideDown(isUpsideDown());
clone(disguise); clone(disguise);