Skip to content

Commit

Permalink
Add some metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Apr 3, 2014
1 parent 9c8b636 commit 25cd562
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/main/java/net/citizensnpcs/api/npc/AbstractNPC.java
Expand Up @@ -204,10 +204,10 @@ public SpeechController getDefaultSpeechController() {

@Override
public String getFullName() {
int nameLength = 64;
int nameLength = getTrait(MobType.class).getType() == EntityType.PLAYER ? 16 : 64;
if (name.length() > nameLength) {
Messaging.severe("ID", id, "created with name length greater than 64, truncating", name, "to",
name.substring(0, nameLength));
Messaging.severe("ID", id, "created with name length greater than " + nameLength + ", truncating", name,
"to", name.substring(0, nameLength));
name = name.substring(0, nameLength);
}
return name;
Expand Down Expand Up @@ -338,6 +338,8 @@ public void removeTrait(Class<? extends Trait> traitClass) {

@Override
public void save(DataKey root) {
if (!metadata.get(NPC.SHOULD_SAVE_METADATA, true))
return;
metadata.saveTo(root.getRelative("metadata"));
root.setString("name", getFullName());
root.setString("uuid", uuid.toString());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/citizensnpcs/api/npc/NPC.java
Expand Up @@ -308,7 +308,9 @@ public interface NPC extends Agent, Cloneable {
public static final String MINECART_ITEM_METADATA = "minecart-item-name";
public static final String MINECART_OFFSET_METADATA = "minecart-item-offset";
public static final String NAMEPLATE_VISIBLE_METADATA = "nameplate-visible";
public static final String PLAYER_SKIN_NAME_METADATA = "player-skin-name";
public static final String RESPAWN_DELAY_METADATA = "respawn-delay";
public static final String SHOULD_SAVE_METADATA = "should-save";
public static final String SWIMMING_METADATA = "swim";
public static final String TARGETABLE_METADATA = "protected-target";
}
Expand Up @@ -82,8 +82,9 @@ public void store(NPC npc) {

@Override
public void storeAll(NPCRegistry registry) {
for (NPC npc : registry)
for (NPC npc : registry) {
store(npc);
}
}

public static NPCDataStore create(Storage storage) {
Expand Down

0 comments on commit 25cd562

Please sign in to comment.