Class AbstractCommand

java.lang.Object
net.guizhanss.guizhanlib.minecraft.commands.AbstractCommand
Direct Known Subclasses:
BaseCommand, SubCommand

public abstract class AbstractCommand extends Object
This is a node in a command tree. A node can have 0-1 parent node and 0-n child nodes.
Author:
ybw0014
  • Constructor Details

    • AbstractCommand

      protected AbstractCommand(@Nullable AbstractCommand parent, @Nonnull String name, @Nonnull Function<AbstractCommand,String> description, @Nonnull String usage, @Nonnull AbstractCommand... subCommands)
      Creates a new AbstractCommand instance.
      Parameters:
      parent - the parent node.
      name - the name of this node.
      description - the description of this node.
      usage - the usage of this node.
      subCommands - the sub-commands of this node.
    • AbstractCommand

      @ParametersAreNonnullByDefault protected AbstractCommand(String name, Function<AbstractCommand,String> description, String usage, AbstractCommand... subCommands)
      Creates a new AbstractCommand instance, without a parent node.
      Parameters:
      name - the name of this node.
      description - the description of this node.
      usage - the usage of this node.
      subCommands - the sub-commands of this node.
  • Method Details

    • addSubCommand

      @Nonnull public AbstractCommand addSubCommand(@Nonnull AbstractCommand subCommand)
      Adds a AbstractCommand to this node.
      Parameters:
      subCommand - the AbstractCommand to add.
      Returns:
      This AbstractCommand instance, for chaining.
    • addSubCommands

      @Nonnull public AbstractCommand addSubCommands(@Nonnull AbstractCommand... subCommands)
      Adds several AbstractCommand to this node.
      Parameters:
      subCommands - the array of AbstractCommand to add.
      Returns:
      This AbstractCommand instance, for chaining.
    • hasParent

      public boolean hasParent()
      Check if this node has a parent node.
      Returns:
      Whether this node has a parent node.
    • hasSubCommands

      public boolean hasSubCommands()
      Check if this node has child nodes.
      Returns:
      Whether this node has child nodes.
    • onCommandExecute

      @ParametersAreNonnullByDefault protected final void onCommandExecute(CommandSender sender, Command command, String label, String[] args)
      The general logic of command execution. This does not contain the real logic of the command.
      Parameters:
      sender - The CommandSender of the command.
      args - The arguments of the command.
    • onTabCompleteExecute

      @Nullable @ParametersAreNonnullByDefault protected final List<String> onTabCompleteExecute(CommandSender sender, String[] args)
      The general logic of tab complete execution. This does not contain the real logic of the command.
      Parameters:
      sender - The CommandSender of the command.
      args - The arguments of the command.
    • getFullUsage

      @Nonnull public String getFullUsage(String label)
      Get the full usage of this node.

      Example: /command subcommand <arg1> [arg2]

      Parameters:
      label - The label of the command.
      Returns:
      The full usage of this node.
    • sendHelp

      @ParametersAreNonnullByDefault protected void sendHelp(CommandSender sender, String label)
      Send the help message of this node to the CommandSender.
      Parameters:
      sender - The CommandSender to send the help message to.
      label - The label of the command.
    • onExecute

      @ParametersAreNonnullByDefault public abstract void onExecute(CommandSender sender, String[] args)
    • onTab

      @ParametersAreNonnullByDefault public List<String> onTab(CommandSender sender, String[] args)