Class AbstractCommand
java.lang.Object
net.guizhanss.guizhanlib.minecraft.commands.AbstractCommand
- Direct Known Subclasses:
BaseCommand,SubCommand
This is a node in a command tree.
A node can have 0-1 parent node and 0-n child nodes.
- Author:
- ybw0014
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractCommand(String name, Function<AbstractCommand, String> description, String usage, AbstractCommand... subCommands) Creates a newAbstractCommandinstance, without a parent node.protectedAbstractCommand(AbstractCommand parent, String name, Function<AbstractCommand, String> description, String usage, AbstractCommand... subCommands) Creates a newAbstractCommandinstance. -
Method Summary
Modifier and TypeMethodDescriptionaddSubCommand(AbstractCommand subCommand) Adds aAbstractCommandto this node.addSubCommands(AbstractCommand... subCommands) Adds severalAbstractCommandto this node.getFullUsage(String label) Get the full usage of this node.booleanCheck if this node has a parent node.booleanCheck if this node has child nodes.protected final voidonCommandExecute(CommandSender sender, Command command, String label, String[] args) The general logic of command execution.abstract voidonExecute(CommandSender sender, String[] args) onTab(CommandSender sender, String[] args) onTabCompleteExecute(CommandSender sender, String[] args) The general logic of tab complete execution.protected voidsendHelp(CommandSender sender, String label) Send the help message of this node to theCommandSender.
-
Constructor Details
-
AbstractCommand
protected AbstractCommand(@Nullable AbstractCommand parent, @Nonnull String name, @Nonnull Function<AbstractCommand, String> description, @Nonnull String usage, @Nonnull AbstractCommand... subCommands) Creates a newAbstractCommandinstance.- 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 newAbstractCommandinstance, 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
Adds aAbstractCommandto this node.- Parameters:
subCommand- theAbstractCommandto add.- Returns:
- This
AbstractCommandinstance, for chaining.
-
addSubCommands
Adds severalAbstractCommandto this node.- Parameters:
subCommands- the array ofAbstractCommandto add.- Returns:
- This
AbstractCommandinstance, 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- TheCommandSenderof 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- TheCommandSenderof the command.args- The arguments of the command.
-
getFullUsage
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
Send the help message of this node to theCommandSender.- Parameters:
sender- TheCommandSenderto send the help message to.label- The label of the command.
-
onExecute
-
onTab
-