From d530dcc5431c0e73c7ca154a86c5cdcc07262ef1 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 15 Sep 2024 21:02:24 +0200 Subject: [PATCH 1/8] update --- src/main/java/ch/njol/skript/Skript.java | 26 +------ .../java/ch/njol/skript/SkriptCommand.java | 21 +++--- .../java/ch/njol/skript/aliases/Aliases.java | 70 +++++++++---------- 3 files changed, 44 insertions(+), 73 deletions(-) diff --git a/src/main/java/ch/njol/skript/Skript.java b/src/main/java/ch/njol/skript/Skript.java index c51112be9ac..2459a713878 100644 --- a/src/main/java/ch/njol/skript/Skript.java +++ b/src/main/java/ch/njol/skript/Skript.java @@ -249,17 +249,6 @@ public static ServerPlatform getServerPlatform() { } } - /** - * Returns true if the underlying installed Java/JVM is 32-bit, false otherwise. - * Note that this depends on a internal system property and these can always be overridden by user using -D JVM options, - * more specifically, this method will return false on non OracleJDK/OpenJDK based JVMs, that don't include bit information in java.vm.name system property. - * @return Whether the installed Java/JVM is 32-bit or not. - */ - private static boolean using32BitJava() { - // Property returned should either be "Java HotSpot(TM) 32-Bit Server VM" or "OpenJDK 32-Bit Server VM" if 32-bit and using OracleJDK/OpenJDK - return System.getProperty("java.vm.name").contains("32"); - } - /** * Checks if server software and Minecraft version are supported. * Prints errors or warnings to console if something is wrong. @@ -502,19 +491,8 @@ public void onEnable() { updater.updateCheck(console); } - try { - Aliases.load(); // Loaded before anything that might use them - } catch (StackOverflowError e) { - if (using32BitJava()) { - Skript.error(""); - Skript.error("There was a StackOverflowError that occured while loading aliases."); - Skript.error("As you are currently using 32-bit Java, please update to 64-bit Java to resolve the error."); - Skript.error("Please report this issue to our GitHub only if updating to 64-bit Java does not fix the issue."); - Skript.error(""); - } else { - throw e; // Uh oh, this shouldn't happen. Re-throw the error. - } - } + // Loaded before anything that might use them + Aliases.load(); // If loading can continue (platform ok), check for potentially thrown error if (classLoadError != null) { diff --git a/src/main/java/ch/njol/skript/SkriptCommand.java b/src/main/java/ch/njol/skript/SkriptCommand.java index c735541cae3..b6d2a768774 100644 --- a/src/main/java/ch/njol/skript/SkriptCommand.java +++ b/src/main/java/ch/njol/skript/SkriptCommand.java @@ -156,15 +156,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St reloading(sender, "config, aliases and scripts", logHandler); SkriptConfig.load(); Aliases.clear(); - Aliases.load(); - - ScriptLoader.unloadScripts(ScriptLoader.getLoadedScripts()); - ScriptLoader.loadScripts(Skript.getInstance().getScriptsFolder(), OpenCloseable.combine(logHandler, timingLogHandler)) - .thenAccept(info -> { - if (info.files == 0) - Skript.warning(Skript.m_no_scripts.toString()); - reloaded(sender, logHandler, timingLogHandler, "config, aliases and scripts"); - }); + Aliases.load().thenRun(() -> { + ScriptLoader.unloadScripts(ScriptLoader.getLoadedScripts()); + ScriptLoader.loadScripts(Skript.getInstance().getScriptsFolder(), OpenCloseable.combine(logHandler, timingLogHandler)) + .thenAccept(info -> { + if (info.files == 0) + Skript.warning(Skript.m_no_scripts.toString()); + reloaded(sender, logHandler, timingLogHandler, "config, aliases and scripts"); + }); + }); } else if (args[1].equalsIgnoreCase("scripts")) { reloading(sender, "scripts", logHandler); @@ -182,8 +182,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } else if (args[1].equalsIgnoreCase("aliases")) { reloading(sender, "aliases", logHandler); Aliases.clear(); - Aliases.load(); - reloaded(sender, logHandler, timingLogHandler, "aliases"); + Aliases.load().thenRun(() -> reloaded(sender, logHandler, timingLogHandler, "aliases")); } else { // Reloading an individual Script or folder File scriptFile = getScriptFromArgs(sender, args); if (scriptFile == null) diff --git a/src/main/java/ch/njol/skript/aliases/Aliases.java b/src/main/java/ch/njol/skript/aliases/Aliases.java index 19daed69359..eaadab8f952 100644 --- a/src/main/java/ch/njol/skript/aliases/Aliases.java +++ b/src/main/java/ch/njol/skript/aliases/Aliases.java @@ -1,21 +1,3 @@ -/** - * This file is part of Skript. - * - * Skript is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Skript is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Skript. If not, see . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ package ch.njol.skript.aliases; import ch.njol.skript.Skript; @@ -25,14 +7,8 @@ import ch.njol.skript.config.Node; import ch.njol.skript.config.SectionNode; import ch.njol.skript.entity.EntityData; -import org.bukkit.entity.EntityType; -import org.skriptlang.skript.lang.script.Script; import ch.njol.skript.lang.parser.ParserInstance; -import ch.njol.skript.localization.ArgsMessage; -import ch.njol.skript.localization.Language; -import ch.njol.skript.localization.Message; -import ch.njol.skript.localization.Noun; -import ch.njol.skript.localization.RegexMessage; +import ch.njol.skript.localization.*; import ch.njol.skript.log.BlockingLogHandler; import ch.njol.skript.util.EnchantmentType; import ch.njol.skript.util.Utils; @@ -41,19 +17,17 @@ import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.lang.script.Script; import java.io.IOException; import java.io.UncheckedIOException; import java.net.URI; import java.net.URISyntaxException; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.file.*; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.concurrent.CompletableFuture; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -384,14 +358,34 @@ public static void clear() { * Loads aliases from Skript's standard locations. * Exceptions will be logged, but not thrown. */ - public static void load() { - try { - long start = System.currentTimeMillis(); - loadInternal(); - Skript.info("Loaded " + provider.getAliasCount() + " aliases in " + (System.currentTimeMillis() - start) + "ms"); - } catch (IOException e) { - Skript.exception(e); - } + public static CompletableFuture load() { + return CompletableFuture.supplyAsync(() -> { + try { + long start = System.currentTimeMillis(); + loadInternal(); + Skript.info("Loaded " + provider.getAliasCount() + " aliases in " + (System.currentTimeMillis() - start) + "ms"); + return true; + } catch (StackOverflowError e) { + /* + * Returns true if the underlying installed Java/JVM is 32-bit, false otherwise. + * Note that this depends on a internal system property and these can always be overridden by user using -D JVM options, + * more specifically, this method will return false on non OracleJDK/OpenJDK based JVMs, that don't include bit information in java.vm.name system property + */ + if (System.getProperty("java.vm.name").contains("32")) { + Skript.error(""); + Skript.error("There was a StackOverflowError that occurred while loading aliases."); + Skript.error("As you are currently using 32-bit Java, please update to 64-bit Java to resolve the error."); + Skript.error("Please report this issue to our GitHub only if updating to 64-bit Java does not fix the issue."); + Skript.error(""); + } else { + Skript.exception(e); + } + return false; + } catch (IOException e) { + Skript.exception(e); + return false; + } + }); } /** From 595967ae82e2b5c7d0e771d4302d89578d80968e Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 15 Sep 2024 21:55:15 +0200 Subject: [PATCH 2/8] await aliases before test loading --- src/main/java/ch/njol/skript/Skript.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/Skript.java b/src/main/java/ch/njol/skript/Skript.java index 2459a713878..05f7b0d6f31 100644 --- a/src/main/java/ch/njol/skript/Skript.java +++ b/src/main/java/ch/njol/skript/Skript.java @@ -131,6 +131,8 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.logging.Filter; @@ -492,7 +494,7 @@ public void onEnable() { } // Loaded before anything that might use them - Aliases.load(); + CompletableFuture aliases = Aliases.load(); // If loading can continue (platform ok), check for potentially thrown error if (classLoadError != null) { @@ -565,6 +567,12 @@ public void run() { } finishedLoadingHooks = true; + try { + aliases.get(); // await alias load + } catch (InterruptedException | ExecutionException e) { + exception(e, "Could not load aliases concurrently"); + } + if (TestMode.ENABLED) { info("Preparing Skript for testing..."); tainted = true; From e03ede14f89ab19bbac3fb5491b90151033345d1 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 15 Sep 2024 22:04:55 +0200 Subject: [PATCH 3/8] update load --- src/main/java/ch/njol/skript/aliases/Aliases.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/aliases/Aliases.java b/src/main/java/ch/njol/skript/aliases/Aliases.java index eaadab8f952..c62c1212290 100644 --- a/src/main/java/ch/njol/skript/aliases/Aliases.java +++ b/src/main/java/ch/njol/skript/aliases/Aliases.java @@ -13,6 +13,7 @@ import ch.njol.skript.util.EnchantmentType; import ch.njol.skript.util.Utils; import ch.njol.skript.util.Version; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -355,8 +356,11 @@ public static void clear() { } /** - * Loads aliases from Skript's standard locations. + * Loads aliases from Skript's standard locations asynchronously. * Exceptions will be logged, but not thrown. + * + * @return A future that completes when the aliases are loaded. + * The returned value is true if the loading was successful, false otherwise. */ public static CompletableFuture load() { return CompletableFuture.supplyAsync(() -> { @@ -379,6 +383,7 @@ public static CompletableFuture load() { Skript.error(""); } else { Skript.exception(e); + Bukkit.getPluginManager().disablePlugin(Skript.getInstance()); } return false; } catch (IOException e) { From 8bb0f6c1edc34ed438135a06a783e0cf85b496c9 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 15 Sep 2024 22:08:38 +0200 Subject: [PATCH 4/8] move aliases --- src/main/java/ch/njol/skript/Skript.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/Skript.java b/src/main/java/ch/njol/skript/Skript.java index 05f7b0d6f31..41f76dcded4 100644 --- a/src/main/java/ch/njol/skript/Skript.java +++ b/src/main/java/ch/njol/skript/Skript.java @@ -481,6 +481,9 @@ public void onEnable() { // ... but also before platform check, because there is a config option to ignore some errors SkriptConfig.load(); + // Loaded before anything that might use them + CompletableFuture aliases = Aliases.load(); + // Now override the verbosity if test mode is enabled if (TestMode.VERBOSITY != null) SkriptLogger.setVerbosity(Verbosity.valueOf(TestMode.VERBOSITY)); @@ -493,9 +496,6 @@ public void onEnable() { updater.updateCheck(console); } - // Loaded before anything that might use them - CompletableFuture aliases = Aliases.load(); - // If loading can continue (platform ok), check for potentially thrown error if (classLoadError != null) { exception(classLoadError); From b16f527f91b538f922066f4ed8ad1c3886b71620 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Sun, 15 Sep 2024 22:18:14 +0200 Subject: [PATCH 5/8] add old method --- src/main/java/ch/njol/skript/Skript.java | 2 +- .../java/ch/njol/skript/SkriptCommand.java | 4 ++-- .../java/ch/njol/skript/aliases/Aliases.java | 21 +++++++++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/Skript.java b/src/main/java/ch/njol/skript/Skript.java index 41f76dcded4..20eef8f7a79 100644 --- a/src/main/java/ch/njol/skript/Skript.java +++ b/src/main/java/ch/njol/skript/Skript.java @@ -482,7 +482,7 @@ public void onEnable() { SkriptConfig.load(); // Loaded before anything that might use them - CompletableFuture aliases = Aliases.load(); + CompletableFuture aliases = Aliases.loadAsync(); // Now override the verbosity if test mode is enabled if (TestMode.VERBOSITY != null) diff --git a/src/main/java/ch/njol/skript/SkriptCommand.java b/src/main/java/ch/njol/skript/SkriptCommand.java index b6d2a768774..dd287fa5db2 100644 --- a/src/main/java/ch/njol/skript/SkriptCommand.java +++ b/src/main/java/ch/njol/skript/SkriptCommand.java @@ -156,7 +156,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St reloading(sender, "config, aliases and scripts", logHandler); SkriptConfig.load(); Aliases.clear(); - Aliases.load().thenRun(() -> { + Aliases.loadAsync().thenRun(() -> { ScriptLoader.unloadScripts(ScriptLoader.getLoadedScripts()); ScriptLoader.loadScripts(Skript.getInstance().getScriptsFolder(), OpenCloseable.combine(logHandler, timingLogHandler)) .thenAccept(info -> { @@ -182,7 +182,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } else if (args[1].equalsIgnoreCase("aliases")) { reloading(sender, "aliases", logHandler); Aliases.clear(); - Aliases.load().thenRun(() -> reloaded(sender, logHandler, timingLogHandler, "aliases")); + Aliases.loadAsync().thenRun(() -> reloaded(sender, logHandler, timingLogHandler, "aliases")); } else { // Reloading an individual Script or folder File scriptFile = getScriptFromArgs(sender, args); if (scriptFile == null) diff --git a/src/main/java/ch/njol/skript/aliases/Aliases.java b/src/main/java/ch/njol/skript/aliases/Aliases.java index c62c1212290..bb24c305756 100644 --- a/src/main/java/ch/njol/skript/aliases/Aliases.java +++ b/src/main/java/ch/njol/skript/aliases/Aliases.java @@ -354,7 +354,24 @@ private static ItemType getAlias(final String s) { public static void clear() { provider.clearAliases(); } - + + /** + * Loads aliases from Skript's standard locations. + * Exceptions will be logged, but not thrown. + * + * @deprecated Freezes server on call. Use {@link #loadAsync()} instead. + */ + @Deprecated + public static void load() { + try { + long start = System.currentTimeMillis(); + loadInternal(); + Skript.info("Loaded " + provider.getAliasCount() + " aliases in " + (System.currentTimeMillis() - start) + "ms"); + } catch (IOException e) { + Skript.exception(e); + } + } + /** * Loads aliases from Skript's standard locations asynchronously. * Exceptions will be logged, but not thrown. @@ -362,7 +379,7 @@ public static void clear() { * @return A future that completes when the aliases are loaded. * The returned value is true if the loading was successful, false otherwise. */ - public static CompletableFuture load() { + public static CompletableFuture loadAsync() { return CompletableFuture.supplyAsync(() -> { try { long start = System.currentTimeMillis(); From 544b10d4420fc03914109311e5ec73c77a7e0cb8 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:10:01 +0200 Subject: [PATCH 6/8] oops --- src/main/java/ch/njol/skript/Skript.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/Skript.java b/src/main/java/ch/njol/skript/Skript.java index 20eef8f7a79..bf20c42abd0 100644 --- a/src/main/java/ch/njol/skript/Skript.java +++ b/src/main/java/ch/njol/skript/Skript.java @@ -481,7 +481,6 @@ public void onEnable() { // ... but also before platform check, because there is a config option to ignore some errors SkriptConfig.load(); - // Loaded before anything that might use them CompletableFuture aliases = Aliases.loadAsync(); // Now override the verbosity if test mode is enabled From 3280cb705e35fe9ba319abd38a3fedceea997d9d Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:44:50 +0100 Subject: [PATCH 7/8] update comment --- src/main/java/ch/njol/skript/Skript.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/Skript.java b/src/main/java/ch/njol/skript/Skript.java index 4982f3a8ee4..722af03ddac 100644 --- a/src/main/java/ch/njol/skript/Skript.java +++ b/src/main/java/ch/njol/skript/Skript.java @@ -580,7 +580,7 @@ public void run() { finishedLoadingHooks = true; try { - aliases.get(); // await alias load + aliases.get(); // wait for aliases to load } catch (InterruptedException | ExecutionException e) { exception(e, "Could not load aliases concurrently"); } From 65f7f41a3e91c522778da7fc401a8cb44bae77e4 Mon Sep 17 00:00:00 2001 From: Efnilite <35348263+Efnilite@users.noreply.github.com> Date: Thu, 31 Oct 2024 20:06:20 +0100 Subject: [PATCH 8/8] fix imports --- src/main/java/ch/njol/skript/aliases/Aliases.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/aliases/Aliases.java b/src/main/java/ch/njol/skript/aliases/Aliases.java index 3c7ca418428..ad41fdb8508 100644 --- a/src/main/java/ch/njol/skript/aliases/Aliases.java +++ b/src/main/java/ch/njol/skript/aliases/Aliases.java @@ -31,11 +31,6 @@ import java.util.concurrent.CompletableFuture; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.jetbrains.annotations.Nullable; -import org.skriptlang.skript.lang.script.Script; public abstract class Aliases { static final boolean USING_ITEM_COMPONENTS = Skript.isRunningMinecraft(1, 20, 5);