Skip to content

Latest commit

 

History

History
149 lines (102 loc) · 2.48 KB

Documentation.md

File metadata and controls

149 lines (102 loc) · 2.48 KB

API usage

Using as dependency

Include the following in your plugin's gradle project:

repositories {
    maven("https://repo.fancyplugins.de/releases")
    ...
}

dependencies {
    implementation("de.oliver:FancyNpcs:version")
    ...
}

You find the current version in the README.md file.

Creating and modifying NPCs

Getting an existing NPC

Npc npc = FancyNpcs.getInstance().getNpcManager().getNpc(npcName);

Creating a NPC

Npc npc = new Npc(npcName, location);
npc.create();
npc.spawnForAll();

Removing

npc.removeForAll();

Moving

npc.moveForAll(location);

Changing skin

SkinFetcher skin = new SkinFetcher(UUIDFetcher.getUUID(playerName).toString());
npc.updateSkin(skin);

Display name

npc.updateDisplayName(displayName);

Equipment

npc.addEquipment(equipmentSlot, CraftItemStack.asNMSCopy(item));
npc.removeForAll();
npc.create();
npc.spawnForAll();

Server command

npc.setServerCommand(command);

Server command

npc.setPlayerCommand(command);

Show in tab

npc.updateShowInTab(shouldShowInTab);

Glowing

npc.updateGlowing(shouldGlow);

Glowing color

ChatFormatting color = ChatFormatting.getByName("color name");
npc.updateGlowingColor(color);
ChatFormatting color = ChatFormatting.getByName("color name");
npc.updateGlowingColor(ChatFormatting.RED);

Turn to player

npc.setTurnToPlayer(shouldTurnToPlayer);
npc.moveForAll(npc.getLocation()); // initially refreshing (optional)

Custom interact

npc.setOnClick(player -> {
    // do something with the player
});

Events

NpcCreateEvent

Is fired when a new NPC is being created.
Contains the player who created the NPC and the NPC object.

NpcRemoveEvent

Is fired when a NPC is being deleted.
Contains the player who removed the NPC and the NPC object.

NpcModifyEvent

Is fired when a NPC is being modified.
Contains the player who modified the NPC, the modification and the NPC object.

NpcInteractEvent

Is fired when a player interacts with a NPC.
Contains the player who interacted, the NPC and all actions.

NpcSpawnEvent

Is fired when a NPC is being spawned. This can happen when a player joins, a player switches the world or the NPC is being modified.
Contains the NPC that is being spawned and the player to whom the spawn packets are being sent.