Core Event Classes
Event
The base class for all events in PocketMine-MP.Returns the name of the event class
Calls all registered event handlers for this event
Returns whether any handlers are registered for this event class. Useful for optimizing hot code paths to avoid unnecessary event object creation.
Cancellable
Interface implemented by events that can be cancelled. Cancelling an event prevents its action from occurring.Returns whether the event is currently cancelled
Cancels the event (provided by CancellableTrait)
Uncancels the event (provided by CancellableTrait)
Event Priorities
Event handlers are called in priority order:- LOWEST (5) - Called first, allows other plugins to customize the outcome
- LOW (4) - Low importance
- NORMAL (3) - Default priority
- HIGH (2) - High importance
- HIGHEST (1) - Critical, has final say
- MONITOR (0) - Called last, for monitoring only (should not modify the event)
Creating Event Listeners
To listen to events, create a class that implements theListener interface:
Event Handler Requirements
For a method to be recognized as an event handler, it must:- Be public
- Not be static
- Accept exactly one parameter of an Event type (or its subclass)
- The event parameter must not be abstract (unless annotated with
@allowHandle)
Handler Annotations
You can use PHPDoc annotations to control handler behavior:@priority <PRIORITY>- Sets the priority (LOWEST, LOW, NORMAL, HIGH, HIGHEST, MONITOR)@handleCancelled- Handler will be called even if the event is cancelled@notHandler- Prevents a method from being registered as a handler
Registering Events
There are two ways to register event listeners:Method 1: Class implements Listener
Method 2: Manual registration
Event Inheritance
Event handlers receive the specified event and all its subclasses. For example:Performance Optimization
UseEvent::hasHandlers() to avoid creating event objects unnecessarily:
Base Event Categories
Player Events
Events related to player actions and state changes
Block Events
Events related to block placement, breaking, and changes
Entity Events
Events related to entity spawning, damage, and behavior
World Events
Events related to world loading, chunks, and changes
Server Events
Events related to server operations and networking