Use a special plugin class loader to resolve classes from other plugins.
This commit is contained in:
parent
c21b87d930
commit
5e3a3d438a
@ -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();
|
||||
}
|
||||
}
|
@ -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()
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user