Skip to content

Commit

Permalink
Add new method for name hologram
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 6, 2020
1 parent e132de8 commit 6084f58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/net/citizensnpcs/api/npc/AbstractNPC.java
Expand Up @@ -209,6 +209,10 @@ public SpeechController getDefaultSpeechController() {
return speechController;
}

private EntityType getEntityType() {
return isSpawned() ? getEntity().getType() : getTrait(MobType.class).getType();
}

@Override
public String getFullName() {
int nameLength = SpigotUtil.getMaxNameLength(getTrait(MobType.class).getType());
Expand Down Expand Up @@ -336,6 +340,13 @@ public void removeTrait(Class<? extends Trait> traitClass) {
}
}

@Override
public boolean requiresNameHologram() {
return getEntityType() != EntityType.ARMOR_STAND
&& ((name.length() > 16 && getEntityType() == EntityType.PLAYER)
|| !Placeholders.replace(name, null, this).equals(name));
}

@Override
public void save(DataKey root) {
if (!metadata.get(NPC.SHOULD_SAVE_METADATA, true))
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/citizensnpcs/api/npc/NPC.java
Expand Up @@ -228,6 +228,8 @@ public interface NPC extends Agent, Cloneable {
*/
public void removeTrait(Class<? extends Trait> trait);

public boolean requiresNameHologram();

/**
* Saves the {@link NPC} to the given {@link DataKey}. This includes all metadata, traits, and spawn information
* that will allow it to respawn at a later time via {@link #load(DataKey)}.
Expand Down

0 comments on commit 6084f58

Please sign in to comment.