Fix NoClassDefFoundError when loading extensions on non-JiJ platforms

This commit is contained in:
Luck 2021-02-19 16:33:59 +00:00
parent 88f040e822
commit 16ee500054
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -27,7 +27,6 @@ package me.lucko.luckperms.common.extension;
import com.google.gson.JsonObject;
import me.lucko.luckperms.common.loader.JarInJarClassLoader;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.util.gson.GsonProvider;
@ -144,7 +143,7 @@ public class SimpleExtensionManager implements ExtensionManager, AutoCloseable {
throw new IllegalArgumentException("class is null");
}
if (useParentClassLoader && getClass().getClassLoader() instanceof JarInJarClassLoader) {
if (useParentClassLoader && isJarInJar()) {
try {
addJarToParentClasspath(path);
} catch (Exception e) {
@ -196,6 +195,11 @@ public class SimpleExtensionManager implements ExtensionManager, AutoCloseable {
return this.extensions.stream().map(e -> e.instance).collect(Collectors.toSet());
}
private static boolean isJarInJar() {
String thisClassLoaderName = SimpleExtensionManager.class.getClassLoader().getClass().getName();
return thisClassLoaderName.equals("me.lucko.luckperms.common.loader.JarInJarClassLoader");
}
private static void addJarToParentClasspath(Path path) throws Exception {
ClassLoader parentClassLoader = SimpleExtensionManager.class.getClassLoader().getParent();
if (!(parentClassLoader instanceof URLClassLoader)) {