java.lang.Object
de.eldoria.eldoutilities.commands.command.util.Arguments
All Implemented Interfaces:
Iterable<Input>

public class Arguments extends Object implements Iterable<Input>
  • Method Details

    • create

      public static Arguments create(Plugin plugin, CommandSender sender, String[] args)
      Create a new argument
      Parameters:
      plugin - plugin instance
      args - argument array
      Returns:
      new argument instance
    • assertLength

      public void assertLength(int index) throws CommandException
      Asserts that the commands have at least the required amount of arguments.
      Parameters:
      index - minimal length
      Throws:
      CommandException - when not enough arguments are present.
    • hasArg

      public boolean hasArg(int index)
      Checks if enough arguments are present
      Parameters:
      index - minimal length
      Returns:
      true if enough arguments are present
    • size

      public int size()
      Size of the arguments.
      Returns:
      the amount of arguments
    • sizeIs

      public boolean sizeIs(int i)
      Size of the arguments.
      Returns:
      the amount of arguments
    • isEmpty

      public boolean isEmpty()
      Checks if no arguments are present
      Returns:
      true if empty
    • parseQuoted

      public void parseQuoted()
      Parses the arguments as quoted args. This will group arguments in quotes.

      Arguments are not parsed quoted by default.

      Use splitArgs() to revert this change

    • splitArgs

      public void splitArgs()
      Splits the arguments if they were grouped by parseQuoted()
    • get

      public Input get(int index)
    • get

      public Input get(int index, Input def)
    • asString

      @NotNull public @NotNull String asString(int index)
      Get the argument as string
      Parameters:
      index - index of argument
      Returns:
      argument as string
    • asString

      @NotNull public @NotNull String asString(int index, String def)
      Get the argument as string
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      argument as string
    • asString

      @NotNull public @NotNull String asString(int index, Supplier<String> def)
      Get the argument as string
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      argument as string
    • asInt

      public int asInt(int index) throws CommandException
      Get the argument as integer
      Parameters:
      index - index of argument
      Returns:
      index as integer
      Throws:
      CommandException - when the argument is not an integer
    • asInt

      public int asInt(int index, int def) throws CommandException
      Get the argument as integer
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as integer
      Throws:
      CommandException - when the argument is not an integer
    • asInt

      public int asInt(int index, Supplier<Integer> def) throws CommandException
      Get the argument as integer
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as integer
      Throws:
      CommandException - when the argument is not an integer
    • asLong

      public long asLong(int index) throws CommandException
      Parameters:
      index - index of argument
      Returns:
      index as long
      Throws:
      CommandException - when the argument is not a long
    • asLong

      public long asLong(int index, long def) throws CommandException
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as long
      Throws:
      CommandException - when the argument is not a long
    • asLong

      public long asLong(int index, Supplier<Long> def) throws CommandException
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as long
      Throws:
      CommandException - when the argument is not a long
    • asDouble

      public double asDouble(int index) throws CommandException
      Parameters:
      index - index of argument
      Returns:
      index as double
      Throws:
      CommandException - when the argument is not a double
    • asDouble

      public double asDouble(int index, double def) throws CommandException
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as double
      Throws:
      CommandException - when the argument is not a double
    • asDouble

      public double asDouble(int index, Supplier<Double> def) throws CommandException
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as double
      Throws:
      CommandException - when the argument is not a double
    • asBoolean

      public boolean asBoolean(int index) throws CommandException
      Get the argument as a boolean
      Parameters:
      index - index of argument
      Returns:
      index as boolean
      Throws:
      CommandException - when the argument is not a boolean
    • asBoolean

      public boolean asBoolean(int index, boolean def) throws CommandException
      Get the argument as a boolean
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as boolean
      Throws:
      CommandException - when the argument is not a boolean
    • asBoolean

      public boolean asBoolean(int index, Supplier<Boolean> def) throws CommandException
      Get the argument as a boolean
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as boolean
      Throws:
      CommandException - when the argument is not a boolean
    • asBoolean

      public boolean asBoolean(int index, String aTrue, String aFalse, boolean def) throws CommandException
      Get the argument as a boolean
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as boolean
      Throws:
      CommandException - when the argument is not a boolean
    • asBoolean

      public boolean asBoolean(int index, String aTrue, String aFalse, Supplier<Boolean> def) throws CommandException
      Get the argument as a boolean
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as boolean
      Throws:
      CommandException - when the argument is not a boolean
    • asBoolean

      public boolean asBoolean(int index, String aTrue, String aFalse) throws CommandException
      Get the argument as a boolean
      Parameters:
      index - index of argument
      aTrue - value of true
      aFalse - value of false
      Returns:
      index as boolean
      Throws:
      CommandException - when the argument is not a boolean
      IndexOutOfBoundsException - when the index is equal or larger than size()
    • asMaterial

      @NotNull public @NotNull Material asMaterial(int index) throws CommandException
      Get the argument as a material.

      This will send a custom message without listing all possible values.

      Parameters:
      index - index of argument
      Returns:
      index as material
      Throws:
      CommandException - when the argument is not a material
      IndexOutOfBoundsException - when the index is equal or larger than size()
    • asMaterial

      @NotNull public @NotNull Material asMaterial(int index, Material def) throws CommandException
      Get the argument as a material.

      This will send a custom message without listing all possible values.

      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as material
      Throws:
      CommandException - when the argument is not a material
    • asMaterial

      @NotNull public @NotNull Material asMaterial(int index, Supplier<Material> def) throws CommandException
      Get the argument as a material.

      This will send a custom message without listing all possible values.

      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as material
      Throws:
      CommandException - when the argument is not a material
    • asMaterial

      @NotNull public @NotNull Material asMaterial(int index, boolean stripStrings) throws CommandException
      Get the argument as a material.

      This will send a custom message without listing all possible values.

      Parameters:
      index - index of argument
      stripStrings - if true underscores will be removed before checking
      Returns:
      index as material
      Throws:
      CommandException - when the argument is not a material
    • asMaterial

      @NotNull public @NotNull Material asMaterial(int index, boolean stripStrings, Material def) throws CommandException
      Get the argument as a material.

      This will send a custom message without listing all possible values.

      Parameters:
      index - index of argument
      def - returned if the index is not valid
      stripStrings - if true underscores will be removed before checking
      Returns:
      index as material
      Throws:
      CommandException - when the argument is not a material
    • asMaterial

      @NotNull public @NotNull Material asMaterial(int index, boolean stripStrings, Supplier<Material> def) throws CommandException
      Get the argument as a material.

      This will send a custom message without listing all possible values.

      Parameters:
      index - index of argument
      def - returned if the index is not valid
      stripStrings - if true underscores will be removed before checking
      Returns:
      index as material
      Throws:
      CommandException - when the argument is not a material
    • asEnum

      @NotNull public <T extends Enum<T>> T asEnum(int index, Class<T> clazz) throws CommandException
      Get the argument as an enum
      Type Parameters:
      T - type of enum
      Parameters:
      index - index of argument
      clazz - enum clazz to parse
      Returns:
      index as enum value
      Throws:
      CommandException - When the string could not be parsed to an enum
    • asEnum

      @NotNull public <T extends Enum<T>> T asEnum(int index, Class<T> clazz, T def) throws CommandException
      Get the argument as an enum
      Type Parameters:
      T - type of enum
      Parameters:
      index - index of argument
      clazz - enum clazz to parse
      def - returned if the index is not valid
      Returns:
      index as enum value
      Throws:
      CommandException - When the string could not be parsed to an enum
    • asEnum

      @NotNull public <T extends Enum<T>> T asEnum(int index, Class<T> clazz, Supplier<T> def) throws CommandException
      Get the argument as an enum
      Type Parameters:
      T - type of enum
      Parameters:
      index - index of argument
      clazz - enum clazz to parse
      def - returned if the index is not valid
      Returns:
      index as enum value
      Throws:
      CommandException - When the string could not be parsed to an enum
    • asEnum

      @NotNull public <T extends Enum<T>> T asEnum(int index, Class<T> clazz, boolean stripStrings) throws CommandException
      Get the argument as an enum
      Type Parameters:
      T - type of enum
      Parameters:
      index - index of argument
      clazz - enum clazz to parse
      stripStrings - if true underscores will be removed before checking
      Returns:
      index as enum value
      Throws:
      CommandException - When the string could not be parsed to an enum
    • asEnum

      @NotNull public <T extends Enum<T>> T asEnum(int index, Class<T> clazz, boolean stripStrings, T def) throws CommandException
      Get the argument as an enum
      Type Parameters:
      T - type of enum
      Parameters:
      index - index of argument
      clazz - enum clazz to parse
      stripStrings - if true underscores will be removed before checking
      def - returned if the index is not valid
      Returns:
      index as enum value
      Throws:
      CommandException - When the string could not be parsed to an enum
    • asEnum

      @NotNull public <T extends Enum<T>> T asEnum(int index, Class<T> clazz, boolean stripStrings, Supplier<T> def) throws CommandException
      Get the argument as an enum
      Type Parameters:
      T - type of enum
      Parameters:
      index - index of argument
      clazz - enum clazz to parse
      stripStrings - if true underscores will be removed before checking
      def - returned if the index is not valid
      Returns:
      index as enum value
      Throws:
      CommandException - When the string could not be parsed to an enum
    • asPlayer

      @NotNull public @NotNull Player asPlayer(int index) throws CommandException
      Get the argument as a player
      Parameters:
      index - index of argument
      Returns:
      index as player
      Throws:
      CommandException - when no player with this name is online
    • asPlayer

      @NotNull public @NotNull Player asPlayer(int index, Player def) throws CommandException
      Get the argument as a player
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as player
      Throws:
      CommandException - when no player with this name is online
    • asPlayer

      @NotNull public @NotNull Player asPlayer(int index, Supplier<Player> def) throws CommandException
      Get the argument as a player
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as player
      Throws:
      CommandException - when no player with this name is online
    • asOfflinePlayer

      @NotNull public @NotNull OfflinePlayer asOfflinePlayer(int index) throws CommandException
      Get the argument as a offline player
      Parameters:
      index - index of argument
      Returns:
      index as offline player
      Throws:
      CommandException - when no player with this name was on this server previously
    • asOfflinePlayer

      @NotNull public @NotNull OfflinePlayer asOfflinePlayer(int index, OfflinePlayer def) throws CommandException
      Get the argument as a offline player
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as offline player
      Throws:
      CommandException - when no player with this name was on this server previously
    • asOfflinePlayer

      @NotNull public @NotNull OfflinePlayer asOfflinePlayer(int index, Supplier<OfflinePlayer> def) throws CommandException
      Get the argument as a offline player
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as offline player
      Throws:
      CommandException - when no player with this name was on this server previously
    • asWorld

      @NotNull public @NotNull World asWorld(int index) throws CommandException
      Get the argument as a world
      Parameters:
      index - index of argument
      Returns:
      index as world
      Throws:
      CommandException - When the string is not the name of a world
    • asWorld

      @NotNull public @NotNull World asWorld(int index, World def) throws CommandException
      Get the argument as a world
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as world
      Throws:
      CommandException - When the string is not the name of a world
    • asWorld

      @NotNull public @NotNull World asWorld(int index, Supplier<World> def) throws CommandException
      Get the argument as a world
      Parameters:
      index - index of argument
      def - returned if the index is not valid
      Returns:
      index as world
      Throws:
      CommandException - When the string is not the name of a world
    • args

      public List<Input> args(int from)
      Get the arguments starting from an index till the end as a list
      Parameters:
      from - the first index to be returned
      Returns:
      a list of arguments
    • join

      public String join()
      Returns a range of arguments as string.
      Returns:
      range as string
    • join

      public String join(int from)
      Returns a range of arguments as string.
      Parameters:
      from - start index (included). Use negative counts to count from the last index.
      Returns:
      range as string
    • join

      public String join(int from, int to)
      Returns a range of arguments as string.
      Parameters:
      from - start index (included). Use negative counts to count from the last index.
      to - end index (excluded). Use negative counts to count from the last index.
      Returns:
      range as string
    • join

      public String join(String delimiter)
      Returns a range of arguments as string.
      Parameters:
      delimiter - delimiter to join
      Returns:
      range as string
    • join

      public String join(String delimiter, int from)
      Returns a range of arguments as string.
      Parameters:
      delimiter - delimiter to join
      from - start index (included). Use negative counts to count from the last index.
      Returns:
      range as string
    • join

      public String join(String delimiter, int from, int to)
      Returns a range of arguments as string.
      Parameters:
      delimiter - delimiter to join
      from - start index (included). Use negative counts to count from the last index.
      to - end index (excluded). Use negative counts to count from the last index.
      Returns:
      range as string
    • args

      public List<Input> args()
      Get the arguments as a list
      Returns:
      arguments as list
    • asArray

      public Input[] asArray()
      Get a copy of the arguments array
      Returns:
      new arguments array
    • args

      public List<Input> args(int from, int to)
      Get the arguments between two indices
      Parameters:
      from - from inclusive
      to - to exclusive
      Returns:
      arguments as list
    • subArguments

      public Arguments subArguments()
      Get the subarguments. This will return all arguments except the first one.
      Returns:
      arguments without the first arguments.
    • subArguments

      public Arguments subArguments(int nesting)
      Get the subarguments. This will return all arguments except the first one.
      Parameters:
      nesting - the amount of arguments which should get removed
      Returns:
      arguments without the first arguments.
    • flags

      public FlagContainer flags()
    • last

      public Input last()
    • sender

      public CommandSender sender()
    • iterator

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

      public Spliterator<Input> spliterator()
      Specified by:
      spliterator in interface Iterable<Input>
    • stream

      public Stream<Input> stream()
    • parallelStream

      public Stream<Input> parallelStream()
    • toString

      public String toString()
      Overrides:
      toString in class Object