mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 07:20:24 +01:00
Added enablePlugin and disablePlugin, triggers events
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
91e76c3c32
commit
f436f334ed
5 changed files with 93 additions and 0 deletions
|
@ -34,4 +34,22 @@ public interface PluginLoader {
|
||||||
* @param event Event details
|
* @param event Event details
|
||||||
*/
|
*/
|
||||||
public void callEvent(RegisteredListener registration, Event event);
|
public void callEvent(RegisteredListener registration, Event event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables the specified plugin
|
||||||
|
*
|
||||||
|
* Attempting to enable a plugin that is already enabled will have no effect
|
||||||
|
*
|
||||||
|
* @param plugin Plugin to enable
|
||||||
|
*/
|
||||||
|
public void enablePlugin(Plugin plugin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables the specified plugin
|
||||||
|
*
|
||||||
|
* Attempting to disable a plugin that is not enabled will have no effect
|
||||||
|
*
|
||||||
|
* @param plugin Plugin to disable
|
||||||
|
*/
|
||||||
|
public void disablePlugin(Plugin plugin);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,4 +84,22 @@ public interface PluginManager {
|
||||||
* @param plugin Plugin to register
|
* @param plugin Plugin to register
|
||||||
*/
|
*/
|
||||||
public void registerEvent(Event.Type type, Listener listener, Priority priority, Plugin plugin);
|
public void registerEvent(Event.Type type, Listener listener, Priority priority, Plugin plugin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables the specified plugin
|
||||||
|
*
|
||||||
|
* Attempting to enable a plugin that is already enabled will have no effect
|
||||||
|
*
|
||||||
|
* @param plugin Plugin to enable
|
||||||
|
*/
|
||||||
|
public void enablePlugin(Plugin plugin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables the specified plugin
|
||||||
|
*
|
||||||
|
* Attempting to disable a plugin that is not enabled will have no effect
|
||||||
|
*
|
||||||
|
* @param plugin Plugin to disable
|
||||||
|
*/
|
||||||
|
public void disablePlugin(Plugin plugin);
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,6 +161,18 @@ public final class SimplePluginManager implements PluginManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void enablePlugin(final Plugin plugin) {
|
||||||
|
if (!plugin.isEnabled()) {
|
||||||
|
plugin.getPluginLoader().enablePlugin(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disablePlugin(final Plugin plugin) {
|
||||||
|
if (plugin.isEnabled()) {
|
||||||
|
plugin.getPluginLoader().disablePlugin(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls a player related event with the given details
|
* Calls a player related event with the given details
|
||||||
*
|
*
|
||||||
|
|
|
@ -88,4 +88,21 @@ public abstract class JavaPlugin implements Plugin {
|
||||||
protected ClassLoader getClassLoader() {
|
protected ClassLoader getClassLoader() {
|
||||||
return classLoader;
|
return classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the enabled state of this plugin
|
||||||
|
*
|
||||||
|
* @param enabled true if enabled, otherwise false
|
||||||
|
*/
|
||||||
|
protected void setEnabled(final boolean enabled) {
|
||||||
|
if (isEnabled != enabled) {
|
||||||
|
isEnabled = enabled;
|
||||||
|
|
||||||
|
if (isEnabled) {
|
||||||
|
onEnable();
|
||||||
|
} else {
|
||||||
|
onDisable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,4 +138,32 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void enablePlugin(final Plugin plugin) {
|
||||||
|
if (!(plugin instanceof JavaPlugin)) {
|
||||||
|
throw new IllegalArgumentException("Plugin is not associated with this PluginLoader");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.isEnabled()) {
|
||||||
|
JavaPlugin jPlugin = (JavaPlugin)plugin;
|
||||||
|
|
||||||
|
server.getPluginManager().callEvent(new PluginEvent(Event.Type.PLUGIN_ENABLE, plugin));
|
||||||
|
|
||||||
|
jPlugin.setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disablePlugin(Plugin plugin) {
|
||||||
|
if (!(plugin instanceof JavaPlugin)) {
|
||||||
|
throw new IllegalArgumentException("Plugin is not associated with this PluginLoader");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!plugin.isEnabled()) {
|
||||||
|
JavaPlugin jPlugin = (JavaPlugin)plugin;
|
||||||
|
|
||||||
|
server.getPluginManager().callEvent(new PluginEvent(Event.Type.PLUGIN_DISABLE, plugin));
|
||||||
|
|
||||||
|
jPlugin.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue