Skip to content

Commit

Permalink
Add string component cache
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Dec 22, 2022
1 parent d819ae9 commit 4c3701a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/main/java/net/citizensnpcs/api/npc/AbstractNPC.java
Expand Up @@ -89,8 +89,9 @@ public void setPersistent(String key, Object data) {
}
}
};
protected Object minecraftComponentCache;
protected Object nameComponentCache;
private String name;
protected String nameStringComponentCache;
private final NPCRegistry registry;
private final List<String> removedTraits = Lists.newArrayList();
private final List<Runnable> runnables = Lists.newArrayList();
Expand All @@ -103,7 +104,8 @@ protected AbstractNPC(UUID uuid, int id, String name, NPCRegistry registry) {
this.id = id;
this.registry = registry;
this.name = name;
minecraftComponentCache = Messaging.minecraftComponentFromRawMessage(name);
nameStringComponentCache = Messaging.parseComponents(name);
nameComponentCache = Messaging.minecraftComponentFromRawMessage(name);
CitizensAPI.getTraitFactory().addDefaultTraits(this);
}

Expand Down Expand Up @@ -476,7 +478,8 @@ public void setName(String name) {
NPCRenameEvent event = new NPCRenameEvent(this, this.name, name);
Bukkit.getPluginManager().callEvent(event);
this.name = event.getNewName();
minecraftComponentCache = Messaging.minecraftComponentFromRawMessage(this.name);
nameComponentCache = Messaging.minecraftComponentFromRawMessage(this.name);
nameStringComponentCache = Messaging.parseComponents(this.name);

if (!isSpawned())
return;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/citizensnpcs/api/util/ItemStorage.java
Expand Up @@ -308,7 +308,7 @@ private static <T extends ItemMeta> T ensureMeta(ItemStack stack) {

public static ItemStack loadItemStack(DataKey root) {
Material material = null;
if (root.keyExists("type_key")) {
if (root.keyExists("type_key") && SpigotUtil.isUsing1_13API()) {
NamespacedKey key = new NamespacedKey(root.getString("type_namespace", "minecraft"),
root.getString("type_key"));
material = Material.getMaterial(key.getKey().toUpperCase(), false);
Expand Down

0 comments on commit 4c3701a

Please sign in to comment.