Class Argument<T>
java.lang.Object
net.minestom.server.command.builder.arguments.Argument<T>
- Type Parameters:
T- the type of this parsed argument
- Direct Known Subclasses:
ArgumentBlockState, ArgumentBoolean, ArgumentColor, ArgumentCommand, ArgumentComponent, ArgumentEntity, ArgumentEnum, ArgumentGroup, ArgumentItemStack, ArgumentLiteral, ArgumentLoop, ArgumentNbtCompoundTag, ArgumentNbtTag, ArgumentNumber, ArgumentRange, ArgumentRegistry, ArgumentRelativeBlockPosition, ArgumentRelativeVec2, ArgumentRelativeVec3, ArgumentResource, ArgumentResourceLocation, ArgumentResourceOrTag, ArgumentString, ArgumentStringArray, ArgumentTime, ArgumentUUID, ArgumentWord
An argument is meant to be parsed when added into a
Command's syntax with Command.addSyntax(CommandExecutor, Argument[]).
You can create your own with your own special conditions.
Arguments are parsed using parse(CommandSender, String).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected @Nullable SuggestionTypeprotected final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets if the argument can contain space.booleanMaps this argument's output to another result.Gets theArgumentCallbackto check if the argument-specific conditions are validated or not.getId()Gets the ID of the argument, showed in-game above the chat bar and used to retrieve the data when the command is parsed inCommandContext.Gets the suggestion callback of the argumentbooleanGets if the argument has any error callback.inthashCode()booleanCheck if the argument has a suggestion.booleanGets if this argument is 'optional'.<O> Argument<O> map(BiFunction<CommandSender, T, O> mapper) <O> Argument<O> Maps this argument's output to another result.byte @Nullable []abstract Tparse(CommandSender sender, String input) Parses the given input, and throw anArgumentSyntaxExceptionif the input cannot be converted toTstatic <T> Tparse(CommandSender sender, Argument<T> argument) Parses an argument, usinggetId()as the inputabstract ArgumentParserTypeparser()voidsetCallback(@Nullable ArgumentCallback callback) Sets theArgumentCallback.setDefaultValue(@Nullable Function<CommandSender, T> defaultValue) setDefaultValue(@Nullable Supplier<T> defaultValue) Sets the default value supplier of the argument.setDefaultValue(T defaultValue) Sets the default value supplier of the argument.setSuggestionCallback(SuggestionCallback suggestionCallback) Sets the suggestion callback (for dynamic tab completion) of this argument.booleanGets if the argument always use all the remaining characters.
-
Field Details
-
allowSpace
protected final boolean allowSpace -
useRemaining
protected final boolean useRemaining -
suggestionType
-
-
Constructor Details
-
Argument
Creates a new argument.- Parameters:
id- the id of the argument, used to retrieve the parsed valueallowSpace- true if the argument can/should have spaces in ituseRemaining- true if the argument will always take the rest of the command arguments
-
Argument
Creates a new argument withuseRemainingsets to false.- Parameters:
id- the id of the argument, used to retrieve the parsed valueallowSpace- true if the argument can/should have spaces in it
-
Argument
Creates a new argument withuseRemainingandallowSpacesets to false.- Parameters:
id- the id of the argument, used to retrieve the parsed value
-
-
Method Details
-
parse
public static <T> T parse(CommandSender sender, Argument<T> argument) throws ArgumentSyntaxException Parses an argument, usinggetId()as the input- Type Parameters:
T- the result type- Parameters:
argument- the argument, with the input as id- Returns:
- the parsed result
- Throws:
ArgumentSyntaxException- if the argument cannot be parsed due to a fault input (argument id)
-
parse
Parses the given input, and throw anArgumentSyntaxExceptionif the input cannot be converted toT- Parameters:
input- the argument to parse- Returns:
- the parsed argument
- Throws:
ArgumentSyntaxException- ifvalueis not valid
-
parser
-
nodeProperties
-
suggestionType
-
getId
Gets the ID of the argument, showed in-game above the chat bar and used to retrieve the data when the command is parsed inCommandContext.- Returns:
- the argument id
-
allowSpace
public boolean allowSpace()Gets if the argument can contain space.- Returns:
- true if the argument allows space, false otherwise
-
useRemaining
public boolean useRemaining()Gets if the argument always use all the remaining characters.ex: /help I am a test - will always give you "I am a test" if the first and single argument does use the remaining.
- Returns:
- true if the argument use all the remaining characters, false otherwise
-
getCallback
Gets theArgumentCallbackto check if the argument-specific conditions are validated or not.- Returns:
- the argument callback, null if not any
-
setCallback
Sets theArgumentCallback.- Parameters:
callback- the argument callback, null to do not have one
-
hasErrorCallback
public boolean hasErrorCallback()Gets if the argument has any error callback.- Returns:
- true if the argument has an error callback, false otherwise
-
isOptional
public boolean isOptional()Gets if this argument is 'optional'.Optional means that this argument can be put at the end of a syntax and obtains a default value (
getDefaultValue()).- Returns:
- true if this argument is considered optional
-
getDefaultValue
-
setDefaultValue
Sets the default value supplier of the argument.A non-null value means that the argument can be put at the end of a syntax to act as an optional one.
- Parameters:
defaultValue- the default argument value, null to make the argument non-optional- Returns:
- 'this' for chaining
-
setDefaultValue
-
setDefaultValue
-
getSuggestionCallback
Gets the suggestion callback of the argument- Returns:
- the suggestion callback of the argument, null if it doesn't exist
- See Also:
-
setSuggestionCallback
Sets the suggestion callback (for dynamic tab completion) of this argument.Note: This will not automatically filter arguments by user input.
- Parameters:
suggestionCallback- The suggestion callback to set.- Returns:
- 'this' for chaining
-
hasSuggestion
public boolean hasSuggestion()Check if the argument has a suggestion.- Returns:
- If this argument has a suggestion.
-
map
-
map
-
filter
Maps this argument's output to another result.- Parameters:
predicate- the argument predicate- Returns:
- A new ArgumentMap that filters using this filterer.
-
equals
-
hashCode
-