Respect name visibility properly

This commit is contained in:
fullwall 2020-07-10 12:19:29 +08:00
parent 44b6da408d
commit 652a68a79d
2 changed files with 11 additions and 3 deletions

View File

@ -399,7 +399,7 @@ public class CitizensNPC extends AbstractNPC {
if (!getEntity().isCustomNameVisible()
&& !data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString().equals("hover")) {
getEntity().setCustomName("");
} else {
} else if (!requiresNameHologram()) {
nameVisibility = true;
getEntity().setCustomName(getFullName());
}

View File

@ -77,9 +77,8 @@ public class HologramTrait extends Trait {
private void load() {
currentLoc = npc.getStoredLocation();
int i = 0;
if (npc.requiresNameHologram()) {
if (npc.requiresNameHologram() && npc.data().get(NPC.NAMEPLATE_VISIBLE_METADATA, true)) {
nameNPC = createHologram(npc.getFullName(), 0);
npc.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, false);
}
for (String line : lines) {
hologramNPCs.add(createHologram(Placeholders.replace(line, null, npc), getHeight(i)));
@ -114,6 +113,15 @@ public class HologramTrait extends Trait {
unload();
return;
}
if (npc.requiresNameHologram()) {
boolean visible = npc.data().get(NPC.NAMEPLATE_VISIBLE_METADATA, true);
if (nameNPC != null && !visible) {
nameNPC.destroy();
nameNPC = null;
} else if (nameNPC == null && visible) {
nameNPC = createHologram(npc.getFullName(), 0);
}
}
boolean update = currentLoc.distanceSquared(npc.getStoredLocation()) >= 0.01;
if (update) {
currentLoc = npc.getStoredLocation();