diff --git a/paper-api/src/main/java/org/bukkit/plugin/IllegalPluginAccessException.java b/paper-api/src/main/java/org/bukkit/plugin/IllegalPluginAccessException.java new file mode 100644 index 0000000000..e438d09df1 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/plugin/IllegalPluginAccessException.java @@ -0,0 +1,23 @@ + +package org.bukkit.plugin; + +/** + * Thrown when a plugin attempts to interact with the server when it is not enabled + */ +public class IllegalPluginAccessException extends RuntimeException { + + /** + * Creates a new instance of IllegalPluginAccessException without detail message. + */ + public IllegalPluginAccessException() { + } + + + /** + * Constructs an instance of IllegalPluginAccessException with the specified detail message. + * @param msg the detail message. + */ + public IllegalPluginAccessException(String msg) { + super(msg); + } +} diff --git a/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java index 4bb73957d3..66f008aaee 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -270,8 +270,9 @@ public final class SimplePluginManager implements PluginManager { */ public void registerEvent(Event.Type type, Listener listener, Priority priority, Plugin plugin) { if (!plugin.isEnabled()) { - server.getLogger().warning("Plugin '" + plugin.getDescription().getName() + "' (ver " + plugin.getDescription().getVersion() + ") is registering events before it is enabled. It may be misbehaving and the author needs to fix this."); + throw new IllegalPluginAccessException("Plugin attempted to register " + type + " while not enabled"); } + getEventListeners( type ).add(new RegisteredListener(listener, priority, plugin, type)); } @@ -285,6 +286,10 @@ public final class SimplePluginManager implements PluginManager { * @param plugin Plugin to register */ public void registerEvent(Event.Type type, Listener listener, EventExecutor executor, Priority priority, Plugin plugin) { + if (!plugin.isEnabled()) { + throw new IllegalPluginAccessException("Plugin attempted to register " + type + " while not enabled"); + } + getEventListeners( type ).add(new RegisteredListener(listener, executor, priority, plugin)); }