Class CommandArguments

java.lang.Object
dev.jorel.commandapi.executors.CommandArguments

public class CommandArguments extends Object
This class stores the arguments for this command
  • Constructor Details

    • CommandArguments

      public CommandArguments(Object[] args, Map<String,Object> argsMap, String fullInput)
      Constructs a new CommandArguments instance
      Parameters:
      args - The arguments for this command
      argsMap - The arguments for this command mapped to the node names. This is an ordered map
      fullInput - The raw command a player has entered
  • Method Details

    • args

      public Object[] args()
      Returns:
      The complete argument array of this command
    • argsMap

      public Map<String,Object> argsMap()
      Returns:
      An unmodifiable clone of the mapping of node names to argument values
    • count

      public int count()
      Returns:
      The number of arguments in this object
    • 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.
    • getFullInput

      public String getFullInput()
      This returns the raw command string a player has entered
      Returns:
      The raw command string a player has entered
    • getOrDefault

      @Deprecated(since="9.0.1", forRemoval=true) public Object getOrDefault(int index, Object defaultValue)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This method has been deprecated! Please use getOptional(int)
      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

      @Deprecated(since="9.0.1", forRemoval=true) public Object getOrDefault(String nodeName, Object defaultValue)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This method has been deprecated! Please use getOptional(String)
      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

      @Deprecated(since="9.0.1", forRemoval=true) public Object getOrDefault(int index, Supplier<?> defaultValue)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This method has been deprecated! Please use getOptional(int)
      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

      @Deprecated(since="9.0.1", forRemoval=true) public Object getOrDefault(String nodeName, Supplier<?> defaultValue)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This method has been deprecated! Please use getOptional(String)
      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
    • 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

      @Deprecated(since="9.0.1", forRemoval=true) public <T> T getOrDefaultUnchecked(int index, T defaultValue)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This method has been deprecated! Please use getOptionalUnchecked(int)
      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

      @Deprecated(since="9.0.1", forRemoval=true) public <T> T getOrDefaultUnchecked(String nodeName, T defaultValue)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This method has been deprecated! Please use getOptionalUnchecked(String)
      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

      @Deprecated(since="9.0.1", forRemoval=true) public <T> T getOrDefaultUnchecked(int index, Supplier<T> defaultValue)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This method has been deprecated! Please use getOptionalUnchecked(int)
      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

      @Deprecated(since="9.0.1", forRemoval=true) public <T> T getOrDefaultUnchecked(String nodeName, Supplier<T> defaultValue)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This method has been deprecated! Please use getOptionalUnchecked(String)
      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