Structure API
Description
This PR adds a new Structure API that is used for creating and registering top-level elements. It also includes a Structure-specific entry parsing system to simplify the usage of entries (like in command structures).
A priority system is also included to determine the order in which structures should initially load. This is particularly useful for things like function definitions.
Also included is a new Script object, with the goal of creating a consistent object to be used across Skript's loading and unloading processes. The Script object includes things such as events and script-specific data values. The "script warning" system has also been moved to this object. Many places across Skript where Config or File were used have been refactored to use this new Script object.
ScriptLoader and SkriptEventHandler have had methods reduced and removed in an effort to promote system isolation / more "softcoding" of systems.
It converts and improves Skript's current structures:
- Aliases
- Makes use of the script-data system to store script aliases
- Commands (makes use of the new Structure entry system)
- Makes use of the new Structure entry system
- Command reloading handling has been moved/isolated to the new Command Structure. Commands are now synced on load AND unload (also fixes an issue that commands wouldn't be synced when a script was unloaded)
- Functions
- Function unloading has been moved/isolated to the new Function Structure
- Options
- Makes use of the script-data system to store script options
- Moved/isolated as much of the system as possible into the new Option Structure. An additional PR will be needed in the future (see TODO comment on ScriptLoader#replaceOptions)
- Variables
Other notable changes:
- Better documentation and javadocs across updated areas
- SkriptEventHandler is truly only for handling events now. It has been removed from classes like ScriptLoader. Yay for isolation!
- Improved error handling and printing in ScriptLoader
- Doc annotations for all the new Structures
- ScriptInfo has been significantly reduced, as it only tracks files and structures now. All lang messages have been updated accordingly.
- SkriptEvent has also been converted into a Structure. All event parsing, registration, and unregistration logic has been moved to SkriptEvent. SelfRegisteringTrigger methods in SkriptEventHandler have been deprecated as they are no longer necessary. The
registerBukkitEvents()method has been replaced with more specific methods to be called by SkriptEvent during the registration process. -
ParserInstance#getCurrentScriptnow returnsScriptinstead ofConfig. -
ParserInstance#getCurrentOptionshas been deprecated. The method will still function properly though. - `ParserInstance#onCurrentScriptChange(Config) has been deprecated.
-
Functions#clearFunctionshas been deprecated. - The class
ScriptOptionshas been removed as it was integrated intoScript. -
Trigger#getScriptnow returnsScriptinstead ofFile. -
SkriptParser#parseEvent(String, String)has been removed. -
Commands#loadCommand(SectionNode)andCommands#loadCommand(SectionNode, boolean)have been removed. -
Commands#unregisterCommands(Script)has been deprecated. - ScriptLoader has had unloading and reloading methods that use File parameters deprecated.
- ScriptLoader has had its loading methods reworked and additional ones added. The method used to load all scripts within the scripts folder has been generalized. Behavior has been moved within the Skript class itself.
- A method has been added to the Skript class to get a File object representing the scripts folder.
- SkriptCommand and EffScriptFile have been reworked to use proper ScriptLoader methods.
- Added static fields to ScriptLoader representing the disabled scripts prefix (currently
-) - Made
loadStructuremethods within ScriptLoader private - Improved SkriptCommandTabCompleter to use better ScriptLoader methods & autocompletion
- Reworked the
currentEventssystem to always require an event. A newContextlessEventhas been added for when there is no specific event(s) to take into account when parsing. Essentially, instead of usingnull,ContextlessEventshould be used. - Deprecated
SelfRegisteringSkriptEvent#afterParse(Config)asStructure#postLoadnow exists. - Added new ParserInstance Activity Status - this is to promote the idea that ParserInstance is meant for loading/parsing/unloading
- ... and a whole bunch of other changes! it's kind of impossible to list everything, so please feel free to read the commits!
Target Minecraft Versions: any Requirements: none Related Issues:
Fixing:
- https://github.com/SkriptLang/Skript/issues/2492
- https://github.com/SkriptLang/Skript/issues/4032
- https://github.com/SkriptLang/Skript/issues/4579
- https://github.com/SkriptLang/Skript/issues/4459
- https://github.com/SkriptLang/Skript/issues/4666
- https://github.com/SkriptLang/Skript/issues/4307
- https://github.com/SkriptLang/Skript/issues/1329
- https://github.com/SkriptLang/Skript/issues/4246
Non-Fixing:
- https://github.com/SkriptLang/Skript/issues/4071
- https://github.com/SkriptLang/Skript/issues/4786
- https://github.com/SkriptLang/Skript/issues/4252
- https://github.com/SkriptLang/Skript/issues/4916
- https://github.com/SkriptLang/Skript/issues/2262
I just realized - would it be possible to create a Structure for events? I suppose their pattern would kind of match everything though - so maybe it would not be worth the trouble.
It would be possible, but I don't think it would improve anything, so I did not do it.
I've added a priority system to preloading structures, and also fixed #2492. @Mwexim could you look at it?
SkriptEvents are now also Structures
These new commits work towards internalizing the Structures and improving ScriptLoader. However, the changes to Structure loading (e.g. sorting them instead of using natural order) are maybe not ideal. TP and I are going to discuss some options and make changes where needed :)
EDIT: builds are failing due to 1.9.4 testing issue
This issue was directed to this pull request https://github.com/SkriptLang/Skript/issues/4246
Has this been addressed in this pull request? Yes -> This issue can be referenced. No -> The PR available tag can be removed on the issue in question.
See https://github.com/SkriptLang/Skript/pull/4252#issuecomment-1153277875 and https://github.com/SkriptLang/Skript/pull/4108/commits/58d70d26512cd5a16df3a69b2bd894c48e84eb42, it's been included, I've updated the description
The entry data system has been made to work with all SectionNode's - not just those representing a Structure (top-level SectionNodes)
There wasn't any real reason to enforce this, as the system has no real dependency on Structure. This makes it more accessible for developers who may wish to combine it with something like the Section API