Implement nasty workaround for Spigot's changes to the PluginClassLoader (#648)

This commit is contained in:
Luck
2017-12-29 15:25:49 +00:00
Unverified
parent cfcd896c59
commit bff9715e7f
6 changed files with 283 additions and 11 deletions
@@ -186,18 +186,12 @@ public class DependencyManager {
}
}
private void loadJar(File file) {
private void loadJar(File file) {
// get the classloader to load into
ClassLoader classLoader = plugin.getClass().getClassLoader();
if (classLoader instanceof URLClassLoader) {
try {
ADD_URL_METHOD.invoke(classLoader, file.toURI().toURL());
} catch (IllegalAccessException | InvocationTargetException | MalformedURLException e) {
throw new RuntimeException("Unable to invoke URLClassLoader#addURL", e);
}
} else {
throw new RuntimeException("Unknown classloader type: " + classLoader.getClass());
try {
plugin.loadUrlIntoClasspath(file.toURI().toURL());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
@@ -210,4 +204,16 @@ public class DependencyManager {
}
}
public static void loadUrlIntoClassLoader(URL url, ClassLoader classLoader) {
if (classLoader instanceof URLClassLoader) {
try {
ADD_URL_METHOD.invoke(classLoader, url);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Unable to invoke URLClassLoader#addURL", e);
}
} else {
throw new RuntimeException("Unknown classloader type: " + classLoader.getClass());
}
}
}
@@ -55,6 +55,7 @@ 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;
@@ -154,6 +155,15 @@ 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.