1
0

Hotfix: Inserting chinese code

Dieser Commit ist enthalten in:
Lixfel 2020-04-19 13:23:29 +02:00
Ursprung f4ea5c7b5c
Commit 340383a2b9
4 geänderte Dateien mit 42 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -1,8 +1,8 @@
package de.steamwar.bungeecore;
import net.md_5.bungee.api.plugin.ModifiedPluginEventBus;
import net.md_5.bungee.api.plugin.PluginUtils;
import net.md_5.bungee.api.plugin.ReflectionUtils;
import net.md_5.bungee.api.bungeepluginmanager.ModifiedPluginEventBus;
import net.md_5.bungee.api.bungeepluginmanager.PluginUtils;
import net.md_5.bungee.api.bungeepluginmanager.ReflectionUtils;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Plugin;

Datei anzeigen

@ -1,4 +1,4 @@
package net.md_5.bungee.api.plugin;
package net.md_5.bungee.api.bungeepluginmanager;
import net.md_5.bungee.api.event.AsyncEvent;
import net.md_5.bungee.api.plugin.Plugin;

Datei anzeigen

@ -1,14 +1,20 @@
package net.md_5.bungee.api.plugin;
package net.md_5.bungee.api.bungeepluginmanager;
import com.google.common.base.Preconditions;
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 java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Handler;
@ -94,10 +100,15 @@ public final class PluginUtils {
severe("Failed to close the classloader for plugin", t, plugin.getDescription().getName());
}
}
//remove classloader
Set<PluginClassloader> allLoaders = ReflectionUtils.getStaticFieldValue(PluginClassloader.class, "allLoaders");
if (checkReflectionNotNull(allLoaders, "allLoaders")) {
// Remove classloader
try {
Class<?> PluginClassLoader = Class.forName("net.md_5.bungee.api.plugin.PluginClassloader");
Set<?> allLoaders = ReflectionUtils.getStaticFieldValue(PluginClassLoader, "allLoaders");
Preconditions.checkNotNull(allLoaders);
allLoaders.remove(pluginClassLoader);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
@ -123,39 +134,37 @@ public final class PluginUtils {
try (InputStream in = jar.getInputStream(pdf)) {
//load description
PluginDescription desc = new Yaml().loadAs(in, PluginDescription.class);
Representer representer = new Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
PluginDescription desc = new Yaml(new Constructor(PluginDescription.class), representer).loadAs(in, PluginDescription.class);
desc.setFile(pluginFile);
//check depends
HashSet<String> plugins = new HashSet<>();
ProxyServer.getInstance().getPluginManager().getPlugins().forEach(plugin -> plugins.add(plugin.getDescription().getName()));
Map<String, Plugin> pluginsMap = ReflectionUtils.getFieldValue(ProxyServer.getInstance().getPluginManager(), "plugins");
Preconditions.checkNotNull(pluginsMap);
for (String dependency : desc.getDepends()) {
if (!plugins.contains(dependency)) {
if (!pluginsMap.keySet().contains(dependency)) {
ProxyServer.getInstance().getLogger().log(Level.WARNING, "{0} (required by {1}) is unavailable", new Object[]{dependency, desc.getName()});
return false;
}
}
// do actual loading
Class<?> main;
try (URLClassLoader loader = new PluginClassloader(ProxyServer.getInstance(), desc, new URL[]{pluginFile.toURI().toURL()})) {
main = loader.loadClass(desc.getMain());
Enumeration<JarEntry> entries = jar.entries();
while(entries.hasMoreElements()){
JarEntry entry = entries.nextElement();
if(!entry.isDirectory() && entry.getName().endsWith(".class")){
loader.loadClass(entry.getName().replace('/', '.').replace(".class", ""));
}
}
}
Plugin clazz = (Plugin) main.getDeclaredConstructor().newInstance();
// reflection
Map<String, Plugin> pluginsMap = ReflectionUtils.getFieldValue(ProxyServer.getInstance().getPluginManager(), "plugins");
ReflectionUtils.invokeMethod(clazz, "init", ProxyServer.getInstance(), desc);
//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);
constructor.setAccessible(true);
URLClassLoader loader = (URLClassLoader) constructor.newInstance(ProxyServer.getInstance(), desc, new URL[]{pluginFile.toURI().toURL()});
Class<?> mainclazz = loader.loadClass(desc.getMain());
Plugin plugin = (Plugin) mainclazz.getDeclaredConstructor().newInstance();
ReflectionUtils.invokeMethod(plugin, "init", ProxyServer.getInstance(), desc);
pluginsMap.put(desc.getName(), clazz);
clazz.onLoad();
clazz.onEnable();
pluginsMap.put(desc.getName(), plugin);
plugin.onLoad();
plugin.onEnable();
return true;
}
} catch (Exception t) {

Datei anzeigen

@ -1,4 +1,4 @@
package net.md_5.bungee.api.plugin;
package net.md_5.bungee.api.bungeepluginmanager;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;