Class CommandArgs

java.lang.Object
net.winmister332.libs.commands.CommandArgs
All Implemented Interfaces:
Iterable<String>

public final class CommandArgs extends Object implements Iterable<String>
Represents the arguments that were passed to the command invoker.
  • Constructor Details

    • CommandArgs

      public CommandArgs(String... arguments)
  • Method Details

    • iterator

      @NotNull public @NotNull Iterator<String> iterator()
      Specified by:
      iterator in interface Iterable<String>
    • count

      public int count()
      The size of the argument array.
      Returns:
      the size of the argument array.
    • size

      public int size()
      The size of the argument array.
      Returns:
      the size of the argument array.
    • isEmpty

      public boolean isEmpty()
      Checks if the length of the argument array is empty.
      Returns:
      True if the argument array is empty.
    • getArgumentAt

      public String getArgumentAt(int position)
      Gets ab argument at the specified position within the argument array. Treat the position index as if it were an array (The first position is actually 0.)
      Parameters:
      position - The array-safe position within the array.
      Returns:
      The string which was at the specified position.
    • getArguments

      public String[] getArguments()
      Gets all the arguments that was passed to a command.
      Returns:
      See Also:
    • isArgumentAtPosition

      public boolean isArgumentAtPosition(int position, String argument)
      Checks if an argument is at the specified position within the argument array.
      Parameters:
      position - The array-safe position.
      argument - The argument/string to check.
      Returns:
    • containsArgument

      public boolean containsArgument(String arg)
      Checks if the specified argument exists anywhere in the argument array.
      Parameters:
      arg - The argument to check.
      Returns:
      True if the argument was found.
    • startsWith

      public boolean startsWith(String arg)
      Checks if the specified argument is at the start (index 0) of the array.
      Parameters:
      arg - The argument to check.
      Returns:
      True if the argument existed at index 0.
    • endsWith

      public boolean endsWith(String arg)
      Checks if the specified argument is at the end of the argument array.
      Parameters:
      arg - The argument to check.
      Returns:
      True if the argument is at the last position in the array.
    • indexOf

      public int indexOf(String arg)
      Gets the index of the specified array if the argument exists anywhere within the argument array.
      Parameters:
      arg - The argument to check.
      Returns:
      The index of the array. -1 if the argument was NOT found in the array.
    • parseArguments

      public static CommandArgs parseArguments(String rawArgs)
      Parse the raw argument string (without command name as that'll just be treated as an argument.
      Parameters:
      rawArgs - The unprocessed arguments.
      Returns:
      An instance of @see CommandArgs which contains the processed arguments.
    • parseArguments

      public static CommandArgs parseArguments(String rawArgs, boolean parseQuotes, boolean ignoreQuotes)
      Parse the raw argument string (without command name as that'll just be treated as an argument.
      Parameters:
      rawArgs - The unprocessed arguments.
      parseQuotes - If true, it tells the CommandArgs class to treat any data within quotes as its own argument.
      ignoreQuotes - If true, it tells the CommandArgs class to ignore innerquotes.
      Returns:
      An instance of @see CommandArgs which contains the processed arguments.