From 5cd9d3a26df38da6fc504a7f88d54a2343cff84c Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Thu, 11 May 2023 19:41:50 -0400 Subject: [PATCH] Initialize the script loader in `ResourceLoader#loadAll` --- .../java/emu/grasscutter/Grasscutter.java | 21 +++++++++--------- .../emu/grasscutter/data/ResourceLoader.java | 22 ++++++++++++------- .../java/io/grasscutter/GrasscutterTest.java | 5 +++-- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/main/java/emu/grasscutter/Grasscutter.java b/src/main/java/emu/grasscutter/Grasscutter.java index 4fae4a872..5b3ef28de 100644 --- a/src/main/java/emu/grasscutter/Grasscutter.java +++ b/src/main/java/emu/grasscutter/Grasscutter.java @@ -1,8 +1,5 @@ package emu.grasscutter; -import static emu.grasscutter.config.Configuration.SERVER; -import static emu.grasscutter.utils.Language.translate; - import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; import emu.grasscutter.auth.AuthenticationSystem; @@ -15,7 +12,6 @@ import emu.grasscutter.data.ResourceLoader; import emu.grasscutter.database.DatabaseManager; import emu.grasscutter.plugin.PluginManager; import emu.grasscutter.plugin.api.ServerHook; -import emu.grasscutter.scripts.ScriptLoader; import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.http.HttpServer; import emu.grasscutter.server.http.dispatch.DispatchHandler; @@ -28,12 +24,6 @@ import emu.grasscutter.server.http.handlers.GenericHandler; import emu.grasscutter.server.http.handlers.LogHandler; import emu.grasscutter.tools.Tools; import emu.grasscutter.utils.*; -import java.io.File; -import java.io.FileWriter; -import java.io.IOError; -import java.io.IOException; -import java.util.Calendar; -import javax.annotation.Nullable; import lombok.Getter; import lombok.Setter; import org.jline.reader.EndOfFileException; @@ -45,6 +35,16 @@ import org.jline.terminal.TerminalBuilder; import org.reflections.Reflections; import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; +import java.io.File; +import java.io.FileWriter; +import java.io.IOError; +import java.io.IOException; +import java.util.Calendar; + +import static emu.grasscutter.config.Configuration.SERVER; +import static emu.grasscutter.utils.Language.translate; + public final class Grasscutter { public static final File configFile = new File("./config.json"); public static final Reflections reflector = new Reflections("emu.grasscutter"); @@ -106,7 +106,6 @@ public final class Grasscutter { // Load all resources. Grasscutter.updateDayOfWeek(); - ScriptLoader.init(); ResourceLoader.loadAll(); // Generate handbooks. diff --git a/src/main/java/emu/grasscutter/data/ResourceLoader.java b/src/main/java/emu/grasscutter/data/ResourceLoader.java index ebafa5b14..660228796 100644 --- a/src/main/java/emu/grasscutter/data/ResourceLoader.java +++ b/src/main/java/emu/grasscutter/data/ResourceLoader.java @@ -1,9 +1,5 @@ package emu.grasscutter.data; -import static emu.grasscutter.utils.FileUtils.getDataPath; -import static emu.grasscutter.utils.FileUtils.getResourcePath; -import static emu.grasscutter.utils.Language.translate; - import com.google.gson.annotations.SerializedName; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.binout.*; @@ -33,6 +29,12 @@ import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArraySet; +import lombok.SneakyThrows; +import lombok.val; +import org.reflections.Reflections; + +import javax.script.Bindings; +import javax.script.CompiledScript; import java.io.IOException; import java.io.InputStreamReader; import java.nio.file.Files; @@ -44,10 +46,10 @@ import java.util.concurrent.CopyOnWriteArraySet; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import javax.script.Bindings; -import javax.script.CompiledScript; -import lombok.val; -import org.reflections.Reflections; + +import static emu.grasscutter.utils.FileUtils.getDataPath; +import static emu.grasscutter.utils.FileUtils.getResourcePath; +import static emu.grasscutter.utils.Language.translate; public final class ResourceLoader { @@ -96,10 +98,14 @@ public final class ResourceLoader { return List.copyOf(map.values()); } + @SneakyThrows public static void loadAll() { if (loadedAll) return; Grasscutter.getLogger().info(translate("messages.status.resources.loading")); + // Initialize the script loader. + ScriptLoader.init(); + loadConfigData(); // Load ability lists loadAbilityEmbryos(); diff --git a/src/test/java/io/grasscutter/GrasscutterTest.java b/src/test/java/io/grasscutter/GrasscutterTest.java index 07cdb2c62..8c57bab16 100644 --- a/src/test/java/io/grasscutter/GrasscutterTest.java +++ b/src/test/java/io/grasscutter/GrasscutterTest.java @@ -3,7 +3,6 @@ package io.grasscutter; import com.mchange.util.AssertException; import emu.grasscutter.Grasscutter; import emu.grasscutter.config.Configuration; -import java.io.IOException; import lombok.Getter; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -12,6 +11,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.io.IOException; + /** Testing entrypoint for {@link Grasscutter}. */ public final class GrasscutterTest { @Getter private static final OkHttpClient httpClient = new OkHttpClient(); @@ -30,7 +31,7 @@ public final class GrasscutterTest { } @BeforeAll - public static void main() { + public static void entry() { try { // Start Grasscutter. Grasscutter.main(new String[] {"-test"});