From 694d05e78aa9ed34561e3836eb5c14c2f33d3c09 Mon Sep 17 00:00:00 2001 From: djytw Date: Thu, 8 Jul 2021 18:42:38 +0200 Subject: [PATCH 1/2] Fix resource load in Windows --- src/main/java/net/minestom/server/extensions/Extension.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minestom/server/extensions/Extension.java b/src/main/java/net/minestom/server/extensions/Extension.java index f3cbac22e..2dc15ef62 100644 --- a/src/main/java/net/minestom/server/extensions/Extension.java +++ b/src/main/java/net/minestom/server/extensions/Extension.java @@ -164,7 +164,8 @@ public abstract class Extension { */ public @Nullable InputStream getPackagedResource(@NotNull Path target) { try { - final URL url = getOrigin().getMinestomExtensionClassLoader().getResource(target.toString()); + String path = target.toString().replace('\\', '/'); + final URL url = getOrigin().getMinestomExtensionClassLoader().getResource(path); if (url == null) { getLogger().debug("Resource not found: {}", target); return null; From 8f771bb8675f0bd7d7602bd7dd4d65d6e5fc5acf Mon Sep 17 00:00:00 2001 From: djytw Date: Thu, 8 Jul 2021 20:25:10 +0200 Subject: [PATCH 2/2] more --- .../minestom/server/extensions/Extension.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/minestom/server/extensions/Extension.java b/src/main/java/net/minestom/server/extensions/Extension.java index 2dc15ef62..a61d42332 100644 --- a/src/main/java/net/minestom/server/extensions/Extension.java +++ b/src/main/java/net/minestom/server/extensions/Extension.java @@ -151,7 +151,18 @@ public abstract class Extension { * @return The file contents, or null if there was an issue reading the file. */ public @Nullable InputStream getPackagedResource(@NotNull String fileName) { - return getPackagedResource(Paths.get(fileName)); + try { + final URL url = getOrigin().getMinestomExtensionClassLoader().getResource(fileName); + if (url == null) { + getLogger().debug("Resource not found: {}", fileName); + return null; + } + + return url.openConnection().getInputStream(); + } catch (IOException ex) { + getLogger().debug("Failed to load resource {}.", fileName, ex); + return null; + } } /** @@ -163,19 +174,7 @@ public abstract class Extension { * @return The file contents, or null if there was an issue reading the file. */ public @Nullable InputStream getPackagedResource(@NotNull Path target) { - try { - String path = target.toString().replace('\\', '/'); - final URL url = getOrigin().getMinestomExtensionClassLoader().getResource(path); - if (url == null) { - getLogger().debug("Resource not found: {}", target); - return null; - } - - return url.openConnection().getInputStream(); - } catch (IOException ex) { - getLogger().debug("Failed to load resource {}.", target, ex); - return null; - } + return getPackagedResource(target.toString().replace('\\', '/')); } /**