java.lang.Object
net.minestom.server.command.builder.arguments.Argument<T>
Type Parameters:
T - the type of this parsed argument
Direct Known Subclasses:
ArgumentBoolean, ArgumentColor, ArgumentDynamicStringArray, ArgumentDynamicWord, ArgumentEntities, ArgumentItemStack, ArgumentNbtCompoundTag, ArgumentNbtTag, ArgumentNumber, ArgumentRange, ArgumentRegistry, ArgumentRelative, ArgumentString, ArgumentStringArray, ArgumentTime, ArgumentWord

public abstract class Argument<T>
extends java.lang.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.

Here in order, how is parsed an argument: getCorrectionResult(String) to check if the syntax is correct, parse(String) to convert the correct argument and getConditionResult(Object) to verify that the parsed object validate the additional conditions.

  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int SUCCESS  
    static int UNDEFINED_ERROR  
  • Constructor Summary

    Constructors 
    Constructor Description
    Argument​(java.lang.String id)
    Creates a new argument with useRemaining and allowSpace sets to false.
    Argument​(java.lang.String id, boolean allowSpace)
    Creates a new argument with useRemaining sets to false.
    Argument​(java.lang.String id, boolean allowSpace, boolean useRemaining)
    Creates a new argument.
  • Method Summary

    Modifier and Type Method Description
    boolean allowSpace()
    Gets if the argument can contain space.
    ArgumentCallback getCallback()
    Gets the ArgumentCallback to check if the argument-specific conditions are validated or not.
    abstract int getConditionResult​(T value)
    Called after parse(String) meaning that value should already represent a valid representation of the input.
    abstract int getCorrectionResult​(java.lang.String value)
    First method called to check the validity of an input.
    java.lang.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 Arguments.
    boolean hasErrorCallback()
    Gets if the argument has any error callback.
    abstract T parse​(java.lang.String value)
    Called after getCorrectionResult(String) returned SUCCESS.
    void setCallback​(ArgumentCallback callback)
    boolean useRemaining()
    Gets if the argument always use all the remaining characters.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Argument

      public Argument​(@NotNull java.lang.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 java.lang.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 java.lang.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

    • getCorrectionResult

      public abstract int getCorrectionResult​(@NotNull java.lang.String value)
      First method called to check the validity of an input.

      If allowSpace() is enabled, the value will be incremented by the next word until it returns SUCCESS, meaning that you need to be sure to check the inexpensive operations first (eg the number of brackets, the first and last char, etc...).

      Parameters:
      value - The received argument
      Returns:
      the error code or SUCCESS
    • parse

      @NotNull public abstract T parse​(@NotNull java.lang.String value)
      Called after getCorrectionResult(String) returned SUCCESS.

      The correction being correct means that value shouldn't be verified again, you can assume that no exception will occur when converting it to the correct type.

      Parameters:
      value - The correct argument which does not need to be verified again
      Returns:
      The parsed argument
    • getConditionResult

      public abstract int getConditionResult​(@NotNull T value)
      Called after parse(String) meaning that value should already represent a valid representation of the input.

      The condition result has for goal to check the optional conditions that are user configurable (eg min/max values for a number, a specific material for an item, etc...).

      Parameters:
      value - The parsed argument
      Returns:
      the error code or SUCCESS
    • getId

      @NotNull public java.lang.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 Arguments.
      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 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 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