Record Class CommandArguments

java.lang.Object
java.lang.Record
dev.jorel.commandapi.executors.CommandArguments
Record Components:
args - The arguments for this command
argsMap - The arguments for this command mapped to their node names. This is an ordered map
rawArgs - The raw arguments for this command.
rawArgsMap - The raw arguments for this command mapped to their node names. This is an ordered map
fullInput - The command string a player has entered (including the /)

public record CommandArguments(Object[] args, Map<String,Object> argsMap, String[] rawArgs, Map<String,String> rawArgsMap, String fullInput) extends Record
This class stores the arguments for this command
  • Constructor Details

    • CommandArguments

      public CommandArguments(Object[] args, Map<String,Object> argsMap, String[] rawArgs, Map<String,String> rawArgsMap, String fullInput)
      Creates an instance of a CommandArguments record class.
      Parameters:
      args - the value for the args record component
      argsMap - the value for the argsMap record component
      rawArgs - the value for the rawArgs record component
      rawArgsMap - the value for the rawArgsMap record component
      fullInput - the value for the fullInput record component
  • Method Details

    • argsMap

      public Map<String,Object> argsMap()
      Returns the value of the argsMap record component.
      Returns:
      the value of the argsMap record component
    • rawArgsMap

      public Map<String,String> rawArgsMap()
      Returns the value of the rawArgsMap record component.
      Returns:
      the value of the rawArgsMap record component
    • count

      public int count()
      Returns:
      The number of arguments for this command
    • get

      @Nullable public Object get(int index)
      Returns an argument by its position
      Parameters:
      index - The position of this argument
      Returns:
      An argument which is placed at the given index, or null if the provided index does not point to an argument.
    • get

      @Nullable public Object get(String nodeName)
      Returns an argument by its node name
      Parameters:
      nodeName - The node name of this argument. This was set when initializing an argument
      Returns:
      An argument which has the given node name. Can be null if nodeName was not found.
    • getOrDefault

      public Object getOrDefault(int index, Object defaultValue)
      Returns an argument by its index
      Parameters:
      index - The position of this argument
      defaultValue - The Object returned if the argument is not existent
      Returns:
      An argument which is placed at the given index, or the provided default value
    • getOrDefault

      public Object getOrDefault(String nodeName, Object defaultValue)
      Returns an argument by its node name
      Parameters:
      nodeName - The node name of this argument. This was set when initializing an argument
      defaultValue - The Object returned if the argument was not found.
      Returns:
      The argument with the specified node name or the provided default value
    • getOrDefault

      public Object getOrDefault(int index, Supplier<?> defaultValue)
      Returns an argument by its index
      Parameters:
      index - The position of this argument
      defaultValue - The Object returned if the argument is not existent
      Returns:
      An argument which is placed at the given index, or the provided default value
    • getOrDefault

      public Object getOrDefault(String nodeName, Supplier<?> defaultValue)
      Returns an argument by its node name
      Parameters:
      nodeName - The node name of this argument. This was set when initializing an argument
      defaultValue - The Object returned if the argument was not found.
      Returns:
      The argument with the specified node name or the provided default value
    • getOptional

      public Optional<Object> getOptional(int index)
      Returns an Optional holding the argument by its index
      Parameters:
      index - The position of this argument
      Returns:
      An optional holding the argument which is placed at the given index, or an empty optional if index is invalid
    • getOptional

      public Optional<Object> getOptional(String nodeName)
      Returns an argument by its node name
      Parameters:
      nodeName - The node name of this argument. This was set when initializing an argument
      Returns:
      An optional holding the argument with the specified node name or an empty optional if the node name was not found
    • getRaw

      @Nullable public String getRaw(int index)
      Returns a raw argument by its position

      A raw argument is the String form of an argument as written in a command. For example take this command:

      /mycommand @e 15.3

      When using this method to access these arguments, @e and 15.3 will be available as Strings and not as a Collection and Double

      Parameters:
      index - The position of this argument
      Returns:
      An argument which is placed at the given index, or null if the provided index does not point to an argument.
    • getRaw

      @Nullable public String getRaw(String nodeName)
      Returns a raw argument by its node name

      A raw argument is the String form of an argument as written in a command. For example take this command:

      /mycommand @e 15.3

      When using this method to access these arguments, @e and 15.3 will be available as Strings and not as a Collection and Double

      Parameters:
      nodeName - The node name of this argument. This was set when initializing an argument
      Returns:
      A raw argument which has the given node name. Can be null if nodeName was not found.
    • getOrDefaultRaw

      public String getOrDefaultRaw(int index, String defaultValue)
      Returns a raw argument by its index

      A raw argument is the String form of an argument as written in a command. For example take this command:

      /mycommand @e 15.3

      When using this method to access these arguments, @e and 15.3 will be available as Strings and not as a Collection and Double

      Parameters:
      index - The position of this argument
      defaultValue - The String returned if the raw argument is not existent
      Returns:
      A raw argument which is placed at the given index, or the provided default value
    • getOrDefaultRaw

      public String getOrDefaultRaw(String nodeName, String defaultValue)
      Returns a raw argument by its node name

      A raw argument is the String form of an argument as written in a command. For example take this command:

      /mycommand @e 15.3

      When using this method to access these arguments, @e and 15.3 will be available as Strings and not as a Collection and Double

      Parameters:
      nodeName - The node name of this argument. This was set when initializing an argument
      defaultValue - The String returned if the raw argument was not found.
      Returns:
      A raw argument with the specified node name or the provided default value
    • getOrDefaultRaw

      public String getOrDefaultRaw(int index, Supplier<String> defaultValue)
      Returns a raw argument by its index

      A raw argument is the String form of an argument as written in a command. For example take this command:

      /mycommand @e 15.3

      When using this method to access these arguments, @e and 15.3 will be available as Strings and not as a Collection and Double

      Parameters:
      index - The position of this argument
      defaultValue - The String returned if the raw argument is not existent
      Returns:
      A raw argument which is placed at the given index, or the provided default value
    • getOrDefaultRaw

      public String getOrDefaultRaw(String nodeName, Supplier<String> defaultValue)
      Returns a raw argument by its node name

      A raw argument is the String form of an argument as written in a command. For example take this command:

      /mycommand @e 15.3

      When using this method to access these arguments, @e and 15.3 will be available as Strings and not as a Collection and Double

      Parameters:
      nodeName - The node name of this raw argument. This was set when initializing an argument
      defaultValue - The String returned if the raw argument was not found.
      Returns:
      A raw argument with the specified node name or the provided default value
    • getRawOptional

      public Optional<String> getRawOptional(int index)
      Returns an Optional holding the raw argument by its index

      A raw argument is the String form of an argument as written in a command. For example take this command:

      /mycommand @e 15.3

      When using this method to access these arguments, @e and 15.3 will be available as Strings and not as a Collection and Double

      Parameters:
      index - The position of this argument
      Returns:
      An optional holding the raw argument which is placed at the given index, or an empty optional if index is invalid
    • getRawOptional

      public Optional<String> getRawOptional(String nodeName)
      Returns an Optional holding the raw argument by its node name

      A raw argument is the String form of an argument as written in a command. For example take this command:

      /mycommand @e 15.3

      When using this method to access these arguments, @e and 15.3 will be available as Strings and not as a Collection and Double

      Parameters:
      nodeName - The node name of this argument. This was set when initializing an argument
      Returns:
      An optional holding the argument with the specified node name or an empty optional if the node name was not found
    • getUnchecked

      @Nullable public <T> T getUnchecked(int index)
      Returns an argument by its position
      Parameters:
      index - The position of this argument
      Returns:
      An argument which is placed at the given index, or null if the provided index does not point to an argument.
    • getUnchecked

      @Nullable public <T> T getUnchecked(String nodeName)
      Returns an argument by its node name
      Parameters:
      nodeName - The node name of this argument. This was set when initializing an argument
      Returns:
      An argument which has the given node name. Can be null if nodeName was not found.
    • getOrDefaultUnchecked

      public <T> T getOrDefaultUnchecked(int index, T defaultValue)
      Returns an argument by its index
      Parameters:
      index - The position of this argument
      defaultValue - The Object returned if the argument is not existent
      Returns:
      An argument which is placed at the given index, or the provided default value
    • getOrDefaultUnchecked

      public <T> T getOrDefaultUnchecked(String nodeName, T defaultValue)
      Returns an argument by its node name
      Parameters:
      nodeName - The node name of this argument. This was set when initializing an argument
      defaultValue - The Object returned if the argument was not found.
      Returns:
      The argument with the specified node name or the provided default value
    • getOrDefaultUnchecked

      public <T> T getOrDefaultUnchecked(int index, Supplier<T> defaultValue)
      Returns an argument by its index
      Parameters:
      index - The position of this argument
      defaultValue - The Object returned if the argument is not existent
      Returns:
      An argument which is placed at the given index, or the provided default value
    • getOrDefaultUnchecked

      public <T> T getOrDefaultUnchecked(String nodeName, Supplier<T> defaultValue)
      Returns an argument by its node name
      Parameters:
      nodeName - The node name of this argument. This was set when initializing an argument
      defaultValue - The Object returned if the argument was not found.
      Returns:
      The argument with the specified node name or the provided default value
    • getOptionalUnchecked

      public <T> Optional<T> getOptionalUnchecked(int index)
      Returns an Optional holding the argument at its index
      Parameters:
      index - The position of this argument
      Returns:
      An optional holding the argument at its index, or an empty optional if the index was invalid
    • getOptionalUnchecked

      public <T> Optional<T> getOptionalUnchecked(String nodeName)
      Returns an Optional holding the argument by its node name
      Parameters:
      nodeName - The node name of this argument. This was set when initializing an argument
      Returns:
      An optional holding the argument with the specified node name, or an empty optional if the index was invalid
    • getByArgument

      @Nullable public <T> T getByArgument(AbstractArgument<T,?,?,?> argumentType)
      Returns an argument purely based on its CommandAPI representation. This also attempts to directly cast the argument to the type represented by AbstractArgument.getPrimitiveType()
      Parameters:
      argumentType - The argument instance used to create the argument
      Returns:
      The argument represented by the CommandAPI argument, or null if the argument was not found.
    • getByArgumentOrDefault

      public <T> T getByArgumentOrDefault(AbstractArgument<T,?,?,?> argumentType, T defaultValue)
      Returns an argument purely based on its CommandAPI representation or a default value if the argument wasn't found.

      If the argument was found, this also attempts to directly cast the argument to the type represented by AbstractArgument.getPrimitiveType()

      Parameters:
      argumentType - The argument instance used to create the argument
      defaultValue - The default value to return if the argument wasn't found
      Returns:
      The argument represented by the CommandAPI argument, or the default value if the argument was not found.
    • getOptionalByArgument

      public <T> Optional<T> getOptionalByArgument(AbstractArgument<T,?,?,?> argumentType)
      Returns an Optional holding the provided argument. This Optional can be empty if the argument was not given when running the command.

      This attempts to directly cast the argument to the type represented by AbstractArgument.getPrimitiveType()

      Parameters:
      argumentType - The argument instance used to create the argument
      Returns:
      An Optional holding the argument, or an empty Optional if the argument was not found.
    • getByClass

      @Nullable public <T> T getByClass(String nodeName, Class<T> argumentType)
      Returns an argument based on its node name. This also attempts to directly cast the argument to the type represented by the argumentType parameter.
      Parameters:
      nodeName - The node name of the argument
      argumentType - The class that represents the argument
      Returns:
      The argument with the given node name, or null if the argument was not found.
    • getByClassOrDefault

      public <T> T getByClassOrDefault(String nodeName, Class<T> argumentType, T defaultValue)
      Returns an argument based on its node name or a default value if the argument wasn't found.

      If the argument was found, this method attempts to directly cast the argument to the type represented by the argumentType parameter.

      Parameters:
      nodeName - The node name of the argument
      argumentType - The class that represents the argument
      defaultValue - The default value to return if the argument wasn't found
      Returns:
      The argument with the given node name, or the default value if the argument was not found.
    • getOptionalByClass

      public <T> Optional<T> getOptionalByClass(String nodeName, Class<T> argumentType)
      Returns an Optional holding the argument with the given node name. This Optional can be empty if the argument was not given when running the command.

      This attempts to directly cast the argument to the type represented by the argumentType parameter.

      Parameters:
      nodeName - The node name of the argument
      argumentType - The class that represents the argument
      Returns:
      An Optional holding the argument, or an empty Optional if the argument was not found.
    • getByClass

      @Nullable public <T> T getByClass(int index, Class<T> argumentType)
      Returns an argument based on its index. This also attempts to directly cast the argument to the type represented by the argumentType parameter.
      Parameters:
      index - The index of the argument
      argumentType - The class that represents the argument
      Returns:
      The argument at the given index, or null if the argument was not found.
    • getByClassOrDefault

      public <T> T getByClassOrDefault(int index, Class<T> argumentType, T defaultValue)
      Returns an argument based on its index or a default value if the argument wasn't found.

      If the argument was found, this method attempts to directly cast the argument to the type represented by the argumentType parameter.

      Parameters:
      index - The index of the argument
      argumentType - The class that represents the argument
      defaultValue - The default value to return if the argument wasn't found
      Returns:
      The argument at the given index, or the default value if the argument was not found.
    • getOptionalByClass

      public <T> Optional<T> getOptionalByClass(int index, Class<T> argumentType)
      Returns an Optional holding the argument at the given index. This Optional can be empty if the argument was not given when running the command.

      This attempts to directly cast the argument to the type represented by the argumentType parameter.

      Parameters:
      index - The index of the argument
      argumentType - The class that represents the argument
      Returns:
      An Optional holding the argument, or an empty Optional if the argument was not found.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • args

      public Object[] args()
      Returns the value of the args record component.
      Returns:
      the value of the args record component
    • rawArgs

      public String[] rawArgs()
      Returns the value of the rawArgs record component.
      Returns:
      the value of the rawArgs record component
    • fullInput

      public String fullInput()
      Returns the value of the fullInput record component.
      Returns:
      the value of the fullInput record component