Contents
- Description
- Nested Class Summary
- Field Summary
- Method Summary
- Field Details
- Method Details
- setOwner(CommandOwner)
- getPermissionGroups()
- getPermissionGroupsRecursive()
- putRecursivePermissionGroups(Map)
- setAllowsExtraArguments(boolean)
- matches(String, String, int)
- completeRegistration()
- requirePermission(String)
- requirePermission(PermissionQuery)
- requireNoPermission()
- getFullyQualifiedName()
- countParents()
- addAliases(String...)
- addSubCommand(AbstractCommand)
- addUsageVariant(AbstractCommand)
- acceptCall(CommandSender, ParserContext, ParseResult)
- hasPermission(CommandSender)
- getUsageString(CommandSender)
- getUsageShort(CommandSender, boolean)
- withRequiredArg(String, String, ArgumentType)
- withRequiredArg(String, String, ArgWrapper)
- withListRequiredArg(String, String, ArgumentType)
- withDefaultArg(String, String, ArgumentType, D, String)
- withDefaultArg(String, String, ArgWrapper, D, String)
- withListDefaultArg(String, String, ArgumentType, List, String)
- withOptionalArg(String, String, ArgumentType)
- withOptionalArg(String, String, ArgWrapper)
- withListOptionalArg(String, String, ArgumentType)
- withFlagArg(String, String)
- isVariant()
- getName()
- getAliases()
- getDescription()
- getOwner()
- getPermission()
- getSubCommands()
- getSubCommand(String)
- getRequiredArguments()
- getOptionalArguments()
- getOptionalArgument(String)
- getVariantCommands()
- getVariantByArgCount(int)
- getSuggestionOverrides()
- hasBeenRegistered()
Class AbstractCommand
java.lang.Object
com.hypixel.hytale.server.core.command.system.AbstractCommand
- Direct Known Subclasses:
AbstractAsyncCommand, CommandBase, NPCDebugCommand.PresetsCommand
An abstract class that represents a command in the command system.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String[]An empty string array constant.static final HytaleLoggerThe logger for this class. -
Method Summary
Modifier and TypeMethodDescriptionacceptCall(CommandSender sender, ParserContext parserContext, ParseResult parseResult) Executes a subcommand, variant, or itself, after accepting aParserContextfrom theTokenizerand converting that raw data into aCommandContextthat the executing command can use.voidaddAliases(String... aliases) Add aliases (alternative names) that can be used in place of the original command name.voidaddSubCommand(AbstractCommand command) Add a subcommand, which is a nested, named command.voidaddUsageVariant(AbstractCommand command) Add a subcommand that has the same command name, but that has a different (and unique to other variants) amount of required arguments.voidHandles the initialization of various systems that require the command to be in a state where it should not be modified further in the future.intRecursively counts how many parents this command has.The fully qualified name of a command is the name of the command, plus all the parent command names before it that you would use to call it ex: "time set".getName()AbstractOptionalArg<?, ?> getOptionalArgument(String nameOrAbbreviation) Resolves an optional argument by the name, alias, or unambiguous abbreviation the user typed after--, the same way execution resolves it.Map<String, AbstractOptionalArg<?, ?>> getOwner()List<RequiredArg<?>> getSubCommand(String name) Resolves a subcommand by name, falling back to subcommand aliases.getUsageShort(CommandSender sender, boolean fullyQualify) Return a near-one-liner, showcasing how to use the command.getUsageString(CommandSender sender) Return the full help text that displays the command and all its parametersgetVariantByArgCount(int requiredArgCount) booleanbooleanhasPermission(CommandSender sender) Determines whether the givenCommandSenderhas permission to execute this command.booleanCalled to check if this command or any of its subcommands/variants match the search string.voidputRecursivePermissionGroups(Map<String, Set<String>> permissionsByGroup) Called to populate the given map with permission groups and their associated permissions.voidDeclares that anyone may run this command.voidrequirePermission(PermissionQuery permission) Set the permission required to execute this command.voidrequirePermission(String permission) Set the permission string required to execute this command.voidsetAllowsExtraArguments(boolean allowsExtraArguments) Set whether this command allows additional arguments beyond the required ones.voidsetOwner(CommandOwner owner) Called to set the owner of this command, and it's sub-commands and variants.<W extends WrappedArg<D>, D>
WwithDefaultArg(String name, String description, ArgWrapper<W, D> wrapper, D defaultValue, String defaultValueDescription) Add an optional argument that will default to a value if not specified or if it is specified without a value.<D> DefaultArg<D> withDefaultArg(String name, String description, ArgumentType<D> argType, D defaultValue, String defaultValueDescription) Add an optional argument that will default to a value if not specified or if it is specified without a value.withFlagArg(String name, String description) Add a flag argument that, when specified on the command is true, and when not specified on the command is false.<D> DefaultArg<List<D>> withListDefaultArg(String name, String description, ArgumentType<D> argType, List<D> defaultValue, String defaultValueDescription) Add an optional argument that will default to a value if not specified or if it is specified without a value.<D> OptionalArg<List<D>> withListOptionalArg(String name, String description, ArgumentType<D> argType) Add a required-value optional argument that is optional to be specified on a command, however, when specified, it must provide a value (ex: "--option=value").<D> RequiredArg<List<D>> withListRequiredArg(String name, String description, ArgumentType<D> argType) Add an argument that is required to be specified at the beginning of a command.<W extends WrappedArg<D>, D>
WwithOptionalArg(String name, String description, ArgWrapper<W, D> wrapper) Add a required-value optional argument that is optional to be specified on a command, however, when specified, it must provide a value (ex: "--option=value").<D> OptionalArg<D> withOptionalArg(String name, String description, ArgumentType<D> argType) Add a required-value optional argument that is optional to be specified on a command, however, when specified, it must provide a value (ex: "--option=value").<W extends WrappedArg<D>, D>
WwithRequiredArg(String name, String description, ArgWrapper<W, D> wrapper) Add an argument that is required to be specified at the beginning of a command.<D> RequiredArg<D> withRequiredArg(String name, String description, ArgumentType<D> argType) Add an argument that is required to be specified at the beginning of a command.
-
Field Details
-
LOGGER
The logger for this class. -
EMPTY_STRING_ARRAY
An empty string array constant.
-
-
Method Details
-
setOwner
Called to set the owner of this command, and it's sub-commands and variants.- Parameters:
owner- owning system or plugin.
-
getPermissionGroups
-
getPermissionGroupsRecursive
-
putRecursivePermissionGroups
-
setAllowsExtraArguments
public void setAllowsExtraArguments(boolean allowsExtraArguments) Set whether this command allows additional arguments beyond the required ones.When true, the command will accept at least the required number of parameters, but may accept more. This is useful for commands like /su that need to capture the rest of the command string.
- Parameters:
allowsExtraArguments- true to allow extra arguments, false otherwise
-
matches
@Nonnull public MatchResult matches(@Nonnull String language, @Nonnull String search, int termDepth) Called to check if this command or any of its subcommands/variants match the search string.- Parameters:
language- The language to use for translations.search- The search string.termDepth- The depth of the search term.- Returns:
- a
MatchResultrepresenting the result of the match.
-
completeRegistration
Handles the initialization of various systems that require the command to be in a state where it should not be modified further in the future.- Throws:
GeneralCommandException- if validation of default arguments failed.
-
requirePermission
Set the permission string required to execute this command.- Parameters:
permission- the permission string required to execute this command.
-
requirePermission
Set the permission required to execute this command.- Parameters:
permission- the lookup for the permission required to execute this command.
-
requireNoPermission
public void requireNoPermission()Declares that anyone may run this command.A command that says nothing is given a permission of its own, so this is the only way to have one that everyone can run. Say it for a command that hands out the first permission on a server, or one that guards itself by some other means, and say why.
-
getFullyQualifiedName
The fully qualified name of a command is the name of the command, plus all the parent command names before it that you would use to call it ex: "time set".- Returns:
- the fully qualified name of this command.
-
countParents
public int countParents()Recursively counts how many parents this command has.- Returns:
- the amount of parents.
-
addAliases
Add aliases (alternative names) that can be used in place of the original command name. These do not overwrite the original, they can be used in addition to the original command name.- Parameters:
aliases- the aliases (alternative names) that you want to add.
-
addSubCommand
Add a subcommand, which is a nested, named command.An example of a subcommand could be "/warp list" where "list" is the subcommand.
- Parameters:
command- the subcommand, where name must not benull.
-
addUsageVariant
Add a subcommand that has the same command name, but that has a different (and unique to other variants) amount of required arguments. In programming terms, it's an overloaded method.- Parameters:
command- TheAbstractCommandto be executed when its number of required args is met.
-
acceptCall
@Nullable public CompletableFuture<Void> acceptCall(@Nonnull CommandSender sender, @Nonnull ParserContext parserContext, @Nonnull ParseResult parseResult) Executes a subcommand, variant, or itself, after accepting aParserContextfrom theTokenizerand converting that raw data into aCommandContextthat the executing command can use.- Parameters:
sender- TheCommandSenderthat sent the initial command.parserContext- AParserContextcreated from theTokenizer.parseResult- The non-failed parse result that will store error data occurring during the command.- Returns:
- A
CompletableFuture<Void>to be run asynchronously, or null.
-
hasPermission
Determines whether the givenCommandSenderhas permission to execute this command.- Parameters:
sender- The sender to check permission for.- Returns:
trueif the sender has permission,falseotherwise.
-
getUsageString
Return the full help text that displays the command and all its parameters- Parameters:
sender- The command sender that sent the command.- Returns:
- the usage message to display.
-
getUsageShort
Return a near-one-liner, showcasing how to use the command.- Parameters:
sender- The command sender that sent the command.fullyQualify- Whether to display the fully qualified name of the command.- Returns:
- The usage message to display.
-
withRequiredArg
@Nonnull public <D> RequiredArg<D> withRequiredArg(@Nonnull String name, @Nonnull String description, @Nonnull ArgumentType<D> argType) Add an argument that is required to be specified at the beginning of a command.- Type Parameters:
D- The data type of the argument.- Parameters:
name- The name of the argument that displays in the usage and help.description- The description that will display in the help message.argType- The type of the argument.- Returns:
- the created and registered arg.
-
withRequiredArg
public <W extends WrappedArg<D>, D> W withRequiredArg(@Nonnull String name, @Nonnull String description, @Nonnull ArgWrapper<W, D> wrapper) Add an argument that is required to be specified at the beginning of a command. This specific method deals withArgWrappers instead ofArgumentTypes, allowing a deeper level of customization for arguments.- Type Parameters:
W- The wrapped arg type.D- The data type of the argument.- Parameters:
name- The name of the argument that displays in the usage and help.description- The description that will display in the help message.wrapper- The wrapper to provide the return type and the argument type.- Returns:
- the wrapped arg.
-
withListRequiredArg
@Nonnull public <D> RequiredArg<List<D>> withListRequiredArg(@Nonnull String name, @Nonnull String description, @Nonnull ArgumentType<D> argType) Add an argument that is required to be specified at the beginning of a command. This specific method allows you to specify multiple values for a single argument.- Type Parameters:
D- The data type of the argument.- Parameters:
name- The name of the argument that displays in the usage and help.description- The description that will display in the help message.argType- The type of the argument.- Returns:
- the created and registered arg.
-
withDefaultArg
@Nonnull public <D> DefaultArg<D> withDefaultArg(String name, String description, ArgumentType<D> argType, @Nullable D defaultValue, String defaultValueDescription) Add an optional argument that will default to a value if not specified or if it is specified without a value.- Type Parameters:
D- The data type of the argument.- Parameters:
name- The name of the argument that displays in the usage and help.description- The description that will display in the help message.argType- The type of the argument.defaultValue- The *nullable* default value.defaultValueDescription- The description of the default value.- Returns:
- the created and registered arg.
-
withDefaultArg
public <W extends WrappedArg<D>, D> W withDefaultArg(@Nonnull String name, @Nonnull String description, @Nonnull ArgWrapper<W, D> wrapper, D defaultValue, @Nonnull String defaultValueDescription) Add an optional argument that will default to a value if not specified or if it is specified without a value. This specific method deals withArgWrappers instead ofArgumentTypes, allowing a deeper level of customization for arguments.- Type Parameters:
W- The wrapped arg type.D- The data type of the argument.- Parameters:
name- The name of the argument that displays in the usage and help.description- The description that will display in the help message.wrapper- The wrapper to provide the return type and the argument type.defaultValue- The *nullable* default value.defaultValueDescription- The description of the default value.- Returns:
- the created and registered arg.
-
withListDefaultArg
@Nonnull public <D> DefaultArg<List<D>> withListDefaultArg(@Nonnull String name, @Nonnull String description, @Nonnull ArgumentType<D> argType, List<D> defaultValue, @Nonnull String defaultValueDescription) Add an optional argument that will default to a value if not specified or if it is specified without a value. This specific method allows you to specify multiple values for a single argument.- Type Parameters:
D- The data type of the argument.- Parameters:
name- The name of the argument that displays in the usage and help.description- The description that will display in the help message.argType- The type of the argument.defaultValue- The *nullable* default value.defaultValueDescription- The description of the default value.- Returns:
- the created and registered arg
-
withOptionalArg
@Nonnull public <D> OptionalArg<D> withOptionalArg(@Nonnull String name, @Nonnull String description, @Nonnull ArgumentType<D> argType) Add a required-value optional argument that is optional to be specified on a command, however, when specified, it must provide a value (ex: "--option=value").- Type Parameters:
D- The data type of the argument.- Parameters:
name- The name of the argument that displays in the usage and help.description- The description that will display in the help message.argType- The type of the argument.- Returns:
- the created and registered arg.
-
withOptionalArg
public <W extends WrappedArg<D>, D> W withOptionalArg(@Nonnull String name, @Nonnull String description, @Nonnull ArgWrapper<W, D> wrapper) Add a required-value optional argument that is optional to be specified on a command, however, when specified, it must provide a value (ex: "--option=value"). This specific method deals withArgWrappers instead ofArgumentTypes, allowing a deeper level of customization for arguments.- Type Parameters:
W- The wrapped arg type.D- The data type of the argument.- Parameters:
name- The name of the argument that displays in the usage and help.description- The description that will display in the help message.wrapper- The wrapper to provide the return type and the argument type.- Returns:
- the created and registered arg.
-
withListOptionalArg
@Nonnull public <D> OptionalArg<List<D>> withListOptionalArg(@Nonnull String name, @Nonnull String description, @Nonnull ArgumentType<D> argType) Add a required-value optional argument that is optional to be specified on a command, however, when specified, it must provide a value (ex: "--option=value"). This specific method allows you to specify multiple values for a single argument.- Type Parameters:
D- The data type of the argument.- Parameters:
name- The name of the argument that displays in the usage and help.description- The description that will display in the help message.argType- The type of the argument.- Returns:
- the created and registered arg.
-
withFlagArg
Add a flag argument that, when specified on the command is true, and when not specified on the command is false. It does not accept values.- Parameters:
name- The name of the argument that displays in the usage and help.description- The description that will display in the help message.- Returns:
- the created and registered arg.
-
isVariant
public boolean isVariant()- Returns:
trueif this command is a variant command,falseotherwise.
-
getName
- Returns:
- the name of the command.
-
getAliases
-
getDescription
- Returns:
- the description of the command.
-
getOwner
- Returns:
- the owner of the command.
-
getPermission
- Returns:
- the permission node required to execute the command.
-
getSubCommands
- Returns:
- the parent command, or null if this command has no parent.
-
getSubCommand
Resolves a subcommand by name, falling back to subcommand aliases. The lookup is case-insensitive.- Parameters:
name- the subcommand name or alias.- Returns:
- the matching subcommand, or
nullif none matches.
-
getRequiredArguments
-
getOptionalArguments
-
getOptionalArgument
Resolves an optional argument by the name, alias, or unambiguous abbreviation the user typed after--, the same way execution resolves it. Returnsnullbefore registration (the abbreviation map is built then) or when nothing matches. -
getVariantCommands
-
getVariantByArgCount
-
getSuggestionOverrides
-
hasBeenRegistered
public boolean hasBeenRegistered()- Returns:
- the parent command, or null if this command has no parent.
-