Add NPC metadata tag to chunk loader NPCs (#82)

This commit is contained in:
OmerBenGera 2024-05-24 13:27:43 +03:00
parent 1e3d79269e
commit 7f504ee2d9

View File

@ -7,7 +7,9 @@ import com.bgsoftware.wildloaders.npc.NPCIdentifier;
import com.bgsoftware.wildloaders.utils.database.Query; import com.bgsoftware.wildloaders.utils.database.Query;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
@ -34,7 +36,12 @@ public final class NPCHandler implements NPCManager {
@Override @Override
public ChunkLoaderNPC createNPC(Location location) { 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 @Override
@ -54,6 +61,9 @@ public final class NPCHandler implements NPCManager {
.setLocation(identifier.getSpawnLocation()) .setLocation(identifier.getSpawnLocation())
.queue(npc.getUniqueId()); .queue(npc.getUniqueId());
Entity npcEntity = npc.getPlayer();
npcEntity.removeMetadata("NPC", plugin);
npc.die(); npc.die();
} }