Merge pull request #15 from FrankHeijden/fix/bungeecord-compatibility
Add support for latest BungeeCord/Waterfall, fixes #14
This commit is contained in:
commit
b0159488e2
6 changed files with 38 additions and 23 deletions
|
|
@ -11,7 +11,7 @@ dependencies {
|
|||
implementation 'co.aikar:acf-bungee:0.5.0-SNAPSHOT'
|
||||
implementation 'org.bstats:bstats-bungeecord:1.8'
|
||||
implementation project(":Common")
|
||||
compileOnly 'net.md-5:bungeecord-api:1.16-R0.4-SNAPSHOT'
|
||||
compileOnly 'net.md-5:bungeecord-api:1.16-R0.5-SNAPSHOT'
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
|
|
|||
|
|
@ -8,14 +8,9 @@ import net.frankheijden.serverutils.bungee.commands.CommandServerUtils;
|
|||
import net.frankheijden.serverutils.bungee.entities.BungeePlugin;
|
||||
import net.frankheijden.serverutils.bungee.listeners.BungeeListener;
|
||||
import net.frankheijden.serverutils.bungee.managers.BungeePluginManager;
|
||||
import net.frankheijden.serverutils.bungee.reflection.RPluginClassLoader;
|
||||
import net.frankheijden.serverutils.bungee.reflection.RPluginManager;
|
||||
import net.frankheijden.serverutils.common.ServerUtilsApp;
|
||||
import net.frankheijden.serverutils.common.config.Config;
|
||||
import net.frankheijden.serverutils.common.config.Messenger;
|
||||
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
||||
import net.frankheijden.serverutils.common.entities.Result;
|
||||
import net.frankheijden.serverutils.common.utils.MapUtils;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
|
||||
|
|
@ -53,7 +48,6 @@ public class ServerUtils extends Plugin {
|
|||
|
||||
plugin.enable();
|
||||
|
||||
loadClasses();
|
||||
ServerUtilsApp.tryCheckForUpdates();
|
||||
}
|
||||
|
||||
|
|
@ -64,16 +58,6 @@ public class ServerUtils extends Plugin {
|
|||
plugin.disable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads some classes in memory so they're available during updating.
|
||||
*/
|
||||
private void loadClasses() {
|
||||
new RPluginManager();
|
||||
new MapUtils();
|
||||
new CloseableResult(Result.SUCCESS);
|
||||
new RPluginClassLoader();
|
||||
}
|
||||
|
||||
public static ServerUtils getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
|
|||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -21,6 +20,7 @@ import net.frankheijden.serverutils.bungee.events.BungeePluginDisableEvent;
|
|||
import net.frankheijden.serverutils.bungee.events.BungeePluginEnableEvent;
|
||||
import net.frankheijden.serverutils.bungee.events.BungeePluginLoadEvent;
|
||||
import net.frankheijden.serverutils.bungee.events.BungeePluginUnloadEvent;
|
||||
import net.frankheijden.serverutils.bungee.reflection.RLibraryLoader;
|
||||
import net.frankheijden.serverutils.bungee.reflection.RPluginClassLoader;
|
||||
import net.frankheijden.serverutils.bungee.reflection.RPluginManager;
|
||||
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
||||
|
|
@ -82,8 +82,14 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
|
|||
}
|
||||
|
||||
try {
|
||||
URL url = desc.getFile().toURI().toURL();
|
||||
URLClassLoader loader = (URLClassLoader) RPluginClassLoader.newInstance(proxy, desc, url);
|
||||
Object libraryLoader = RPluginManager.getLibraryLoader(proxy.getPluginManager());
|
||||
ClassLoader classLoader = RLibraryLoader.createLoader(libraryLoader, desc);
|
||||
URLClassLoader loader = (URLClassLoader) RPluginClassLoader.newInstance(
|
||||
proxy,
|
||||
desc,
|
||||
desc.getFile(),
|
||||
classLoader
|
||||
);
|
||||
|
||||
Class<?> main = loader.loadClass(desc.getMain());
|
||||
Plugin plugin = (Plugin) main.getDeclaredConstructor().newInstance();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package net.frankheijden.serverutils.bungee.reflection;
|
||||
|
||||
import dev.frankheijden.minecraftreflection.MinecraftReflection;
|
||||
import net.md_5.bungee.api.plugin.PluginDescription;
|
||||
|
||||
public class RLibraryLoader {
|
||||
|
||||
private static final MinecraftReflection reflection = MinecraftReflection
|
||||
.of("net.md_5.bungee.api.plugin.LibraryLoader");
|
||||
|
||||
private RLibraryLoader() {}
|
||||
|
||||
public static ClassLoader createLoader(Object instance, PluginDescription desc) {
|
||||
return instance == null ? null : reflection.invoke(instance, "createLoader", desc);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package net.frankheijden.serverutils.bungee.reflection;
|
||||
|
||||
import java.net.URL;
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import dev.frankheijden.minecraftreflection.ClassObject;
|
||||
import dev.frankheijden.minecraftreflection.MinecraftReflection;
|
||||
|
|
@ -13,14 +13,17 @@ public class RPluginClassLoader {
|
|||
private static final MinecraftReflection reflection = MinecraftReflection
|
||||
.of("net.md_5.bungee.api.plugin.PluginClassloader");
|
||||
|
||||
private RPluginClassLoader() {}
|
||||
|
||||
/**
|
||||
* Creates a new instance of a PluginClassLoader from given parameters.
|
||||
*/
|
||||
public static Object newInstance(ProxyServer proxy, PluginDescription desc, URL... urls) {
|
||||
public static Object newInstance(ProxyServer proxy, PluginDescription desc, File file, ClassLoader classLoader) {
|
||||
return reflection.newInstance(
|
||||
ClassObject.of(ProxyServer.class, proxy),
|
||||
ClassObject.of(PluginDescription.class, desc),
|
||||
ClassObject.of(URL[].class, urls)
|
||||
ClassObject.of(File.class, file),
|
||||
ClassObject.of(ClassLoader.class, classLoader)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ public class RPluginManager {
|
|||
private static final MinecraftReflection reflection = MinecraftReflection
|
||||
.of("net.md_5.bungee.api.plugin.PluginManager");
|
||||
|
||||
private RPluginManager() {}
|
||||
|
||||
/**
|
||||
* Clears the plugin from the PluginManager.
|
||||
* @param instance The instance of the PluginManager.
|
||||
|
|
@ -51,4 +53,8 @@ public class RPluginManager {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getLibraryLoader(Object instance) {
|
||||
return reflection.get(instance, "libraryLoader");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue