Event System Overview
Pumpkin’s event system allows plugins to listen and respond to game events like player actions, block changes, and server events. The system is async-first and supports priority-based execution.Event Handler Trait
Implement theEventHandler trait to handle specific events:
Non-Blocking Handlers
Usehandle() for non-blocking event handlers that run in parallel:
Blocking Handlers
Usehandle_blocking() for handlers that need to modify events or run sequentially:
Registering Event Handlers
Register event handlers in your plugin’son_load hook:
Event Priorities
Event handlers execute in priority order:- All blocking handlers run first, in priority order (Highest → Lowest)
- Then all non-blocking handlers run in parallel
Cancellable Events
Many events implement theCancellable trait:
Cancelling Events
Available Events
Player Events
Block Events
World Events
Server Events
Event Examples
Player Join Handler
Block Break Handler
Chat Handler
Creating Custom Events
You can create custom events using thePayload trait:
Firing Custom Events
Event Handler Best Practices
Do’s
- Use non-blocking handlers when possible for better performance
- Use blocking handlers when you need to modify events
- Set appropriate priorities based on handler dependencies
- Handle errors gracefully within handlers
- Keep handlers lightweight and fast
Don’ts
- Don’t perform expensive operations in handlers
- Don’t use blocking I/O in event handlers
- Don’t assume event execution order between same-priority handlers
- Don’t modify events in non-blocking handlers (use handle_blocking)
- Don’t cancel events unless absolutely necessary
Payload Trait
All events implement thePayload trait:
Next Steps
- Explore specific event types in the API reference
- Learn about command registration
- Study permission system integration
- Review complete plugin examples
