NpcLib is a library for creating NPCs in Minecraft. It is designed to be easy to use and to be able to be used in any Bukkit plugin.
Feature | Description |
---|---|
NPCs | 🏗️ Create/Delete NPCs with a name, skin and position |
Interactions | 🎧 Listen to click events on NPCs |
- Add support for animations
- Install latest version of ProtocolLib on your server.
- Download the latest release and put it in your server
plugins
folder. - Import the NpcLib API in your project using Maven or Gradle.
- Put the
depends: [NpcLib]
in your plugin.yml.
repositories {
maven(url = "https://nexus.codinbox.fr/repository/maven-public/")
}
dependencies {
compileOnly("fr.codinbox.npclib:api:2.8.1")
}
A NPC holder is an object that manages the creation and deletion of NPCs for a specific plugin. A signe plugin can only have one NPC holder.
In order to create an NPC holder, you must use the NpcLib.api().createHolder(Plugin)
method.
It is recommended to create the holder in the onEnable
method of your plugin.
You can then use your holder in order to create and manage your NPCs!
class MyNpcSpawner {
private static final String SKIN_TEXTURE = null; // Place your skin texture here
private static final String SKIN_SIGNATURE = null; // Place your skin signature here
private final NpcHolder npcHolder;
public MyNpcManager(NpcHolder npcHolder) {
this.npcHolder = npcHolder;
}
public void spawnNpc() {
Location location = new Location(Bukkit.getWorld("world"), 0, 0, 0); // The NPC location
Skin skin = Skin.fromValueAndSignature(SKIN_TEXTURE, SKIN_SIGNATURE); // The NPC skin
Npc npc = this.npcHolder.createNpc(
NpcConfig.create(location, skin)
.setGlobal(true) // Display the NPC to all players
.setRenderDistance(64) // The NPC can be seen from 64 blocks away
);
// From now, every player will see the NPC
npc.getClickedListeners().add(event -> {
var player = event.getPlayer();
player.sendMessage("You clicked on the NPC!");
});
}
}
After creating the NPC, the holder will automatically manage the lifecycle of the NPC :)