Simple API to create Minecraft NPC using spigot/bukkit Paper/Spigot version 1.8.8 (v1_8_R3)
In your plugin.yml
depend: [NPCAPI]
Pre load skin (most likely on plugin startup)
SkinLoader.loadSkinFromUUID(skinId, "uuid of the player skin");
note the skin id must be unique
Spawn NPC
NPC npc = new NPC(UUID.randomUUID(), "Your NPC name")
.setLocation(loc) // Set the npc location / looking direction
.setSkin(SkinLoader.getSkinById(0)) // Get the skin you are supposed to pre load using his id
.setCapeVisible(true); // Display or not the NPC cape and more option available like displaying the name
NPCManager.spawnNPC(npc, event.getPlayer()); // Spawn your new NPC
Create a new class used to listen the interaction with the NCP
public class YourClassName implements NPCPacket {
@Override
public void onLeftClick(Player player, int id) {
APlayer ap = APlayer.get(player);
for (NPC npc : ap.npcs) {
if (id == npc.getEntityId()) {
System.out.println(npc.getName());
}
}
}
@Override
public void onRightClick(Player player, int id) {
APlayer ap = APlayer.get(player);
for (NPC npc : ap.npcs) {
if (id == npc.getEntityId()) {
System.out.println(npc.getName());
}
}
}
}
On player join create the packet listener
PacketInteractListener.init(event.getPlayer(), new YourClassName()); //NOTE: YourClassName must be the name of you class implementing NPCPacket
And remove it when the player leave
PacketInteractListener.remove(event.getPlayer());
This is still WIP and this will never be a big project just a tool to create NPC faster for my future plugins