Promotion background
Halloween Season IS HERE!
10% off limited time offer!
limited time offer SAVE 10% NOW →
API

API

On this page, you will find everything you need to know about our API.

#API

Read NPCs, react to clicks, add your own action types or draw the nameplates yourself.

#Maven Repository

<repositories>
    <repository>
        <id>phoenixplugins</id>
        <url>https://repo.phoenixplugins.com/</url>
    </repository>
</repositories>

#Dependency

<dependency>
    <groupId>com.phoenixplugins.phoenixnpcs</groupId>
    <artifactId>api</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>

#Getting started

Add PhoenixNPCs to your plugin.yml so your plugin loads after it.

depend: [PhoenixNPCs]

Use softdepend instead if your plugin should still work without it, and check PhoenixNPCsAPI.isAvailable() before calling anything.

if (!PhoenixNPCsAPI.isAvailable()) {
    return;
}

NpcPlugin npcs = PhoenixNPCsAPI.get();
Method Returns
getNpc(String identifier) One NPC by its id, as an Optional
getNpcs() Every loaded NPC
getNpcsByTag(String tag) Every NPC with that tag
registerAction(String type, String syntax, NpcActionHandler handler) Adds an action type, see below
unregisterAction(String type) Removes an action type you added
setNameplateProvider(NameplateProvider provider) Draws every nameplate and indicator with your own code, null to go back to the built-in ones

#The NPC

Method Returns
getIdentifier(), getDisplayName(), getTags(), isEnabled() The NPC's settings
getLocation() Where the NPC was placed
getCurrentLocation() Where it is now, which differs while it walks
getNameplateLocation() Where its name is drawn
getViewerIds() The players who can see it now
isVisibleTo(Player player) Whether that player can see it
refreshNameplate() Redraws the name, for example after a placeholder changed
runActions(Player player, List<String> actions) Runs actions for a player as if this NPC ran them

#Custom Actions

A registered type shows in the editor's action builder and in /pnpc action, with a single text field. The handler gets the NPC, the player and everything after the type. Return false to stop the actions after it.

PhoenixNPCsAPI.get().registerAction("QUEST", "<quest>", (npc, player, argument) -> {
    return quests.start(player, argument);
});

Unregister it in your onDisable. An NPC that still lists a type nobody registered logs a warning when clicked and skips that action.

Last updated about 2 hours ago
My Cart (0 items)

Oops... looks like the spiders padded through here

Add products to your cart and remove them from here Lets buy