diff --git a/api/src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java b/api/src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java index dd59436..8c162e6 100644 --- a/api/src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java +++ b/api/src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java @@ -24,6 +24,7 @@ /** * Represents a plugin using the API */ +@SuppressWarnings("EmptyMethod") public class AnnoyingPlugin extends JavaPlugin { /** * Instance of {@link AnnoyingCommandRegister}, used to other plugins' register commands @@ -62,19 +63,10 @@ public AnnoyingPlugin() { */ @Override public final void onLoad() { - // Load messages loadMessages(); - // Custom onLoad load(); } - /** - * Loads the messages.yml file - */ - public void loadMessages() { - messages = new AnnoyingResource(this, options.messagesFileName); - } - /** * Called when the plugin is enabled. *

Do not try to override this method! Override {@link #enable()} instead @@ -145,10 +137,21 @@ public final void onDisable() { disable(); } + /** + * Reloads the plugin ({@link #messages}, etc...). This will not trigger {@link #onLoad()} or {@link #onEnable()} + *

This is not run automatically (such as {@link #onEnable()} and {@link #onDisable()}), it is to be used manually by the plugin itself (ex: in a {@code /reload} command) + *

Do not try to override this method! Override {@link #reload()} instead + * + * @see #reload() + */ + public final void reloadPlugin() { + loadMessages(); + reload(); + } + /** * Called when the plugin is loaded */ - @SuppressWarnings("EmptyMethod") public void load() { // This method is meant to be overridden } @@ -156,7 +159,6 @@ public void load() { /** * Called after dependency checks, start-up messages, and command/listener registration. */ - @SuppressWarnings("EmptyMethod") public void enable() { // This method is meant to be overridden } @@ -164,38 +166,41 @@ public void enable() { /** * Called when the plugin is disabled */ - @SuppressWarnings("EmptyMethod") public void disable() { // This method is meant to be overridden } /** - * Disables the plugin (not the API) + * Called when the plugin is reloaded + * + * @see #reloadPlugin() + */ + public void reload() { + // This method is meant to be overridden + } + + /** + * Loads the messages.yml file to {@link #messages} + */ + public void loadMessages() { + messages = new AnnoyingResource(this, options.messagesFileName); + } + + /** + * Disables the plugin. Unregisters commands/listeners, cancels tasks, and then runs {@link PluginManager#disablePlugin(Plugin)} *

This is not meant to be overriden, only override if you know what you're doing! */ public void disablePlugin() { - // Unregister commands & listeners, cancel tasks, and disable the plugin options.commands.forEach(AnnoyingCommand::unregister); options.listeners.forEach(AnnoyingListener::unregister); Bukkit.getScheduler().cancelTasks(this); Bukkit.getPluginManager().disablePlugin(this); } - /** - * Reloads the plugin (calls {@link PluginManager#disablePlugin(Plugin)} and then {@link PluginManager#enablePlugin(Plugin)}) - *

This is not meant to be overriden, only override if you know what you're doing! - *

This is known to break stuff with the plugin, it's highly unrecommended to use this! - */ - public void reloadPlugin() { - final PluginManager manager = Bukkit.getPluginManager(); - manager.disablePlugin(this); - manager.enablePlugin(this); - } - /** * Logs a message to the console * - * @param level the level of the message + * @param level the level of the message. If {@code null}, {@link Level#INFO} will be used * @param message the message to log */ public void log(@Nullable Level level, @NotNull String message) { @@ -204,12 +209,11 @@ public void log(@Nullable Level level, @NotNull String message) { } /** - * Gets a string from {@link AnnoyingOptions#messagesFileName} with the specified key - *

If the string is not found, it will return the key + * Gets a string from {@link #messages} with the specified key * * @param key the key of the string * - * @return the string + * @return the string, or the {@code key} if {@link #messages} is {@code null} or the string is not found */ @NotNull public String getMessagesString(@NotNull String key) {