Class ArgumentList

java.lang.Object
com.zetaplugins.zetacore.commands.ArgumentList
All Implemented Interfaces:
Iterable<String>

public class ArgumentList extends Object implements Iterable<String>
Represents a list of command arguments
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the ArgumentList class
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the arguments as a list
    getArg(int index)
    Get the argument at the specified index
    Get the arguments
    boolean
    getBoolean(int index, boolean defaultValue)
    Get a boolean at the specified index
    Get the last argument
    int
    Get the last argument index
    double
    getDouble(int index)
    Get a double at the specified index
    double
    getDouble(int index, double defaultValue)
    Get a double at the specified index, with a default value
    <E extends Enum<E>>
    E
    getEnum(int index, Class<E> enumClass)
    Get an enum at the specified index
    <E extends Enum<E>>
    E
    getEnum(int index, Class<E> enumClass, E defaultValue)
    Get an enum at the specified index, with a default value
    <E extends Enum<E>>
    E
    getEnumIgnoreCase(int index, Class<E> enumClass, E defaultValue)
    Get an enum at the specified index, ignoring case
    int
    getInt(int index)
    Get an integer at the specified index
    int
    getInt(int index, int defaultValue)
    Get an integer at the specified index, with a default value
    int
    getInt(int index, int defaultValue, int min, int max)
    Get an integer at the specified index, with a default value and bounds
    getJoinedString(int startIndex)
    Get the joined string of arguments starting from the specified index with a space seperator
    getJoinedString(int startIndex, String seperator)
    Get the joined string of arguments starting from the specified index
    long
    getLong(int index)
    Get a long at the specified index
    long
    getLong(int index, long defaultValue)
    Get a long at the specified index, with a default value
    getPlayer(int index, Player defaultPlayer, JavaPlugin plugin)
    Get the player at the specified index, with a default value
    getPlayer(int index, JavaPlugin plugin)
    Get the player at the specified index
    getString(int index, String defaultValue)
    Get the argument at the specified index, with a default value
    boolean
    hasArg(int index)
    Get the argument at the specified index
    @NotNull Iterator<String>
     
    int
    Get the number of arguments
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • ArgumentList

      public ArgumentList(String[] args)
      Constructor for the ArgumentList class
      Parameters:
      args - The list of arguments
  • Method Details

    • hasArg

      public boolean hasArg(int index)
      Get the argument at the specified index
      Parameters:
      index - The index of the argument
      Returns:
      The argument at the specified index
    • getArg

      public String getArg(int index)
      Get the argument at the specified index
      Parameters:
      index - The index of the argument
      Returns:
      The argument at the specified index
    • getString

      public String getString(int index, String defaultValue)
      Get the argument at the specified index, with a default value
      Parameters:
      index - The index of the argument
      defaultValue - The default value to return if the argument does not exist
      Returns:
      The argument at the specified index, or the default value
    • getJoinedString

      public String getJoinedString(int startIndex)
      Get the joined string of arguments starting from the specified index with a space seperator
      Parameters:
      startIndex - The index to start joining from
      Returns:
      The joined string of arguments
    • getJoinedString

      public String getJoinedString(int startIndex, String seperator)
      Get the joined string of arguments starting from the specified index
      Parameters:
      startIndex - The index to start joining from
      seperator - The seperator to use between arguments
      Returns:
      The joined string of arguments
    • getPlayer

      public Player getPlayer(int index, JavaPlugin plugin)
      Get the player at the specified index
      Parameters:
      index - The index of the argument
      plugin - The instance of the plugin
      Returns:
      The player at the specified index
    • getPlayer

      public Player getPlayer(int index, Player defaultPlayer, JavaPlugin plugin)
      Get the player at the specified index, with a default value
      Parameters:
      index - The index of the argument
      defaultPlayer - The default player to return if the argument does not exist
      plugin - The instance of the plugin
      Returns:
      The player at the specified index, or the default player
    • getInt

      public int getInt(int index) throws NumberFormatException
      Get an integer at the specified index
      Parameters:
      index - The index of the argument
      Returns:
      The integer at the specified index
      Throws:
      NumberFormatException - When the argument is not an integer
    • getDouble

      public double getDouble(int index) throws NumberFormatException
      Get a double at the specified index
      Parameters:
      index - The index of the argument
      Returns:
      The double at the specified index
      Throws:
      NumberFormatException - When the argument is not a double
    • getLong

      public long getLong(int index) throws NumberFormatException
      Get a long at the specified index
      Parameters:
      index - The index of the argument
      Returns:
      The long at the specified index
      Throws:
      NumberFormatException - When the argument is not a long
    • getInt

      public int getInt(int index, int defaultValue)
      Get an integer at the specified index, with a default value
      Parameters:
      index - The index of the argument
      defaultValue - The default value to return if the argument is not an integer or does not exist
      Returns:
      The integer at the specified index, or the default value
    • getInt

      public int getInt(int index, int defaultValue, int min, int max)
      Get an integer at the specified index, with a default value and bounds
      Parameters:
      index - The index of the argument
      defaultValue - The default value to return if the argument is not an integer or does not exist
      min - The minimum value (inclusive)
      max - The maximum value (inclusive)
      Returns:
      The integer at the specified index, or the default value, clamped to the specified bounds
    • getDouble

      public double getDouble(int index, double defaultValue)
      Get a double at the specified index, with a default value
      Parameters:
      index - The index of the argument
      defaultValue - The default value to return if the argument is not a double or does not exist
      Returns:
      The double at the specified index, or the default value
    • getLong

      public long getLong(int index, long defaultValue)
      Get a long at the specified index, with a default value
      Parameters:
      index - The index of the argument
      defaultValue - The default value to return if the argument is not a long or does not exist
      Returns:
      The long at the specified index, or the default value
    • getBoolean

      public boolean getBoolean(int index, boolean defaultValue)
      Get a boolean at the specified index
      Parameters:
      index - The index of the argument
      Returns:
      The boolean at the specified index
    • getEnum

      public <E extends Enum<E>> E getEnum(int index, Class<E> enumClass)
      Get an enum at the specified index
      Type Parameters:
      E - The type of the enum
      Parameters:
      index - The index of the argument
      enumClass - The class of the enum
      Returns:
      The enum at the specified index
    • getEnum

      public <E extends Enum<E>> E getEnum(int index, Class<E> enumClass, E defaultValue)
      Get an enum at the specified index, with a default value
      Type Parameters:
      E - The type of the enum
      Parameters:
      index - The index of the argument
      enumClass - The class of the enum
      defaultValue - The default value to return if the argument is not a valid enum or does not exist
      Returns:
      The enum at the specified index, or the default value
    • getEnumIgnoreCase

      public <E extends Enum<E>> E getEnumIgnoreCase(int index, Class<E> enumClass, E defaultValue)
      Get an enum at the specified index, ignoring case
      Type Parameters:
      E - The type of the enum
      Parameters:
      index - The index of the argument
      enumClass - The class of the enum
      Returns:
      The enum at the specified index
    • getCurrentArgIndex

      public int getCurrentArgIndex()
      Get the last argument index
      Returns:
      The last argument index or -1 if there are no arguments
    • getCurrentArg

      public String getCurrentArg()
      Get the last argument
      Returns:
      The last argument or null if there are no arguments
    • size

      public int size()
      Get the number of arguments
      Returns:
      The number of arguments
    • getArgs

      public String[] getArgs()
      Get the arguments
      Returns:
      The arguments
    • getAllArgs

      public List<String> getAllArgs()
      Get the arguments as a list
      Returns:
      The arguments as a list
    • iterator

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

      public String toString()
      Overrides:
      toString in class Object