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
Modifier and TypeFieldDescriptionprotected final boolean
static final Registry.Container
<net.minestom.server.command.builder.arguments.Argument.ArgumentImpl> protected SuggestionType
protected final boolean
-
Constructor Summary
ConstructorDescriptionCreates a new argument withuseRemaining
andallowSpace
sets to false.Creates a new argument withuseRemaining
sets to false.Creates a new argument. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Gets if the argument can contain space.boolean
Maps this argument's output to another result.@Nullable ArgumentCallback
Gets theArgumentCallback
to check if the argument-specific conditions are validated or not.@Nullable Function
<CommandSender, T> @NotNull String
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
.@Nullable SuggestionCallback
Gets the suggestion callback of the argumentboolean
Gets if the argument has any error callback.int
hashCode()
boolean
Check if the argument has a suggestion.boolean
Gets if this argument is 'optional'.<O> @NotNull Argument
<O> map
(@NotNull BiFunction<CommandSender, T, O> mapper) <O> @NotNull Argument
<O> Maps this argument's output to another result.byte @Nullable []
abstract T
parse
(@NotNull CommandSender sender, @NotNull String input) Parses the given input, and throw anArgumentSyntaxException
if the input cannot be converted toT
static <T> T
parse
(@NotNull CommandSender sender, @NotNull Argument<T> argument) Parses an argument, usinggetId()
as the inputabstract String
parser()
void
setCallback
(@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
(@NotNull SuggestionCallback suggestionCallback) Sets the suggestion callback (for dynamic tab completion) of this argument.@Nullable SuggestionType
boolean
Gets if the argument always use all the remaining characters.
-
Field Details
-
CONTAINER
@Internal public static final Registry.Container<net.minestom.server.command.builder.arguments.Argument.ArgumentImpl> CONTAINER -
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 withuseRemaining
sets 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 withuseRemaining
andallowSpace
sets to false.- Parameters:
id
- the id of the argument, used to retrieve the parsed value
-
-
Method Details
-
parse
@Experimental @NotNull public static <T> T parse(@NotNull @NotNull CommandSender sender, @NotNull @NotNull 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
@NotNull public abstract T parse(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String input) throws ArgumentSyntaxException Parses the given input, and throw anArgumentSyntaxException
if the input cannot be converted toT
- Parameters:
input
- the argument to parse- Returns:
- the parsed argument
- Throws:
ArgumentSyntaxException
- ifvalue
is not valid
-
parser
-
nodeProperties
public byte @Nullable [] 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 theArgumentCallback
to 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
@NotNull public @NotNull Argument<T> setDefaultValue(@Nullable @Nullable Function<CommandSender, T> defaultValue) -
setDefaultValue
Sets the default value supplier of the argument.- Parameters:
defaultValue
- the default argument value- Returns:
- 'this' for chaining
-
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
Maps this argument's output to another result.- Type Parameters:
O
- The type of output expected.- Parameters:
mapper
- The mapper to use (this argument's input = desired output)- Returns:
- A new ArgumentMap that can get this complex object type.
-
map
@Experimental @NotNull public <O> @NotNull Argument<O> map(@NotNull @NotNull BiFunction<CommandSender, T, O> mapper) -
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
public int hashCode()
-