mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-04-19 10:46:07 +02:00
Adjust hologram name NPC implementation
This commit is contained in:
parent
ed4f43a5aa
commit
85c91780c9
@ -47,7 +47,7 @@ public class HologramTrait extends Trait {
|
|||||||
@Persist
|
@Persist
|
||||||
private double lineHeight = -1;
|
private double lineHeight = -1;
|
||||||
private final List<HologramLine> lines = Lists.newArrayList();
|
private final List<HologramLine> lines = Lists.newArrayList();
|
||||||
private NPC nameNPC;
|
private HologramLine nameLine;
|
||||||
private final NPCRegistry registry = CitizensAPI.createCitizensBackedNPCRegistry(new MemoryNPCDataStore());
|
private final NPCRegistry registry = CitizensAPI.createCitizensBackedNPCRegistry(new MemoryNPCDataStore());
|
||||||
private int t;
|
private int t;
|
||||||
private boolean useTextDisplay;
|
private boolean useTextDisplay;
|
||||||
@ -191,7 +191,7 @@ public class HologramTrait extends Trait {
|
|||||||
* Note: this is implementation-specific and may be removed at a later date.
|
* Note: this is implementation-specific and may be removed at a later date.
|
||||||
*/
|
*/
|
||||||
public Entity getNameEntity() {
|
public Entity getNameEntity() {
|
||||||
return nameNPC != null && nameNPC.isSpawned() ? nameNPC.getEntity() : null;
|
return nameLine != null && nameLine.hologram.isSpawned() ? nameLine.hologram.getEntity() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -204,9 +204,9 @@ public class HologramTrait extends Trait {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDespawn() {
|
public void onDespawn() {
|
||||||
if (nameNPC != null) {
|
if (nameLine != null) {
|
||||||
nameNPC.destroy();
|
nameLine.removeNPC();
|
||||||
nameNPC = null;
|
nameLine = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (HologramLine line : lines) {
|
for (HologramLine line : lines) {
|
||||||
@ -228,7 +228,8 @@ public class HologramTrait extends Trait {
|
|||||||
.parseBoolean(npc.data().<Object> get(NPC.Metadata.NAMEPLATE_VISIBLE, true).toString());
|
.parseBoolean(npc.data().<Object> get(NPC.Metadata.NAMEPLATE_VISIBLE, true).toString());
|
||||||
currentLoc = npc.getStoredLocation();
|
currentLoc = npc.getStoredLocation();
|
||||||
if (npc.requiresNameHologram() && lastNameplateVisible) {
|
if (npc.requiresNameHologram() && lastNameplateVisible) {
|
||||||
nameNPC = createHologram(Placeholders.replace(npc.getRawName(), null, npc), 0);
|
nameLine = new HologramLine(npc.getRawName(), false);
|
||||||
|
nameLine.spawnNPC(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
@ -277,11 +278,12 @@ public class HologramTrait extends Trait {
|
|||||||
boolean nameplateVisible = Boolean
|
boolean nameplateVisible = Boolean
|
||||||
.parseBoolean(npc.data().<Object> get(NPC.Metadata.NAMEPLATE_VISIBLE, true).toString());
|
.parseBoolean(npc.data().<Object> get(NPC.Metadata.NAMEPLATE_VISIBLE, true).toString());
|
||||||
if (npc.requiresNameHologram()) {
|
if (npc.requiresNameHologram()) {
|
||||||
if (nameNPC != null && !nameplateVisible) {
|
if (nameLine != null && !nameplateVisible) {
|
||||||
nameNPC.destroy();
|
nameLine.removeNPC();
|
||||||
nameNPC = null;
|
nameLine = null;
|
||||||
} else if (nameNPC == null && nameplateVisible) {
|
} else if (nameLine == null && nameplateVisible) {
|
||||||
nameNPC = createHologram(Placeholders.replace(npc.getRawName(), null, npc), 0);
|
nameLine = new HologramLine(npc.getRawName(), false);
|
||||||
|
nameLine.spawnNPC(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,12 +302,12 @@ public class HologramTrait extends Trait {
|
|||||||
lastEntityHeight = getEntityHeight();
|
lastEntityHeight = getEntityHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nameNPC != null && nameNPC.isSpawned()) {
|
if (nameLine != null && nameLine.hologram.isSpawned()) {
|
||||||
if (updatePosition) {
|
if (updatePosition) {
|
||||||
nameNPC.teleport(currentLoc.clone().add(0, getEntityHeight(), 0), TeleportCause.PLUGIN);
|
nameLine.hologram.teleport(currentLoc.clone().add(0, getEntityHeight(), 0), TeleportCause.PLUGIN);
|
||||||
}
|
}
|
||||||
if (updateName) {
|
if (updateName) {
|
||||||
nameNPC.setName(Placeholders.replace(npc.getRawName(), null, npc));
|
nameLine.setText(npc.getRawName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,7 +409,6 @@ public class HologramTrait extends Trait {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class HologramLine implements Function<Player, String> {
|
private class HologramLine implements Function<Player, String> {
|
||||||
boolean hasPlayerPlaceholder;
|
|
||||||
NPC hologram;
|
NPC hologram;
|
||||||
double mb, mt;
|
double mb, mt;
|
||||||
boolean persist;
|
boolean persist;
|
||||||
@ -443,7 +444,6 @@ public class HologramTrait extends Trait {
|
|||||||
|
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
this.text = text == null ? "" : text;
|
this.text = text == null ? "" : text;
|
||||||
this.hasPlayerPlaceholder = Placeholders.containsPlayerPlaceholder(text);
|
|
||||||
|
|
||||||
if (hologram != null) {
|
if (hologram != null) {
|
||||||
String name = Placeholders.replace(text, null, npc);
|
String name = Placeholders.replace(text, null, npc);
|
||||||
|
Loading…
Reference in New Issue
Block a user