diff --git a/src/main/java/me/clip/placeholderapi/util/FileUtil.java b/src/main/java/me/clip/placeholderapi/util/FileUtil.java index ab5f3b5..81fd690 100644 --- a/src/main/java/me/clip/placeholderapi/util/FileUtil.java +++ b/src/main/java/me/clip/placeholderapi/util/FileUtil.java @@ -27,6 +27,8 @@ import java.io.File; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; @@ -43,7 +45,11 @@ public class FileUtil final URL jar = file.toURI().toURL(); - try (final URLClassLoader loader = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader()); final JarInputStream stream = new JarInputStream(jar.openStream())) + final List matches = new ArrayList<>(); + final List> classes = new ArrayList<>(); + + + try (final JarInputStream stream = new JarInputStream(jar.openStream()); final URLClassLoader loader = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader())) { JarEntry entry; while ((entry = stream.getNextJarEntry()) != null) @@ -54,21 +60,25 @@ public class FileUtil continue; } + matches.add(name.substring(0, name.lastIndexOf('.')).replace('/', '.')); + } + + for (final String match : matches) + { try { - final Class loaded = loader.loadClass(name.substring(0, name.lastIndexOf('.')).replace('/', '.')); + final Class loaded = loader.loadClass(match); if (clazz.isAssignableFrom(loaded)) { - return loaded.asSubclass(clazz); + classes.add(loaded.asSubclass(clazz)); } } catch (final NoClassDefFoundError ignored) - { - } + { } } } - return null; + return classes.isEmpty() ? null : classes.get(0); } }