-
-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internal Events API #5552
Internal Events API #5552
Conversation
2.7? |
src/main/java/org/skriptlang/skript/api/event/EventRegister.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we allow for EventRegister
s to define a parent EventRegister
? This would let Script
's event register to define ScriptLoader
's event register as parent (= get events will include the parent, so duplicate code can be prevented). This would require ScriptLoaderEvent
to extend ScriptEvent
(because of generics).
Example:
// Old
eventRegister.getEvents(ScriptLoaderEvent.ScriptUnloadEvent.class)
.forEach(eventHandler -> eventHandler.onUnload(parser, script));
script.getEventRegister().getEvents(ScriptLoaderEvent.ScriptUnloadEvent.class)
.forEach(eventHandler -> eventHandler.onUnload(parser, script));
// New
script.getEventRegister().getEvents(ScriptLoaderEvent.ScriptUnloadEvent.class)
.forEach(eventHandler -> eventHandler.onUnload(parser, script));
Let me know if you have any questions :)
Discussed on Discord a little, but this might be difficult for ScriptEvents as ScriptLoader will eventually get unique events that only apply to it. This class will be extendable by developers though if they would have a case for this kind of functionality. |
This is an alternative for the now-deprecated Bukkit implementation
bd134d0
to
3f08853
Compare
The event classes have been refactored as inner classes of the classes they concern. This is to help accomdate future API changes (e.g. to ParserInstance, ScriptLoader, etc.) where the events may need to change.
conflicts need resolving! |
Introduction
This PR aims to refactor and expand upon the existing Script Event API.
This PR does NOT implement backwards compatibility of the existing Script Event API. The API was marked as experimental, and I do not believe it has widely been used. However, backwards compatibility may be implemented if we see it as important.
Event Registry
A generic container for event instances. Events may be registered/unregistered. This simply serves for standardizing the event registration process across Skript. Below is an example of registering an event on ScriptLoader:
Events
Events have been added that can have handlers registered with ScriptLoader (global) and specific Script instances. To explain further, the example above registered an event with the ScriptLoader that logs when a Script has been unloaded. It would also be possible to register a handler for that event on a specific Script instance (to detect when that Script has been unloaded):
ScriptPreInitEvent
This event is a replacement for the Bukkit-based PreScriptLoadEvent. This event triggers right before the collection of Configs (pre-parsed script files) are loaded into actual Script instances. The collection is modifiable which allows the prevention of certain Configs from loading into Scripts.
ScriptInitEvent
This event is triggered right after a Script has been loaded into the ScriptLoader, but not yet fully initialized.
ScriptLoadEvent
This event is triggered right after a Script has finished loading. That is, all of its Structures have finished loading.
ScriptUnloadEvent
This event is triggered right before a Script is unloaded in the ScriptLoader. All data/Structures are still available.
ScriptActivityChangeEvent
This event is triggered when the activity status of a ParserInstance changes (resulting in a Script being made active/inactive). This would trigger through the usage of
ParserInstance#setActive(Script)
andParserInstance#setInactive()
. This could be useful for managing data on Scripts that should reset when it is not active in a ParserInstance.Target Minecraft Versions: Any
Requirements: None
Related Issues: N/A