diff --git a/src/net/md_5/bungee/api/bungeepluginmanager/PluginUtils.java b/src/net/md_5/bungee/api/bungeepluginmanager/PluginUtils.java index 04e3a3c..677afa2 100644 --- a/src/net/md_5/bungee/api/bungeepluginmanager/PluginUtils.java +++ b/src/net/md_5/bungee/api/bungeepluginmanager/PluginUtils.java @@ -24,13 +24,11 @@ import com.google.common.collect.Multimap; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.plugin.*; import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.representer.Representer; import org.yaml.snakeyaml.constructor.Constructor; - +import org.yaml.snakeyaml.representer.Representer; import java.io.File; import java.io.InputStream; -import java.net.URL; import java.net.URLClassLoader; import java.util.Map; import java.util.ResourceBundle; @@ -169,18 +167,19 @@ public final class PluginUtils { Preconditions.checkNotNull(pluginsMap); for (String dependency : desc.getDepends()) { - if (!pluginsMap.keySet().contains(dependency)) { + if (!pluginsMap.containsKey(dependency)) { ProxyServer.getInstance().getLogger().log(Level.WARNING, "{0} (required by {1}) is unavailable", new Object[]{dependency, desc.getName()}); return false; } } + Object libraryLoader = ReflectionUtils.getFieldValue(ProxyServer.getInstance().getPluginManager(), "libraryLoader"); //load plugin Class pluginClassLoader = Class.forName("net.md_5.bungee.api.plugin.PluginClassloader"); - java.lang.reflect.Constructor constructor = pluginClassLoader.getConstructor(ProxyServer.class, PluginDescription.class, URL[].class); + java.lang.reflect.Constructor constructor = pluginClassLoader.getConstructor(ProxyServer.class, PluginDescription.class, File.class, ClassLoader.class); constructor.setAccessible(true); - URLClassLoader loader = (URLClassLoader) constructor.newInstance(ProxyServer.getInstance(), desc, new URL[]{pluginFile.toURI().toURL()}); + URLClassLoader loader = (URLClassLoader) constructor.newInstance(ProxyServer.getInstance(), desc, pluginFile, libraryLoader != null ? ReflectionUtils.invokeMethod(libraryLoader, "createLoader", desc) : null); Class mainclazz = loader.loadClass(desc.getMain()); Plugin plugin = (Plugin) mainclazz.getDeclaredConstructor().newInstance(); ReflectionUtils.invokeMethod(plugin, "init", ProxyServer.getInstance(), desc); diff --git a/src/net/md_5/bungee/api/bungeepluginmanager/ReflectionUtils.java b/src/net/md_5/bungee/api/bungeepluginmanager/ReflectionUtils.java index 8bcd5d5..4ef2e86 100644 --- a/src/net/md_5/bungee/api/bungeepluginmanager/ReflectionUtils.java +++ b/src/net/md_5/bungee/api/bungeepluginmanager/ReflectionUtils.java @@ -70,20 +70,21 @@ public final class ReflectionUtils { return null; } - static void invokeMethod(Object obj, String methodName, Object... args) { + static Object invokeMethod(Object obj, String methodName, Object... args) { Class clazz = obj.getClass(); do { try { for (Method method : clazz.getDeclaredMethods()) { if (method.getName().equals(methodName) && method.getParameterTypes().length == args.length) { method.setAccessible(true); - method.invoke(obj, args); + return method.invoke(obj, args); } } } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException error) { // Ignore } } while ((clazz = clazz.getSuperclass()) != null); + throw new SecurityException("Method could not be found!"); } }