-
Notifications
You must be signed in to change notification settings - Fork 0
NPCs
Rapha149 edited this page Jan 29, 2024
·
4 revisions
To create an NPC, you first have to adjust it's settings via the NPCBuilder and then add it using NPCUtil#addNPC:
// Create the NPC's skin
NPCSkin skin = new NPCSkin(
"ewogICJ0a...", // texture
"vP7de1V4M...", // signature
NPCSkinPart.getDefaultParts() // list of skin parts to dispaly
);
// Create the builder
NPCBuilder builder = new NPCBuilder(
"mynpc", // unique identifier to easily remove the NPC if needed
"§aJohn", // name of the NPC, can contain color codes
skin, // the NPC's skin (see above)
new Location(Bukkit.getWorld("world"), 0, 70, 0, 90F, 0F), // location of the NPC, can contain yaw and pitch
player -> { // npc use listener
player.sendMessage("That tickled!");
}
);
// here you can call optional methods of the builder to further adjust the settings for your npcs
// see the javadoc for explanation of the methods
// add the npc
NPCUtil.addNPC(builder.build());To remove an NPC, all you have to do is call NPCUtil#removeNPC:
NPCUtil.removeNPC("mynpc"); // you have to use the earlier defined identifier hereThe NPC will automatically be removed for all players.
You can also check if an NPC with a specific identifier exists using NPCUtil#isNPC or get a set of all identifiers using NPCUtil#getNPCIdentifiers().