From 652a68a79d51702605354b430b2cc90beff9f6c9 Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 10 Jul 2020 12:19:29 +0800 Subject: [PATCH] Respect name visibility properly --- .../main/java/net/citizensnpcs/npc/CitizensNPC.java | 2 +- .../java/net/citizensnpcs/trait/HologramTrait.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index b1f4c4813..ea3226007 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -399,7 +399,7 @@ public class CitizensNPC extends AbstractNPC { if (!getEntity().isCustomNameVisible() && !data(). get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString().equals("hover")) { getEntity().setCustomName(""); - } else { + } else if (!requiresNameHologram()) { nameVisibility = true; getEntity().setCustomName(getFullName()); } diff --git a/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java b/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java index 94ead38aa..6f6281949 100644 --- a/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java @@ -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();