Class WbsSubcommand

java.lang.Object
wbs.utils.util.plugin.WbsMessenger
wbs.utils.util.commands.WbsSubcommand
Direct Known Subclasses:
WbsCommandNode, WbsErrorsSubcommand, WbsReloadSubcommand

public abstract class WbsSubcommand extends WbsMessenger
A "leaf" of a WbsCommand. WbsSubcommands are called from WbsCommands or WbsCommandNodes to run their command.
  • Constructor Details

    • WbsSubcommand

      public WbsSubcommand(@NotNull @NotNull WbsPlugin plugin, @NotNull @NotNull String label)
      Parameters:
      plugin - The plugin to use for messaging
      label - The label for this subcommand
  • Method Details

    • onCommand

      protected boolean onCommand(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String label, @NotNull @NotNull String[] args)
      Run this subcommand for the given sender, starting at arg[start]. When this is called, the permission has already been checked.
      Parameters:
      sender - The sender that ran the command
      label - The alias used to run this command
      args - The arguments provided
      Returns:
      false if the command failed unexpectedly, true otherwise
    • onCommand

      protected boolean onCommand(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String label, @NotNull @NotNull String[] args, int start)
      Run this subcommand for the given sender, starting at arg[start]. When this is called, the permission has already been checked.
      Parameters:
      sender - The sender that ran the command
      label - The alias used to run this command
      args - The arguments provided
      Returns:
      false if the command failed unexpectedly, true otherwise
    • onCommandCheckPermission

      protected final boolean onCommandCheckPermission(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String label, @NotNull @NotNull String[] args, int start)
      Check this command's permission, and if successful, run the implementing class's onCommand method
      Parameters:
      sender - The sender that ran the command
      label - The alias used to run this command
      args - The arguments provided
      start - The index that was reached before running this command
      Returns:
      false if the command failed unexpectedly, true otherwise
    • sendUsage

      protected final void sendUsage(String usage, org.bukkit.command.CommandSender sender, String label, String[] args)
    • sendUsage

      protected final void sendUsage(String usage, org.bukkit.command.CommandSender sender, String label, String[] args, int count)
    • setPermission

      @NotNull public @NotNull WbsSubcommand setPermission(@NotNull @NotNull String permission)
      Sets the permission needed to use this subcommand
      Parameters:
      permission - The permission that will be needed to use this subcommand
      Returns:
      The same WbsSubcommand (for chaining)
    • getPermission

      @NotNull public @NotNull String getPermission()
      Returns:
      The permission required to use this subcommand
    • addAlias

      public WbsSubcommand addAlias(String alias)
      Add an alternative label to use instead of label. The added alias does not appear in tabbing.
      Parameters:
      alias - A new alias for this subcommand
      Returns:
      The same WbsSubcommand (for chaining)
    • addAliases

      public WbsSubcommand addAliases(String... aliases)
      Add multiple aliases for this subcommand
      Parameters:
      aliases - Any number of Strings that this subcommand can be referenced by
      Returns:
      The same WbsSubcommand (for chaining)
    • setAliases

      public WbsSubcommand setAliases(Set<String> aliases)
      Sets the list of aliases for this subcommand to the provided value, removing all existing ones.
      Parameters:
      aliases - The new aliases to be used for this subcommand.
      Returns:
      The same WbsSubcommand (for chaining)
    • getAliases

      public Collection<String> getAliases()
      Returns a copy of the collection of aliases for this subcommand
      Returns:
      A copy of the collection of aliases
    • isAliased

      public boolean isAliased(String check)
      Check if the given String is an alias of this subcommand
      Parameters:
      check - The String to check
      Returns:
      True if the given String can be used to reference this subcommand, via an alias or the label
    • getLabel

      @NotNull public @NotNull String getLabel()
      Returns:
      The label of this subcommand
    • getTabCompletions

      protected List<String> getTabCompletions(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String label, @NotNull @NotNull String[] args)
    • getTabCompletions

      protected List<String> getTabCompletions(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String label, @NotNull @NotNull String[] args, int start)