Skip to content

API Events

Eisi05 edited this page Jan 21, 2026 · 1 revision

NPC interaction

NpcAPI fires NpcInteractEvent when a player interacts with an NPC.

  • NpcInteractListener calls npc.getClickEvent().call(event) automatically.
  • You can either set a click action on the NPC or listen to the Bukkit event.

Option A: per-NPC click handler

npc.setClickEvent(event -> {
  event.getPlayer().sendMessage("Clicked: " + event.getNpc().getUUID());
});

Note:

  • NpcClickAction is Serializable and is saved when you call npc.save(). Avoid lambdas that capture non-serializable objects.

Option B: global listener

@EventHandler
public void onNpcInteract(NpcInteractEvent event) {
  // event.getPlayer(), event.getNpc(), event.getAction()
}

Showing / hiding events

When an NPC is shown to a player:

  • NpcPreShowEvent (cancellable)
    • provides wasViewer() to distinguish first show vs refresh
  • NpcPostShowEvent
    • also provides wasViewer()

When an NPC is hidden from a player:

  • NpcHideEvent

Walking events

When walking starts:

  • NpcStartWalkingEvent (cancellable)
    • you can modify speed and the changeRealLocation flag

When walking stops:

  • NpcStopWalkingEvent
    • provides a WalkingResult (SUCCESS/CANCELLED)
    • you can decide whether the NPC’s real location should be updated

Clone this wiki locally