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

public abstract class Argument<T> extends Object
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 Details

    • allowSpace

      protected final boolean allowSpace
    • useRemaining

      protected final boolean useRemaining
    • suggestionType

      protected SuggestionType suggestionType
  • Constructor Details

    • Argument

      public Argument(@NotNull @NotNull String id, boolean allowSpace, boolean useRemaining)
      Creates a new argument.
      Parameters:
      id - the id of the argument, used to retrieve the parsed value
      allowSpace - true if the argument can/should have spaces in it
      useRemaining - true if the argument will always take the rest of the command arguments
    • Argument

      public Argument(@NotNull @NotNull String id, boolean allowSpace)
      Creates a new argument with useRemaining sets to false.
      Parameters:
      id - the id of the argument, used to retrieve the parsed value
      allowSpace - true if the argument can/should have spaces in it
    • Argument

      public Argument(@NotNull @NotNull String id)
      Creates a new argument with useRemaining and allowSpace sets to false.
      Parameters:
      id - the id of the argument, used to retrieve the parsed value
  • Method Details

    • parse

      @NotNull public static <T> T parse(@NotNull @NotNull CommandSender sender, @NotNull @NotNull Argument<T> argument) throws ArgumentSyntaxException
      Parses an argument, using getId() 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 an ArgumentSyntaxException if the input cannot be converted to T
      Parameters:
      input - the argument to parse
      Returns:
      the parsed argument
      Throws:
      ArgumentSyntaxException - if value is not valid
    • parser

      public abstract ArgumentParserType parser()
    • nodeProperties

      public byte @Nullable [] nodeProperties()
    • suggestionType

      @Nullable public @Nullable SuggestionType suggestionType()
    • getId

      @NotNull public @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 in CommandContext.
      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

      @Nullable public @Nullable ArgumentCallback getCallback()
      Gets the ArgumentCallback to check if the argument-specific conditions are validated or not.
      Returns:
      the argument callback, null if not any
    • setCallback

      public void setCallback(@Nullable @Nullable ArgumentCallback callback)
      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

      @Nullable public @Nullable Function<CommandSender,T> getDefaultValue()
    • setDefaultValue

      @NotNull public @NotNull Argument<T> setDefaultValue(@Nullable @Nullable Supplier<T> defaultValue)
      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

      @NotNull public @NotNull Argument<T> setDefaultValue(@NotNull T defaultValue)
      Sets the default value supplier of the argument.
      Parameters:
      defaultValue - the default argument value
      Returns:
      'this' for chaining
    • getSuggestionCallback

      @Nullable public @Nullable SuggestionCallback getSuggestionCallback()
      Gets the suggestion callback of the argument
      Returns:
      the suggestion callback of the argument, null if it doesn't exist
      See Also:
    • setSuggestionCallback

      public Argument<T> setSuggestionCallback(@NotNull @NotNull SuggestionCallback suggestionCallback)
      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

      @NotNull public <O> @NotNull Argument<O> map(@NotNull @NotNull Function<T,O> mapper)
      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

      @NotNull public <O> @NotNull Argument<O> map(@NotNull @NotNull BiFunction<CommandSender,T,O> mapper)
    • filter

      @Experimental @NotNull public @NotNull Argument<T> filter(@NotNull @NotNull Predicate<T> predicate)
      Maps this argument's output to another result.
      Parameters:
      predicate - the argument predicate
      Returns:
      A new ArgumentMap that filters using this filterer.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object