mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-29 23:57:42 +02:00
HologramTrait now alters hologram height if name visibility is toggled
This commit is contained in:
parent
f9bb877e85
commit
49559e26bc
@ -33,6 +33,7 @@ public class HologramTrait extends Trait {
|
|||||||
private Location currentLoc;
|
private Location currentLoc;
|
||||||
@Persist
|
@Persist
|
||||||
private HologramDirection direction = HologramDirection.BOTTOM_UP;
|
private HologramDirection direction = HologramDirection.BOTTOM_UP;
|
||||||
|
private boolean lastNameplateVisible;
|
||||||
@Persist
|
@Persist
|
||||||
private double lineHeight = -1;
|
private double lineHeight = -1;
|
||||||
private final List<NPC> lineHolograms = Lists.newArrayList();
|
private final List<NPC> lineHolograms = Lists.newArrayList();
|
||||||
@ -151,9 +152,10 @@ public class HologramTrait extends Trait {
|
|||||||
public void onSpawn() {
|
public void onSpawn() {
|
||||||
if (!npc.isSpawned())
|
if (!npc.isSpawned())
|
||||||
return;
|
return;
|
||||||
|
lastNameplateVisible = Boolean
|
||||||
|
.parseBoolean(npc.data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString());
|
||||||
currentLoc = npc.getStoredLocation();
|
currentLoc = npc.getStoredLocation();
|
||||||
if (npc.requiresNameHologram()
|
if (npc.requiresNameHologram() && lastNameplateVisible) {
|
||||||
&& Boolean.parseBoolean(npc.data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString())) {
|
|
||||||
nameNPC = createHologram(npc.getFullName(), 0);
|
nameNPC = createHologram(npc.getFullName(), 0);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
@ -182,18 +184,20 @@ public class HologramTrait extends Trait {
|
|||||||
if (currentLoc == null) {
|
if (currentLoc == null) {
|
||||||
currentLoc = npc.getStoredLocation();
|
currentLoc = npc.getStoredLocation();
|
||||||
}
|
}
|
||||||
if (npc.requiresNameHologram()) {
|
boolean nameplateVisible = Boolean
|
||||||
boolean visible = Boolean
|
|
||||||
.parseBoolean(npc.data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString());
|
.parseBoolean(npc.data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString());
|
||||||
if (nameNPC != null && !visible) {
|
if (npc.requiresNameHologram()) {
|
||||||
|
if (nameNPC != null && !nameplateVisible) {
|
||||||
nameNPC.destroy();
|
nameNPC.destroy();
|
||||||
nameNPC = null;
|
nameNPC = null;
|
||||||
} else if (nameNPC == null && visible) {
|
} else if (nameNPC == null && nameplateVisible) {
|
||||||
nameNPC = createHologram(npc.getFullName(), 0);
|
nameNPC = createHologram(npc.getFullName(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean update = currentLoc.getWorld() != npc.getStoredLocation().getWorld()
|
boolean update = currentLoc.getWorld() != npc.getStoredLocation().getWorld()
|
||||||
|| currentLoc.distance(npc.getStoredLocation()) >= 0.001;
|
|| currentLoc.distance(npc.getStoredLocation()) >= 0.001 || lastNameplateVisible != nameplateVisible;
|
||||||
|
lastNameplateVisible = nameplateVisible;
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
currentLoc = npc.getStoredLocation();
|
currentLoc = npc.getStoredLocation();
|
||||||
}
|
}
|
||||||
@ -208,7 +212,8 @@ public class HologramTrait extends Trait {
|
|||||||
if (!hologramNPC.isSpawned())
|
if (!hologramNPC.isSpawned())
|
||||||
continue;
|
continue;
|
||||||
if (update) {
|
if (update) {
|
||||||
hologramNPC.teleport(currentLoc.clone().add(0, getEntityHeight() + getHeight(i), 0),
|
hologramNPC.teleport(
|
||||||
|
currentLoc.clone().add(0, getEntityHeight() + getHeight(nameplateVisible ? i : i - 1), 0),
|
||||||
TeleportCause.PLUGIN);
|
TeleportCause.PLUGIN);
|
||||||
}
|
}
|
||||||
if (i >= lines.size()) {
|
if (i >= lines.size()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user