Overview
Custom events allow you to create new trigger points in Skript that users can listen to. This enables deep integration between your addon and Skript scripts.Creating a SkriptEvent
All Skript events extend theSkriptEvent abstract class and define when and how they should be triggered.
Basic Structure
Real Example: Test Case Event
Here’s a real example from Skript’s testing framework:/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java:14-69
Registering Event Values
Event values allow expressions to retrieve data from your custom event.Registration
/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java:23-26
Usage in Scripts
Once registered, users can access these values:Creating Custom Bukkit Events
Often you’ll want to create your own Bukkit event that Skript can listen to.Define the Bukkit Event
Create the SkriptEvent
Fire the Event
Conditional Event Loading
You can control when events are loaded usingshouldLoadEvent():
/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java:56-58
This allows you to:
- Enable events only in certain game versions
- Require specific plugins to be installed
- Check configuration settings
Advanced Pattern Matching
Events can have complex patterns with captures:/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java:29-42
Event Documentation
Use Skript’s documentation annotations:Complete Example
Best Practices
Register event values
Register event values
Always register relevant event values so users can access data from your event using expressions like
event-player or event-string.Use clear patterns
Use clear patterns
Make event patterns intuitive and similar to existing Skript patterns.
Document thoroughly
Document thoroughly
Provide examples and descriptions so users understand when and how to use your event.
Handle null safely
Handle null safely
Always check for null values in event data and handle them gracefully.
Next Steps
Testing
Learn how to test your custom events and syntax
Addon Development
Back to addon development overview
