From 2bdec62824b0756a8ef3d387506d9dac03514dd1 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Thu, 21 Nov 2024 08:03:20 +0000 Subject: [PATCH 01/55] Script type & expression. (#6702) * Create Script type. * Support script string/name conversion. * Script expression. * Add script lang entry. * Tests for script expression & names. * Support all scripts expression. * Script effects & tests. * Create dummy Script handle for disabled scripts. * Script reflection feature flag. * Restrict literal parsing to commands & parse. * Test feature flag for resolving name. * Split ExprScripts by feature to support disabled scripts. * Fix ExprName tests for new & old behaviour. * Add tests for disabled script handles. * Apply suggestions from code review Co-authored-by: Patrick Miller * Improve script loading/unloading safety. * Add feature check for script hotswapping. * Use expression stream. * Conformity for file names and proper loading safety. * Document validity & add condition support. * Add script is loaded condition + tests. * Some changes from code review. * More changes. * Apply suggestions from code review Co-authored-by: Patrick Miller * Clean up EffScriptFile and rename ExprScripts variations. * Finish code review changes. * Clean up script loader stuff. * Fix conflicts. * Suggested changes. * Apply suggestions from code review Co-authored-by: Patrick Miller * Finished. --------- Co-authored-by: Patrick Miller Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com> --- .../java/ch/njol/skript/ScriptLoader.java | 56 ++++++- .../java/ch/njol/skript/SkriptCommand.java | 39 +---- .../skript/classes/data/SkriptClasses.java | 54 +++++++ .../njol/skript/conditions/CondIsLoaded.java | 119 +++++++++----- .../njol/skript/conditions/CondIsValid.java | 21 ++- .../skript/conditions/CondScriptLoaded.java | 12 +- .../java/ch/njol/skript/config/Config.java | 36 +++++ .../ch/njol/skript/effects/EffScriptFile.java | 151 ++++++++++++------ .../ch/njol/skript/expressions/ExprName.java | 14 +- .../njol/skript/expressions/ExprScript.java | 137 ++++++++++++---- .../njol/skript/expressions/ExprScripts.java | 82 ++++------ .../skript/expressions/ExprScriptsOld.java | 131 +++++++++++++++ .../ch/njol/skript/registrations/Feature.java | 1 + .../skriptlang/skript/lang/script/Script.java | 40 ++++- .../org/skriptlang/skript/util/Validated.java | 86 ++++++++++ src/main/resources/lang/default.lang | 12 ++ src/test/skript/tests/misc/-disabled.sk | 2 + .../skript/tests/misc/legacy script name.sk | 7 + .../tests/syntaxes/conditions/CondIsLoaded.sk | 20 +++ .../tests/syntaxes/effects/EffScriptFile.sk | 53 ++++++ .../tests/syntaxes/expressions/ExprName.sk | 7 + .../tests/syntaxes/expressions/ExprScript.sk | 50 ++++++ 22 files changed, 909 insertions(+), 221 deletions(-) create mode 100644 src/main/java/ch/njol/skript/expressions/ExprScriptsOld.java create mode 100644 src/main/java/org/skriptlang/skript/util/Validated.java create mode 100644 src/test/skript/tests/misc/-disabled.sk create mode 100644 src/test/skript/tests/misc/legacy script name.sk create mode 100644 src/test/skript/tests/syntaxes/conditions/CondIsLoaded.sk create mode 100644 src/test/skript/tests/syntaxes/effects/EffScriptFile.sk create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprScript.sk diff --git a/src/main/java/ch/njol/skript/ScriptLoader.java b/src/main/java/ch/njol/skript/ScriptLoader.java index 47923956ca6..56a9822e593 100644 --- a/src/main/java/ch/njol/skript/ScriptLoader.java +++ b/src/main/java/ch/njol/skript/ScriptLoader.java @@ -15,6 +15,7 @@ import ch.njol.skript.log.*; import ch.njol.skript.sections.SecLoop; import ch.njol.skript.structures.StructOptions.OptionsData; +import ch.njol.skript.test.runner.TestMode; import ch.njol.skript.util.ExceptionUtils; import ch.njol.skript.util.SkriptColor; import ch.njol.skript.util.Task; @@ -26,6 +27,7 @@ import ch.njol.util.StringUtils; import org.bukkit.Bukkit; import org.bukkit.event.Event; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.util.event.EventRegistry; import org.skriptlang.skript.lang.script.Script; @@ -696,7 +698,6 @@ private static LoadingScriptInfo loadScript(Config config) { ScriptLoader.eventRegistry().events(ScriptInitEvent.class) .forEach(event -> event.onInit(script)); - return null; }; if (isAsync()) { // Need to delegate to main thread @@ -868,6 +869,7 @@ public static ScriptInfo unloadScripts(Set