Use a special plugin class loader to resolve classes from other plugins.

This commit is contained in:
md_5 2013-02-01 19:46:06 +11:00
parent c21b87d930
commit 5e3a3d438a
2 changed files with 34 additions and 1 deletions

View File

@ -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<PluginClassloader> 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();
}
}

View File

@ -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()
});