From 7c0b62274291f4a0687f29ce9410652ea3fbb1d8 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 19 Apr 2021 08:01:58 -0400 Subject: [PATCH] Try #2 at explicit path --- .../proxy/util/FileSystemUtils.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java index 0b634b7cf..1139f004f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java @@ -28,7 +28,9 @@ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Collections; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.function.Consumer; public class FileSystemUtils { @@ -38,18 +40,20 @@ public class FileSystemUtils { * path of the given {@link Class}. * * @param target The target class of the resource path to scan - * @param path The path to scan within the resource path * @param consumer The consumer to visit the resolved path + * @param firstPathComponent First path component + * @param remainingPathComponents Remaining path components */ @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"}) - public static boolean visitResources(Class target, String path, Consumer consumer) + public static boolean visitResources(Class target, Consumer consumer, + String firstPathComponent, String... remainingPathComponents) throws IOException { final File file = new File(target .getProtectionDomain().getCodeSource().getLocation().getPath()); if (file.isFile()) { // jar try (FileSystem fileSystem = FileSystems.newFileSystem(file.toPath(), (ClassLoader) null)) { - Path toVisit = fileSystem.getPath(path); + Path toVisit = fileSystem.getPath(firstPathComponent, remainingPathComponents); if (Files.exists(toVisit)) { consumer.accept(toVisit); return true; @@ -58,8 +62,12 @@ public class FileSystemUtils { } } else { URI uri; + List componentList = new ArrayList<>(); + componentList.add(firstPathComponent); + componentList.addAll(Arrays.asList(remainingPathComponents)); + try { - URL url = target.getClassLoader().getResource(path); + URL url = target.getClassLoader().getResource(String.join("/", componentList)); if (url == null) { return false; }