Add support for latest BungeeCord/Waterfall, fixes #14
This commit is contained in:
parent
c737d0c94a
commit
9871af44f2
6 changed files with 38 additions and 23 deletions
|
|
@ -11,7 +11,7 @@ dependencies {
|
||||||
implementation 'co.aikar:acf-bungee:0.5.0-SNAPSHOT'
|
implementation 'co.aikar:acf-bungee:0.5.0-SNAPSHOT'
|
||||||
implementation 'org.bstats:bstats-bungeecord:1.8'
|
implementation 'org.bstats:bstats-bungeecord:1.8'
|
||||||
implementation project(":Common")
|
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 {
|
processResources {
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,9 @@ import net.frankheijden.serverutils.bungee.commands.CommandServerUtils;
|
||||||
import net.frankheijden.serverutils.bungee.entities.BungeePlugin;
|
import net.frankheijden.serverutils.bungee.entities.BungeePlugin;
|
||||||
import net.frankheijden.serverutils.bungee.listeners.BungeeListener;
|
import net.frankheijden.serverutils.bungee.listeners.BungeeListener;
|
||||||
import net.frankheijden.serverutils.bungee.managers.BungeePluginManager;
|
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.ServerUtilsApp;
|
||||||
import net.frankheijden.serverutils.common.config.Config;
|
import net.frankheijden.serverutils.common.config.Config;
|
||||||
import net.frankheijden.serverutils.common.config.Messenger;
|
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 net.md_5.bungee.api.plugin.Plugin;
|
||||||
import org.bstats.bungeecord.Metrics;
|
import org.bstats.bungeecord.Metrics;
|
||||||
|
|
||||||
|
|
@ -53,7 +48,6 @@ public class ServerUtils extends Plugin {
|
||||||
|
|
||||||
plugin.enable();
|
plugin.enable();
|
||||||
|
|
||||||
loadClasses();
|
|
||||||
ServerUtilsApp.tryCheckForUpdates();
|
ServerUtilsApp.tryCheckForUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,16 +58,6 @@ public class ServerUtils extends Plugin {
|
||||||
plugin.disable();
|
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() {
|
public static ServerUtils getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
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.BungeePluginEnableEvent;
|
||||||
import net.frankheijden.serverutils.bungee.events.BungeePluginLoadEvent;
|
import net.frankheijden.serverutils.bungee.events.BungeePluginLoadEvent;
|
||||||
import net.frankheijden.serverutils.bungee.events.BungeePluginUnloadEvent;
|
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.RPluginClassLoader;
|
||||||
import net.frankheijden.serverutils.bungee.reflection.RPluginManager;
|
import net.frankheijden.serverutils.bungee.reflection.RPluginManager;
|
||||||
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
import net.frankheijden.serverutils.common.entities.CloseableResult;
|
||||||
|
|
@ -82,8 +82,14 @@ public class BungeePluginManager extends AbstractPluginManager<Plugin> {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL url = desc.getFile().toURI().toURL();
|
Object libraryLoader = RPluginManager.getLibraryLoader(proxy.getPluginManager());
|
||||||
URLClassLoader loader = (URLClassLoader) RPluginClassLoader.newInstance(proxy, desc, url);
|
ClassLoader classLoader = RLibraryLoader.createLoader(libraryLoader, desc);
|
||||||
|
URLClassLoader loader = (URLClassLoader) RPluginClassLoader.newInstance(
|
||||||
|
proxy,
|
||||||
|
desc,
|
||||||
|
desc.getFile(),
|
||||||
|
classLoader
|
||||||
|
);
|
||||||
|
|
||||||
Class<?> main = loader.loadClass(desc.getMain());
|
Class<?> main = loader.loadClass(desc.getMain());
|
||||||
Plugin plugin = (Plugin) main.getDeclaredConstructor().newInstance();
|
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;
|
package net.frankheijden.serverutils.bungee.reflection;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.io.File;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import dev.frankheijden.minecraftreflection.ClassObject;
|
import dev.frankheijden.minecraftreflection.ClassObject;
|
||||||
import dev.frankheijden.minecraftreflection.MinecraftReflection;
|
import dev.frankheijden.minecraftreflection.MinecraftReflection;
|
||||||
|
|
@ -13,14 +13,17 @@ public class RPluginClassLoader {
|
||||||
private static final MinecraftReflection reflection = MinecraftReflection
|
private static final MinecraftReflection reflection = MinecraftReflection
|
||||||
.of("net.md_5.bungee.api.plugin.PluginClassloader");
|
.of("net.md_5.bungee.api.plugin.PluginClassloader");
|
||||||
|
|
||||||
|
private RPluginClassLoader() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of a PluginClassLoader from given parameters.
|
* 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(
|
return reflection.newInstance(
|
||||||
ClassObject.of(ProxyServer.class, proxy),
|
ClassObject.of(ProxyServer.class, proxy),
|
||||||
ClassObject.of(PluginDescription.class, desc),
|
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
|
private static final MinecraftReflection reflection = MinecraftReflection
|
||||||
.of("net.md_5.bungee.api.plugin.PluginManager");
|
.of("net.md_5.bungee.api.plugin.PluginManager");
|
||||||
|
|
||||||
|
private RPluginManager() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the plugin from the PluginManager.
|
* Clears the plugin from the PluginManager.
|
||||||
* @param instance The instance of the PluginManager.
|
* @param instance The instance of the PluginManager.
|
||||||
|
|
@ -51,4 +53,8 @@ public class RPluginManager {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object getLibraryLoader(Object instance) {
|
||||||
|
return reflection.get(instance, "libraryLoader");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue