From 5e3a3d438ab225716ef4da4d7c9a10687e95aaed Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 1 Feb 2013 19:46:06 +1100 Subject: [PATCH] Use a special plugin class loader to resolve classes from other plugins. --- .../bungee/api/plugin/PluginClassloader.java | 33 +++++++++++++++++++ .../md_5/bungee/api/plugin/PluginManager.java | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 api/src/main/java/net/md_5/bungee/api/plugin/PluginClassloader.java diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/PluginClassloader.java b/api/src/main/java/net/md_5/bungee/api/plugin/PluginClassloader.java new file mode 100644 index 00000000..0babad65 --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/plugin/PluginClassloader.java @@ -0,0 +1,33 @@ +package net.md_5.bungee.api.plugin; + +import java.net.URL; +import java.net.URLClassLoader; +import java.util.HashSet; +import java.util.Set; + +public class PluginClassloader extends URLClassLoader +{ + + private static final Set allLoaders = new HashSet<>(); + + public PluginClassloader(URL[] urls) + { + super(urls); + allLoaders.add(this); + } + + @Override + protected Class findClass(String name) throws ClassNotFoundException + { + for (PluginClassloader loader : allLoaders) + { + try + { + return loader.loadClass(name); + } catch (ClassNotFoundException ex) + { + } + } + throw new ClassNotFoundException(); + } +} diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java index 1a5f3865..cfcc72f0 100644 --- a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java +++ b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java @@ -158,7 +158,7 @@ public class PluginManager try (InputStream in = jar.getInputStream(pdf)) { PluginDescription desc = yaml.loadAs(in, PluginDescription.class); - URLClassLoader loader = new URLClassLoader(new URL[] + URLClassLoader loader = new PluginClassloader(new URL[] { file.toURI().toURL() });