Skip to content

Commit

Permalink
Use the mod class loader to get the contents of the command resource …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
TechnoPorg committed Sep 20, 2024
1 parent 4d3b8c2 commit 069b6dd
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -78,7 +79,7 @@ private static List<String> getCommandsJson(List<String> 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);
Expand Down

0 comments on commit 069b6dd

Please sign in to comment.