Revert Spigot PluginClassLoader workaround

This commit is contained in:
Luck
2017-12-29 20:40:43 +00:00
Unverified
parent 9bb1ba12b2
commit 717347273d
6 changed files with 19 additions and 278 deletions
@@ -103,10 +103,14 @@ public class DependencyManager {
dependencies.add(Dependency.JEDIS);
}
// don't load slf4j or configurate dependencies on sponge, as they're already present
if (plugin.getServerType() == PlatformType.SPONGE) {
// don't load slf4j if it's already present
if (classExists("org.slf4j.Logger") && classExists("org.slf4j.LoggerFactory")) {
dependencies.remove(Dependency.SLF4J_API);
dependencies.remove(Dependency.SLF4J_SIMPLE);
}
// don't load configurate dependencies on sponge
if (plugin.getServerType() == PlatformType.SPONGE) {
dependencies.remove(Dependency.CONFIGURATE_CORE);
dependencies.remove(Dependency.CONFIGURATE_GSON);
dependencies.remove(Dependency.CONFIGURATE_YAML);
@@ -182,20 +186,14 @@ public class DependencyManager {
}
}
private void loadJar(File file) {
private void loadJar(File file) {
// get the classloader to load into
try {
plugin.loadUrlIntoClasspath(file.toURI().toURL());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
ClassLoader classLoader = plugin.getClass().getClassLoader();
public static void loadUrlIntoClassLoader(URL url, ClassLoader classLoader) {
if (classLoader instanceof URLClassLoader) {
try {
ADD_URL_METHOD.invoke(classLoader, url);
} catch (IllegalAccessException | InvocationTargetException e) {
ADD_URL_METHOD.invoke(classLoader, file.toURI().toURL());
} catch (IllegalAccessException | InvocationTargetException | MalformedURLException e) {
throw new RuntimeException("Unable to invoke URLClassLoader#addURL", e);
}
} else {
@@ -203,4 +201,13 @@ public class DependencyManager {
}
}
private static boolean classExists(String className) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}
@@ -55,7 +55,6 @@ import me.lucko.luckperms.common.verbose.VerboseHandler;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -155,15 +154,6 @@ public interface LuckPermsPlugin {
*/
DependencyManager getDependencyManager();
/**
* Loads a dependency into the plugins classpath
*
* @param url the url to load
*/
default void loadUrlIntoClasspath(URL url) {
DependencyManager.loadUrlIntoClassLoader(url, getClass().getClassLoader());
}
/**
* Gets the context manager.
* This object handles context accumulation for all players on the platform.