diff --git a/api/src/main/java/xyz/srnyx/annoyingapi/command/AnnoyingCommand.java b/api/src/main/java/xyz/srnyx/annoyingapi/command/AnnoyingCommand.java index 8797d33..2a3d5a1 100644 --- a/api/src/main/java/xyz/srnyx/annoyingapi/command/AnnoyingCommand.java +++ b/api/src/main/java/xyz/srnyx/annoyingapi/command/AnnoyingCommand.java @@ -10,6 +10,7 @@ import xyz.srnyx.annoyingapi.AnnoyingMessage; import xyz.srnyx.annoyingapi.AnnoyingPlugin; +import xyz.srnyx.annoyingapi.parents.Annoyable; import xyz.srnyx.annoyingapi.utility.AnnoyingUtility; import java.util.Collection; @@ -23,15 +24,7 @@ /** * Represents a command that can be executed by a player or the console */ -public interface AnnoyingCommand extends TabExecutor { - /** - * The {@link AnnoyingPlugin} that this command belongs to - * - * @return the plugin instance - */ - @NotNull - AnnoyingPlugin getPlugin(); - +public interface AnnoyingCommand extends TabExecutor, Annoyable { /** * {@code OPTIONAL} This is the name of the command *

If not specified, the lowercase class name will be used ({@code Command} will be removed) @@ -97,16 +90,16 @@ default Collection onTabComplete(@NotNull AnnoyingSender sender) { } /** - * Returns whether the command is registered to the {@link #getPlugin()} + * Returns whether the command is registered to the {@link #getAnnoyingPlugin()} * * @return whether the command is registered */ default boolean isRegistered() { - return getPlugin().registeredCommands.contains(this); + return getAnnoyingPlugin().registeredCommands.contains(this); } /** - * Toggles the registration of the command to the {@link #getPlugin()} + * Toggles the registration of the command to the {@link #getAnnoyingPlugin()} * * @param registered whether the command should be registered or unregistered */ @@ -119,27 +112,27 @@ default void setRegistered(boolean registered) { } /** - * Registers the command to the {@link #getPlugin()} + * Registers the command to the {@link #getAnnoyingPlugin()} */ default void register() { if (isRegistered()) return; - final PluginCommand command = getPlugin().getCommand(getName()); + final PluginCommand command = getAnnoyingPlugin().getCommand(getName()); if (command == null) { AnnoyingPlugin.log(Level.WARNING, "&cCommand &4" + getName() + "&c not found in plugin.yml!"); return; } command.setExecutor(this); - getPlugin().registeredCommands.add(this); + getAnnoyingPlugin().registeredCommands.add(this); } /** - * Unregisters the command from the {@link #getPlugin()} + * Unregisters the command from the {@link #getAnnoyingPlugin()} */ default void unregister() { if (!isRegistered()) return; - final PluginCommand command = getPlugin().getCommand(getName()); - if (command != null) command.setExecutor(new DisabledCommand(getPlugin())); - getPlugin().registeredCommands.remove(this); + final PluginCommand command = getAnnoyingPlugin().getCommand(getName()); + if (command != null) command.setExecutor(new DisabledCommand(getAnnoyingPlugin())); + getAnnoyingPlugin().registeredCommands.remove(this); } /** @@ -156,7 +149,7 @@ default void unregister() { */ @Override default boolean onCommand(@NotNull CommandSender cmdSender, @NotNull Command cmd, @NotNull String label, @NotNull String[] args) { - final AnnoyingSender sender = new AnnoyingSender(getPlugin(), cmdSender, cmd, label, args); + final AnnoyingSender sender = new AnnoyingSender(getAnnoyingPlugin(), cmdSender, cmd, label, args); // Permission & player check final String permission = getPermission(); @@ -164,7 +157,7 @@ default boolean onCommand(@NotNull CommandSender cmdSender, @NotNull Command cmd // Argument check if (!getArgsPredicate().test(args)) { - new AnnoyingMessage(getPlugin(), getPlugin().options.messageKeys.invalidArguments).send(sender); + new AnnoyingMessage(getAnnoyingPlugin(), getAnnoyingPlugin().options.messageKeys.invalidArguments).send(sender); return true; } @@ -189,7 +182,7 @@ default List onTabComplete(@NotNull CommandSender cmdSender, @NotNull Co if (permission != null && !cmdSender.hasPermission(permission)) return Collections.emptyList(); // Get suggestions - final Collection suggestions = onTabComplete(new AnnoyingSender(getPlugin(), cmdSender, cmd, label, args)); + final Collection suggestions = onTabComplete(new AnnoyingSender(getAnnoyingPlugin(), cmdSender, cmd, label, args)); if (suggestions == null) return Collections.emptyList(); // Filter suggestions diff --git a/api/src/main/java/xyz/srnyx/annoyingapi/command/DisabledCommand.java b/api/src/main/java/xyz/srnyx/annoyingapi/command/DisabledCommand.java index ee9cf42..e846984 100644 --- a/api/src/main/java/xyz/srnyx/annoyingapi/command/DisabledCommand.java +++ b/api/src/main/java/xyz/srnyx/annoyingapi/command/DisabledCommand.java @@ -30,7 +30,7 @@ public DisabledCommand(@NotNull AnnoyingPlugin plugin) { * @return the plugin instance */ @Override @NotNull - public AnnoyingPlugin getPlugin() { + public AnnoyingPlugin getAnnoyingPlugin() { return plugin; } diff --git a/api/src/main/java/xyz/srnyx/annoyingapi/events/EventHandlers.java b/api/src/main/java/xyz/srnyx/annoyingapi/events/EventHandlers.java index 6996cfb..4c138ac 100644 --- a/api/src/main/java/xyz/srnyx/annoyingapi/events/EventHandlers.java +++ b/api/src/main/java/xyz/srnyx/annoyingapi/events/EventHandlers.java @@ -33,8 +33,8 @@ public EventHandlers(@NotNull AnnoyingPlugin plugin) { this.plugin = plugin; } - @NotNull - public AnnoyingPlugin getPlugin() { + @Override @NotNull + public AnnoyingPlugin getAnnoyingPlugin() { return plugin; } diff --git a/api/src/main/java/xyz/srnyx/annoyingapi/parents/Annoyable.java b/api/src/main/java/xyz/srnyx/annoyingapi/parents/Annoyable.java new file mode 100644 index 0000000..36fd087 --- /dev/null +++ b/api/src/main/java/xyz/srnyx/annoyingapi/parents/Annoyable.java @@ -0,0 +1,16 @@ +package xyz.srnyx.annoyingapi.parents; + +import org.jetbrains.annotations.NotNull; + +import xyz.srnyx.annoyingapi.AnnoyingPlugin; + + +public interface Annoyable { + /** + * The {@link AnnoyingPlugin} instance + * + * @return the plugin instance + */ + @NotNull + AnnoyingPlugin getAnnoyingPlugin(); +} diff --git a/example-plugin/src/main/java/xyz/srnyx/annoyingexample/ExampleCommand.java b/example-plugin/src/main/java/xyz/srnyx/annoyingexample/ExampleCommand.java index c6deccc..1dd121b 100644 --- a/example-plugin/src/main/java/xyz/srnyx/annoyingexample/ExampleCommand.java +++ b/example-plugin/src/main/java/xyz/srnyx/annoyingexample/ExampleCommand.java @@ -32,7 +32,7 @@ public ExampleCommand(@NotNull ExamplePlugin plugin) { } @Override @NotNull - public ExamplePlugin getPlugin() { + public ExamplePlugin getAnnoyingPlugin() { return plugin; } diff --git a/example-plugin/src/main/java/xyz/srnyx/annoyingexample/ExampleListener.java b/example-plugin/src/main/java/xyz/srnyx/annoyingexample/ExampleListener.java index 3e1987c..2223b4e 100644 --- a/example-plugin/src/main/java/xyz/srnyx/annoyingexample/ExampleListener.java +++ b/example-plugin/src/main/java/xyz/srnyx/annoyingexample/ExampleListener.java @@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull; -import xyz.srnyx.annoyingapi.AnnoyingListener; +import xyz.srnyx.annoyingapi.parents.AnnoyingListener; import xyz.srnyx.annoyingapi.AnnoyingMessage; import xyz.srnyx.annoyingapi.events.PlayerDamageByPlayerEvent; import xyz.srnyx.annoyingapi.utility.ItemDataUtility; @@ -33,7 +33,7 @@ public ExampleListener(@NotNull ExamplePlugin plugin) { } @Override @NotNull - public ExamplePlugin getPlugin() { + public ExamplePlugin getAnnoyingPlugin() { return plugin; }