12
1

Remove classloader mishap
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2022-05-11 11:25:39 +02:00
Ursprung bee858695f
Commit 3ed9cc04de
2 geänderte Dateien mit 0 neuen und 529 gelöschten Zeilen

Datei anzeigen

@ -1,290 +0,0 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package org.bukkit.plugin.java;
import com.google.common.base.Charsets;
import org.apache.commons.lang.Validate;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.PluginBase;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.PluginLogger;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class JavaPlugin extends PluginBase {
private boolean isEnabled = false;
private PluginLoader loader = null;
private Server server = null;
private File file = null;
private PluginDescriptionFile description = null;
private File dataFolder = null;
private ClassLoader classLoader = null;
private boolean naggable = true;
private FileConfiguration newConfig = null;
private File configFile = null;
private PluginLogger logger = null;
public JavaPlugin() {
init(PluginClassLoader.current.loader, PluginClassLoader.current.loader.server, PluginClassLoader.current.description, PluginClassLoader.current.dataFolder, PluginClassLoader.current.file, PluginClassLoader.current);
}
protected JavaPlugin( JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
ClassLoader classLoader = this.getClass().getClassLoader();
if (classLoader instanceof PluginClassLoader) {
throw new IllegalStateException("Cannot use initialization constructor at runtime");
} else {
this.init(loader, loader.server, description, dataFolder, file, classLoader);
}
}
public final File getDataFolder() {
return this.dataFolder;
}
public final PluginLoader getPluginLoader() {
return this.loader;
}
public final Server getServer() {
return this.server;
}
public final boolean isEnabled() {
return this.isEnabled;
}
protected File getFile() {
return this.file;
}
public final PluginDescriptionFile getDescription() {
return this.description;
}
public FileConfiguration getConfig() {
if (this.newConfig == null) {
this.reloadConfig();
}
return this.newConfig;
}
protected final Reader getTextResource( String file) {
InputStream in = this.getResource(file);
return in == null ? null : new InputStreamReader(in, Charsets.UTF_8);
}
public void reloadConfig() {
this.newConfig = YamlConfiguration.loadConfiguration(this.configFile);
InputStream defConfigStream = this.getResource("config.yml");
if (defConfigStream != null) {
this.newConfig.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
}
}
public void saveConfig() {
try {
this.getConfig().save(this.configFile);
} catch (IOException var2) {
this.logger.log(Level.SEVERE, "Could not save config to " + this.configFile, var2);
}
}
public void saveDefaultConfig() {
if (!this.configFile.exists()) {
this.saveResource("config.yml", false);
}
}
public void saveResource( String resourcePath, boolean replace) {
if (resourcePath != null && !resourcePath.equals("")) {
resourcePath = resourcePath.replace('\\', '/');
InputStream in = this.getResource(resourcePath);
if (in == null) {
throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + this.file);
} else {
File outFile = new File(this.dataFolder, resourcePath);
int lastIndex = resourcePath.lastIndexOf(47);
File outDir = new File(this.dataFolder, resourcePath.substring(0, lastIndex >= 0 ? lastIndex : 0));
if (!outDir.exists()) {
outDir.mkdirs();
}
try {
if (outFile.exists() && !replace) {
this.logger.log(Level.WARNING, "Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists.");
} else {
OutputStream out = new FileOutputStream(outFile);
byte[] buf = new byte[1024];
int len;
while((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
in.close();
}
} catch (IOException var10) {
this.logger.log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + outFile, var10);
}
}
} else {
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
}
}
public InputStream getResource( String filename) {
try {
URL url = this.getClassLoader().getResource(filename);
if (url == null) {
return null;
} else {
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
return connection.getInputStream();
}
} catch (IOException var4) {
return null;
}
}
protected final ClassLoader getClassLoader() {
return this.classLoader;
}
protected final void setEnabled(boolean enabled) {
if (this.isEnabled != enabled) {
this.isEnabled = enabled;
if (this.isEnabled) {
this.onEnable();
} else {
this.onDisable();
}
}
}
final void init( PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader) {
this.loader = loader;
this.server = server;
this.file = file;
this.description = description;
this.dataFolder = dataFolder;
this.classLoader = classLoader;
this.configFile = new File(dataFolder, "config.yml");
this.logger = new PluginLogger(this);
}
public boolean onCommand( CommandSender sender, Command command, String label, String[] args) {
return false;
}
public List<String> onTabComplete( CommandSender sender, Command command, String alias, String[] args) {
return null;
}
public PluginCommand getCommand( String name) {
String alias = name.toLowerCase(Locale.ENGLISH);
PluginCommand command = this.getServer().getPluginCommand(alias);
if (command == null || command.getPlugin() != this) {
command = this.getServer().getPluginCommand(this.description.getName().toLowerCase(Locale.ENGLISH) + ":" + alias);
}
return command != null && command.getPlugin() == this ? command : null;
}
public void onLoad() {
}
public void onDisable() {
}
public void onEnable() {
}
public ChunkGenerator getDefaultWorldGenerator( String worldName, String id) {
return null;
}
public final boolean isNaggable() {
return this.naggable;
}
public final void setNaggable(boolean canNag) {
this.naggable = canNag;
}
public Logger getLogger() {
return this.logger;
}
public String toString() {
return this.description.getFullName();
}
public static <T extends JavaPlugin> T getPlugin( Class<T> clazz) {
Validate.notNull(clazz, "Null class cannot have a plugin");
if (!JavaPlugin.class.isAssignableFrom(clazz)) {
throw new IllegalArgumentException(clazz + " does not extend " + JavaPlugin.class);
} else {
ClassLoader cl = clazz.getClassLoader();
if (!(cl instanceof PluginClassLoader)) {
throw new IllegalArgumentException(clazz + " is not initialized by " + PluginClassLoader.class);
} else {
JavaPlugin plugin = ((PluginClassLoader)cl).plugin;
if (plugin == null) {
throw new IllegalStateException("Cannot get plugin for " + clazz + " from a static initializer");
} else {
return clazz.cast(plugin);
}
}
}
}
public static JavaPlugin getProvidingPlugin( Class<?> clazz) {
Validate.notNull(clazz, "Null class cannot have a plugin");
ClassLoader cl = clazz.getClassLoader();
if (!(cl instanceof PluginClassLoader)) {
throw new IllegalArgumentException(clazz + " is not provided by " + PluginClassLoader.class);
} else {
JavaPlugin plugin = ((PluginClassLoader)cl).plugin;
return plugin;
}
}
}

Datei anzeigen

@ -1,239 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package org.bukkit.plugin.java;
import com.google.common.io.ByteStreams;
import org.apache.commons.lang.Validate;
import org.bukkit.plugin.InvalidPluginException;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.SimplePluginManager;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.CodeSigner;
import java.security.CodeSource;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.logging.Level;
final class PluginClassLoader extends URLClassLoader {
static PluginClassLoader current;
final JavaPluginLoader loader;
private final Map<String, Class<?>> classes = new ConcurrentHashMap();
final PluginDescriptionFile description;
final File dataFolder;
final File file;
private final JarFile jar;
private final Manifest manifest;
private final URL url;
final JavaPlugin plugin;
private JavaPlugin pluginInit;
private IllegalStateException pluginState;
private final Set<String> seenIllegalAccess = Collections.newSetFromMap(new ConcurrentHashMap());
static {
ClassLoader.registerAsParallelCapable();
}
PluginClassLoader( JavaPluginLoader loader, ClassLoader parent, PluginDescriptionFile description, File dataFolder, File file) throws IOException, InvalidPluginException, MalformedURLException {
super(new URL[]{file.toURI().toURL()}, parent);
Validate.notNull(loader, "Loader cannot be null");
this.loader = loader;
this.description = description;
this.dataFolder = dataFolder;
this.file = file;
this.jar = new JarFile(file);
this.manifest = this.jar.getManifest();
this.url = file.toURI().toURL();
try {
Class jarClass;
try {
jarClass = Class.forName(description.getMain(), true, this);
} catch (ClassNotFoundException var10) {
throw new InvalidPluginException("Cannot find main class `" + description.getMain() + "'", var10);
}
Class pluginClass;
try {
pluginClass = jarClass.asSubclass(JavaPlugin.class);
} catch (ClassCastException var9) {
throw new InvalidPluginException("main class `" + description.getMain() + "' does not extend JavaPlugin", var9);
}
current = this;
this.plugin = (JavaPlugin)pluginClass.newInstance();
} catch (IllegalAccessException var11) {
throw new InvalidPluginException("No public constructor", var11);
} catch (InstantiationException var12) {
throw new InvalidPluginException("Abnormal plugin type", var12);
}
}
public URL getResource(String name) {
return this.findResource(name);
}
public Enumeration<URL> getResources(String name) throws IOException {
return this.findResources(name);
}
protected Class<?> findClass(String name) throws ClassNotFoundException {
return this.findClass(name, true);
}
Class<?> findClass( String name, boolean checkGlobal) throws ClassNotFoundException {
if (!name.startsWith("org.bukkit.") && !name.startsWith("net.minecraft.")) {
Class<?> result = (Class)this.classes.get(name);
if (result == null) {
if (checkGlobal) {
result = this.loader.getClassByName(name);
if (result != null) {
PluginDescriptionFile provider = ((PluginClassLoader)result.getClassLoader()).description;
if (provider != this.description && !this.seenIllegalAccess.contains(provider.getName()) && !((SimplePluginManager)this.loader.server.getPluginManager()).isTransitiveDepend(this.description, provider)) {
this.seenIllegalAccess.add(provider.getName());
if (this.plugin != null) {
this.plugin.getLogger().log(Level.WARNING, "Loaded class {0} from {1} which is not a depend, softdepend or loadbefore of this plugin.", new Object[]{name, provider.getFullName()});
} else {
this.loader.server.getLogger().log(Level.WARNING, "[{0}] Loaded class {1} from {2} which is not a depend, softdepend or loadbefore of this plugin.", new Object[]{this.description.getName(), name, provider.getFullName()});
}
}
}
}
if (result == null) {
String path = name.replace('.', '/').concat(".class");
JarEntry entry = this.jar.getJarEntry(path);
if (entry != null) {
byte[] classBytes;
String pkgName;
try {
Throwable var7 = null;
pkgName = null;
try {
InputStream is = this.jar.getInputStream(entry);
try {
classBytes = ByteStreams.toByteArray(is);
} finally {
if (is != null) {
is.close();
}
}
} catch (Throwable var19) {
if (var7 == null) {
var7 = var19;
} else if (var7 != var19) {
var7.addSuppressed(var19);
}
throw var19;
}
} catch (IOException var20) {
throw new ClassNotFoundException(name, var20);
}
classBytes = this.loader.server.getUnsafe().processClass(this.description, path, classBytes);
int dot = name.lastIndexOf(46);
if (dot != -1) {
pkgName = name.substring(0, dot);
if (this.getPackage(pkgName) == null) {
try {
if (this.manifest != null) {
this.definePackage(pkgName, this.manifest, this.url);
} else {
this.definePackage(pkgName, (String)null, (String)null, (String)null, (String)null, (String)null, (String)null, (URL)null);
}
} catch (IllegalArgumentException var21) {
if (this.getPackage(pkgName) == null) {
throw new IllegalStateException("Cannot find package " + pkgName);
}
}
}
}
CodeSigner[] signers = entry.getCodeSigners();
CodeSource source = new CodeSource(this.url, signers);
result = this.defineClass(name, classBytes, 0, classBytes.length, source);
}
if (result == null) {
result = super.findClass(name);
}
if (result != null) {
this.loader.setClass(name, result);
}
this.classes.put(name, result);
}
}
return result;
} else {
throw new ClassNotFoundException(name);
}
}
public void close() throws IOException {
try {
super.close();
} finally {
this.jar.close();
}
}
Set<String> getClasses() {
return this.classes.keySet();
}
synchronized void initialize( JavaPlugin javaPlugin) {
Validate.notNull(javaPlugin, "Initializing plugin cannot be null");
Validate.isTrue(javaPlugin.getClass().getClassLoader() == this, "Cannot initialize plugin outside of this class loader");
if (this.plugin == null && this.pluginInit == null) {
this.pluginState = new IllegalStateException("Initial initialization");
this.pluginInit = javaPlugin;
javaPlugin.init(this.loader, this.loader.server, this.description, this.dataFolder, this.file, this);
} else {
throw new IllegalArgumentException("Plugin already initialized!", this.pluginState);
}
}
}