diff --git a/paper-api/src/org/bukkit/plugin/PluginLoader.java b/paper-api/src/org/bukkit/plugin/PluginLoader.java index 01112122e4..541b14c514 100644 --- a/paper-api/src/org/bukkit/plugin/PluginLoader.java +++ b/paper-api/src/org/bukkit/plugin/PluginLoader.java @@ -5,38 +5,10 @@ import java.io.File; import java.util.regex.Pattern; /** - * Represents a plugin loader, which provides access and management for all plugins - * currently loaded on a server instance + * Represents a plugin loader, which handles direct access to specific types + * of plugins */ public interface PluginLoader { - /** - * Checks if the given plugin is loaded and returns it when applicable - * - * Please note that the name of the plugin is case-sensitive - * - * @param name Name of the plugin to check - * @return Plugin if it exists, otherwise null - */ - public Plugin getPlugin(String name); - - /** - * Checks if the given plugin is enabled or not - * - * Please note that the name of the plugin is case-sensitive. - * - * @param name Name of the plugin to check - * @return true if the plugin is enabled, otherwise false - */ - public boolean isPluginEnabled(String name); - - /** - * Checks if the given plugin is enabled or not - * - * @param plugin Plugin to check - * @return true if the plugin is enabled, otherwise false - */ - public boolean isPluginEnabled(Plugin plugin); - /** * Loads the plugin contained in the specified file * diff --git a/paper-api/src/org/bukkit/plugin/PluginManager.java b/paper-api/src/org/bukkit/plugin/PluginManager.java index d1d15c67ad..7a3997969a 100644 --- a/paper-api/src/org/bukkit/plugin/PluginManager.java +++ b/paper-api/src/org/bukkit/plugin/PluginManager.java @@ -6,6 +6,7 @@ import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -18,8 +19,9 @@ import java.util.regex.Pattern; */ public final class PluginManager { private final Server server; - private final HashMap fileAssociations = new HashMap(); + private final Map fileAssociations = new HashMap(); private final List plugins = new ArrayList(); + private final Map lookupNames = new HashMap(); public PluginManager(Server instance) { server = instance; @@ -107,9 +109,50 @@ public final class PluginManager { if (result != null) { plugins.add(result); + lookupNames.put(result.getDescription().getName(), result); result.onInitialize(); } return result; } + + /** + * Checks if the given plugin is loaded and returns it when applicable + * + * Please note that the name of the plugin is case-sensitive + * + * @param name Name of the plugin to check + * @return Plugin if it exists, otherwise null + */ + public Plugin getPlugin(String name) { + return lookupNames.get(name); + } + + /** + * Checks if the given plugin is enabled or not + * + * Please note that the name of the plugin is case-sensitive. + * + * @param name Name of the plugin to check + * @return true if the plugin is enabled, otherwise false + */ + public boolean isPluginEnabled(String name) { + Plugin plugin = getPlugin(name); + + return isPluginEnabled(plugin); + } + + /** + * Checks if the given plugin is enabled or not + * + * @param plugin Plugin to check + * @return true if the plugin is enabled, otherwise false + */ + public boolean isPluginEnabled(Plugin plugin) { + if ((plugin != null) && (plugins.contains(plugin))) { + return plugin.isEnabled(); + } else { + return false; + } + } } diff --git a/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java index b5ca9d9af9..085e96f758 100644 --- a/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java @@ -4,11 +4,8 @@ package org.bukkit.plugin.java; import java.io.File; import java.io.FileNotFoundException; import java.lang.reflect.Constructor; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.util.logging.Level; -import java.util.logging.Logger; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginLoader; import java.util.regex.Pattern; @@ -29,18 +26,6 @@ public final class JavaPluginLoader implements PluginLoader { server = instance; } - public Plugin getPlugin(String name) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public boolean isPluginEnabled(String name) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public boolean isPluginEnabled(Plugin plugin) { - throw new UnsupportedOperationException("Not supported yet."); - } - public Plugin loadPlugin(File file) throws InvalidPluginException { JavaPlugin result = null; PluginDescriptionFile description = new PluginDescriptionFile("Sample Plugin", "org.bukkit.plugin.sample.main");