Class WbsCommand

java.lang.Object
wbs.utils.util.plugin.WbsMessenger
wbs.utils.util.commands.WbsCommand
All Implemented Interfaces:
org.bukkit.command.CommandExecutor, org.bukkit.command.TabCompleter, org.bukkit.command.TabExecutor

public abstract class WbsCommand extends WbsMessenger implements org.bukkit.command.TabExecutor
A command executor that is run entirely by the subcommands added to it. Automatically handles the initial command and passes the executor args to the first layer of subcommands. Automatically tabs to the labels (not aliases) of any added subcommands.
  • Constructor Details

    • WbsCommand

      public WbsCommand(WbsPlugin plugin, org.bukkit.command.PluginCommand command)
      Parameters:
      plugin - The WbsPlugin this command should be registered to
      command - The PluginCommand this command represents, as defined in the plugin.yml of the given WbsPlugin
  • Method Details

    • onCommandNoArgs

      public boolean onCommandNoArgs(@NotNull @NotNull org.bukkit.command.CommandSender sender, String label)
      A method that gets run when no arguments are provided. Overrideable, but defaults to a dynamic usage message that lists the subcommands usable by the sender.
      Parameters:
      sender - The sender performing this command
      label - The label they used to get this command
      Returns:
      Whether or not the command was successful
    • getSubcommandLabels

      public List<String> getSubcommandLabels(org.bukkit.command.CommandSender sender)
      Gets a list of all labels for subcommands usable by the given sender
      Parameters:
      sender - The sender to filter by
      Returns:
      The list of labels for subcommands usable by the sender
    • getLabelsString

      public String getLabelsString(org.bukkit.command.CommandSender sender)
      Gets a human readable list of all labels for subcommands usable by the given sender
      Parameters:
      sender - The command sender to filter by
      Returns:
      A human readable list of subcommand labels
    • onCommand

      public final boolean onCommand(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull org.bukkit.command.Command command, @NotNull @NotNull String label, @NotNull @NotNull String[] args)
      Specified by:
      onCommand in interface org.bukkit.command.CommandExecutor
    • runDefaultCommand

      protected final boolean runDefaultCommand(org.bukkit.command.CommandSender sender, String label, String[] args)
    • onTabComplete

      public final List<String> onTabComplete(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull org.bukkit.command.Command command, @NotNull @NotNull String label, @NotNull @NotNull String[] args)
      Specified by:
      onTabComplete in interface org.bukkit.command.TabCompleter
    • setDefaultCommand

      public WbsCommand setDefaultCommand(WbsSubcommand defaultCommand)
      Set the command to run if an invalid argument is passed in as the first argument
      Parameters:
      defaultCommand - The default command
      Returns:
      The same WbsCommand (for chaining)
    • addSubcommand

      public WbsCommand addSubcommand(WbsSubcommand subcommand, String permission)
      Add a subcommand under a given permission
      Parameters:
      subcommand - The subcommand to add
      permission - The permission to automatically set for the subcommand
      Returns:
      The same WbsCommand (for chaining)
    • addSubcommand

      public WbsCommand addSubcommand(WbsSubcommand subcommand)
      Add a subcommand without specifying a permission
      Parameters:
      subcommand - The subcommand to add
      Returns:
      The same WbsCommand (for chaining)