From 069b6dd0e537e78ef4a2ca27d5e32c3456b7aa43 Mon Sep 17 00:00:00 2001 From: Jonah Janzen Date: Thu, 19 Sep 2024 20:30:06 -0400 Subject: [PATCH] Use the mod class loader to get the contents of the command resource file Presumably, the system class loader is something tied to the main Minecraft process, as it has no access to any of the resources of the Discord Verifier JAR. It now uses the mod-specific class loader, which loads resources within the proper context and fixes the bug of the command file not being loaded when packaged in a JAR. --- .../novamaday/d4j/gradle/simplebot/GlobalCommandRegistrar.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/novamaday/d4j/gradle/simplebot/GlobalCommandRegistrar.java b/src/main/java/com/novamaday/d4j/gradle/simplebot/GlobalCommandRegistrar.java index e09d8be..ee7fbd0 100644 --- a/src/main/java/com/novamaday/d4j/gradle/simplebot/GlobalCommandRegistrar.java +++ b/src/main/java/com/novamaday/d4j/gradle/simplebot/GlobalCommandRegistrar.java @@ -4,6 +4,7 @@ import discord4j.discordjson.json.ApplicationCommandRequest; import discord4j.rest.RestClient; import discord4j.rest.service.ApplicationService; +import org.iolhaven.discord_verifier.DiscordVerifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -78,7 +79,7 @@ private static List getCommandsJson(List fileNames) throws IOExc * @return The contents of the file as a String, otherwise throws an exception */ private static String getResourceFileAsString(String fileName) throws IOException { - ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + ClassLoader classLoader = DiscordVerifier.class.getClassLoader(); try (InputStream resourceAsStream = classLoader.getResourceAsStream(fileName)) { if (resourceAsStream == null) return null; try (InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream);