From 7f504ee2d9e6c9a2d0ff0455607693a6a0b1c9d8 Mon Sep 17 00:00:00 2001 From: OmerBenGera Date: Fri, 24 May 2024 13:27:43 +0300 Subject: [PATCH] Add `NPC` metadata tag to chunk loader NPCs (#82) --- .../bgsoftware/wildloaders/handlers/NPCHandler.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bgsoftware/wildloaders/handlers/NPCHandler.java b/src/main/java/com/bgsoftware/wildloaders/handlers/NPCHandler.java index bf8cbca..509ff51 100644 --- a/src/main/java/com/bgsoftware/wildloaders/handlers/NPCHandler.java +++ b/src/main/java/com/bgsoftware/wildloaders/handlers/NPCHandler.java @@ -7,7 +7,9 @@ import com.bgsoftware.wildloaders.npc.NPCIdentifier; import com.bgsoftware.wildloaders.utils.database.Query; import com.google.common.collect.Maps; import org.bukkit.Location; +import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; +import org.bukkit.metadata.FixedMetadataValue; import java.util.Collections; import java.util.Map; @@ -34,7 +36,12 @@ public final class NPCHandler implements NPCManager { @Override public ChunkLoaderNPC createNPC(Location location) { - return npcs.computeIfAbsent(new NPCIdentifier(location), i -> plugin.getNMSAdapter().createNPC(i.getSpawnLocation(), getUUID(i))); + return npcs.computeIfAbsent(new NPCIdentifier(location), i -> { + ChunkLoaderNPC npc = plugin.getNMSAdapter().createNPC(i.getSpawnLocation(), getUUID(i)); + Entity npcEntity = npc.getPlayer(); + npcEntity.setMetadata("NPC", new FixedMetadataValue(plugin, true)); + return npc; + }); } @Override @@ -54,6 +61,9 @@ public final class NPCHandler implements NPCManager { .setLocation(identifier.getSpawnLocation()) .queue(npc.getUniqueId()); + Entity npcEntity = npc.getPlayer(); + npcEntity.removeMetadata("NPC", plugin); + npc.die(); }