Skip to content

Creating Custom Event Listeners

BDX edited this page May 31, 2023 · 6 revisions

Creating Custom Event Listeners

This guide will outline how to create custom command listeners in Nhplugin and Javascript

Creating the Event Listener File

  • In the events directory (/plugins/Nhplugin/scripts/events) is where all event listener scripts are created
  • For this example we are going to make a file called playerJoinEvent.js in the events folder

Creating the Function

  • In any event handler the function will follow the format below:
function <event_handler_name>(event, nhplugin){}
  • The event parameter is the instance of the event
  • The Nhplugin param is the instance of Nhlugin allowing access to the inbuilt utility classes, functions, and data
  • For the playerJoinEvent.js file the following will be used:
function playerJoinEvent(event, nhplugin){

    var player = event.getPlayer()
    Bukkit.broadcast(player.getDisplayName() + " has joined the server", "nh.join_alerts")

}
  • This will broadcast to all players with the nh.chat permission when a user joins the server

Registering the Event Listener

  • To register the event listener, the eventHandler.js script in the /plugins/Nhplugin/scripts/eventHandler.js must be modified.

Clone this wiki locally