From 118fbe5d87e343c000ebfa72df2573e01171b311 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 24 Dec 2010 12:55:46 +0000 Subject: [PATCH] Pass the Server instance to pluginloaders, changed register method on pluginmanager By: Dinnerbone --- .../src/org/bukkit/plugin/PluginManager.java | 25 ++++++++++++++++--- .../bukkit/plugin/java/JavaPluginLoader.java | 6 +++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/paper-api/src/org/bukkit/plugin/PluginManager.java b/paper-api/src/org/bukkit/plugin/PluginManager.java index 1de78b9a25..1185440731 100644 --- a/paper-api/src/org/bukkit/plugin/PluginManager.java +++ b/paper-api/src/org/bukkit/plugin/PluginManager.java @@ -2,6 +2,7 @@ package org.bukkit.plugin; import java.io.File; +import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -24,13 +25,29 @@ public final class PluginManager { /** * Registers the specified plugin loader * - * @param loader PluginLoader to register + * @param loader Class name of the PluginLoader to register */ - public void RegisterInterface(PluginLoader loader) { - Pattern[] patterns = loader.getPluginFileFilters(); + public void RegisterInterface(Class loader) { + PluginLoader instance; + + if (PluginLoader.class.isAssignableFrom(loader)) { + Constructor constructor; + try { + constructor = loader.getConstructor(Server.class); + instance = (PluginLoader) constructor.newInstance(server); + } catch (NoSuchMethodException ex) { + throw new IllegalArgumentException(String.format("Class %s does not have a public %s(Server) constructor", loader.getName()), ex); + } catch (Exception ex) { + throw new IllegalArgumentException(String.format("Unexpected exception %s while attempting to construct a new instance of %s", ex.getClass().getName(), loader.getName()), ex); + } + } else { + throw new IllegalArgumentException(String.format("Class %s does not implement interface PluginLoader", loader.getName())); + } + + Pattern[] patterns = instance.getPluginFileFilters(); for (Pattern pattern : patterns) { - fileAssociations.put(pattern, loader); + fileAssociations.put(pattern, instance); } } diff --git a/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java index abc16deb9a..58d498edbd 100644 --- a/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java @@ -5,15 +5,21 @@ import java.io.File; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginLoader; import java.util.regex.Pattern; +import org.bukkit.Server; /** * Represents a Java plugin loader, allowing plugins in the form of .jars */ public final class JavaPluginLoader implements PluginLoader { + private final Server server; private final Pattern[] fileFilters = new Pattern[] { Pattern.compile("\\.jar$"), }; + public JavaPluginLoader(Server instance) { + server = instance; + } + public Plugin getPlugin(String name) { throw new UnsupportedOperationException("Not supported yet."); }