From 8b6f1612a136c27b6c91a62c888e0056698dbc58 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 16 Jun 2012 00:48:47 -0500 Subject: [PATCH] Revert "Shift plugin initialization; Addresses BUKKIT-1788" This reverts commit 27cb5e7c9c6b2cfc5419262df75d89bc6bfe7879. Issues were discovered with shared class loaders. By: Wesley Wolfe --- .../org/bukkit/plugin/java/JavaPlugin.java | 7 +---- .../bukkit/plugin/java/JavaPluginLoader.java | 4 ++- .../bukkit/plugin/java/PluginClassLoader.java | 30 ------------------- 3 files changed, 4 insertions(+), 37 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java index 188a61434f..b7ecc18111 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java @@ -49,12 +49,7 @@ public abstract class JavaPlugin extends PluginBase { private File configFile = null; private PluginLogger logger = null; - public JavaPlugin() { - ClassLoader classLoader = this.getClass().getClassLoader(); - if (classLoader instanceof PluginClassLoader) { - ((PluginClassLoader) classLoader).initialize(this); - } - } + public JavaPlugin() {} /** * Returns the folder that the plugin data's files are located in. The diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 6ddcc1d595..38ca9422c8 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -134,7 +134,7 @@ public class JavaPluginLoader implements PluginLoader { loader = loaders.get(description.getClassLoaderOf()); loader.addURL(urls[0]); } else { - loader = new PluginClassLoader(this, urls, getClass().getClassLoader(), server, description, dataFolder, file); + loader = new PluginClassLoader(this, urls, getClass().getClassLoader()); } Class jarClass = Class.forName(description.getMain(), true, loader); @@ -143,6 +143,8 @@ public class JavaPluginLoader implements PluginLoader { Constructor constructor = plugin.getConstructor(); result = constructor.newInstance(); + + result.initialize(this, server, description, dataFolder, file, loader); } catch (InvocationTargetException ex) { throw new InvalidPluginException(ex.getCause()); } catch (Throwable ex) { diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java index 6a9b4bbaab..dd7bffc5b6 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java @@ -1,43 +1,22 @@ package org.bukkit.plugin.java; -import java.io.File; import java.net.URL; import java.net.URLClassLoader; import java.util.HashMap; import java.util.Map; import java.util.Set; -import org.apache.commons.lang.Validate; -import org.bukkit.Server; -import org.bukkit.plugin.PluginDescriptionFile; - /** * A ClassLoader for plugins, to allow shared classes across multiple plugins */ public class PluginClassLoader extends URLClassLoader { private final JavaPluginLoader loader; private final Map> classes = new HashMap>(); - private final PluginDescriptionFile description; - private final Server server; - private final File dataFolder; - private final File file; - /** - * Changed in favor of class loader that initializes plugins - */ - @Deprecated public PluginClassLoader(final JavaPluginLoader loader, final URL[] urls, final ClassLoader parent) { - this(loader, urls, parent, null, null, null, null); - } - - public PluginClassLoader(final JavaPluginLoader loader, final URL[] urls, final ClassLoader parent, final Server server, final PluginDescriptionFile description, final File dataFolder, final File file) { super(urls, parent); this.loader = loader; - this.server = server; - this.description = description; - this.dataFolder = dataFolder; - this.file = file; } @Override @@ -75,13 +54,4 @@ public class PluginClassLoader extends URLClassLoader { public Set getClasses() { return classes.keySet(); } - - 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 (server != null && description != null && dataFolder != null && file != null) { - javaPlugin.initialize(loader, server, description, dataFolder, file, this); - } - } }