13
0

Update for new BungeeCord (api)

Dieser Commit ist enthalten in:
Lixfel 2021-05-24 07:56:07 +02:00
Ursprung a92642e612
Commit be90aa57e2
2 geänderte Dateien mit 8 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -24,13 +24,11 @@ import com.google.common.collect.Multimap;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.*;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.representer.Representer;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.representer.Representer;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;
import java.util.ResourceBundle;
@ -169,18 +167,19 @@ public final class PluginUtils {
Preconditions.checkNotNull(pluginsMap);
for (String dependency : desc.getDepends()) {
if (!pluginsMap.keySet().contains(dependency)) {
if (!pluginsMap.containsKey(dependency)) {
ProxyServer.getInstance().getLogger().log(Level.WARNING, "{0} (required by {1}) is unavailable", new Object[]{dependency, desc.getName()});
return false;
}
}
Object libraryLoader = ReflectionUtils.getFieldValue(ProxyServer.getInstance().getPluginManager(), "libraryLoader");
//load plugin
Class<?> pluginClassLoader = Class.forName("net.md_5.bungee.api.plugin.PluginClassloader");
java.lang.reflect.Constructor<?> constructor = pluginClassLoader.getConstructor(ProxyServer.class, PluginDescription.class, URL[].class);
java.lang.reflect.Constructor<?> constructor = pluginClassLoader.getConstructor(ProxyServer.class, PluginDescription.class, File.class, ClassLoader.class);
constructor.setAccessible(true);
URLClassLoader loader = (URLClassLoader) constructor.newInstance(ProxyServer.getInstance(), desc, new URL[]{pluginFile.toURI().toURL()});
URLClassLoader loader = (URLClassLoader) constructor.newInstance(ProxyServer.getInstance(), desc, pluginFile, libraryLoader != null ? ReflectionUtils.invokeMethod(libraryLoader, "createLoader", desc) : null);
Class<?> mainclazz = loader.loadClass(desc.getMain());
Plugin plugin = (Plugin) mainclazz.getDeclaredConstructor().newInstance();
ReflectionUtils.invokeMethod(plugin, "init", ProxyServer.getInstance(), desc);

Datei anzeigen

@ -70,20 +70,21 @@ public final class ReflectionUtils {
return null;
}
static void invokeMethod(Object obj, String methodName, Object... args) {
static Object invokeMethod(Object obj, String methodName, Object... args) {
Class<?> clazz = obj.getClass();
do {
try {
for (Method method : clazz.getDeclaredMethods()) {
if (method.getName().equals(methodName) && method.getParameterTypes().length == args.length) {
method.setAccessible(true);
method.invoke(obj, args);
return method.invoke(obj, args);
}
}
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException error) {
// Ignore
}
} while ((clazz = clazz.getSuperclass()) != null);
throw new SecurityException("Method could not be found!");
}
}