Listening to Events
Everything related to events listeners in scripts.
Scripts can register event listeners by using the in-built events
object.
Examples
The following are various examples of how the events object can be used
Simple event registration
// Declare the Java type
import "@bukkit.event.player.PlayerJoinEvent"
// Register a function to list to the given event
events.register(PlayerJoinEvent, onPlayerJoin);
// Function called when event is triggered
function onPlayerJoin(event) {
logger.info("Player {} joined the server!", event.getPlayer());
}
Prioritized listener registration
Please see The Bukkit Wiki for information about EventPriority.
import * as EventPrio from "@bukkit.event.EventPriority"
// Register a function to list to the given event with the LOWEST
// priority
events.register(PlayerJoinEvent, onPlayerJoin, EventPrio.LOWEST);
Ignoring cancelled events
This section is very similar to the past one, with simply one extra parameter
// The final parameter states whether events that have been cancelled by
// other listeners that were executed before this listener, should be ignored.
// If true, cancelled events won't call the given function, if false, they will
events.register(PlayerJoinEvent, onPlayerJoin, EventPrio.LOWEST, true);
Last modified March 19, 2023: Update listener.md (6653707)