Class CommandArguments


  • public final class CommandArguments
    extends java.lang.Object
    Represents a class, containing the actual argument resolving of a command.
    • Constructor Detail

      • CommandArguments

        public CommandArguments​(CommandExecutionContext commandContext,
                                java.util.List<java.lang.String> args)
    • Method Detail

      • nextUnsafe

        @Nullable
        public @Nullable java.lang.String nextUnsafe()
        Gets the next argument while decrementing the size(). This method is unsafe as the method may return null if there are no arguments and the safe alternatives of this method are next() or next(ArgumentResolver). Be careful when using the methods with next in their name!
        Returns:
        a string argument or null
      • next

        public java.util.Optional<java.lang.String> next()
        Gets the next argument while decrementing the size(). Be careful when using the methods with next in their name!
        Returns:
        a optional with string argument if present, a empty optional if not present
      • getArgUnsafe

        @Nullable
        public @Nullable java.lang.String getArgUnsafe​(int arg)
        Gets the specified argument while decrementing the size(). This method is unsafe as the method may return null if there are no arguments and the safe alternative of this method is getArg(int). Be very careful how you use this.
        Parameters:
        arg - the argument you want to get
        Returns:
        the string argument or null
      • getArg

        public java.util.Optional<java.lang.String> getArg​(int arg)
        Gets the specified argument while decrementing the size(). Be very careful how you use this.
        Parameters:
        arg - the argument yiu want to get
        Returns:
        a optional with string argument if present, a empty optional if not present
      • next

        @NotNull
        @CheckReturnValue
        public <T> @NotNull ArgumentOptional<T> next​(@NotNull
                                                     @NotNull ArgumentResolver<T> resolver)
        Resolves the next argument to the specified resolver. The specified method decrements size() and if you run that method like that:
        
         public void execute(CommandExecutionContext context, CommandArguments args) {
             args.next(ArgumentResolvers.INTEGER).ifPresent(number -> {
                 // handling
             }).orElse(failReason -> {
                 // handling
             });
             args.next(ArgumentResolvers.INTEGER).ifPresent(number -> {
                 // handling
             }).orElse(failReason -> {
                 // handling
             });
         }

        The 2nd get will get the next argument after the 1st call so it won't be equal to the first one. That's why 2nd or more arguments should be in the call before to have access to all of the arguments you need. Be careful when using the methods with next in their name!

        Type Parameters:
        T - the type of the argument
        Parameters:
        resolver - the resolver of the argument you want to resolve.
        Returns:
        empty ArgumentOptional if argument not parsed, or the argument parsed is not the type, or the type parsed is null.
      • nextInt

        @NotNull
        @CheckReturnValue
        public @NotNull ArgumentOptional<java.lang.Integer> nextInt()
      • nextString

        @NotNull
        @CheckReturnValue
        public @NotNull ArgumentOptional<java.lang.String> nextString()
      • nextDouble

        @NotNull
        @CheckReturnValue
        public @NotNull ArgumentOptional<java.lang.Double> nextDouble()
      • nextFloat

        @NotNull
        @CheckReturnValue
        public @NotNull ArgumentOptional<java.lang.Float> nextFloat()
      • joinArgumentsSpace

        public java.lang.String joinArgumentsSpace​(int from)
        Joins the specified arguments with space as a delimiter.
        Parameters:
        from - from which argument the joiner should start
        Returns:
        joined string from arguments with space as delimiter
      • joinArguments

        public java.lang.String joinArguments​(int from,
                                              char separator)
        Joins the specified arguments with the character specified.
        Parameters:
        from - from which argument the joiner should start
        separator - the separator used to join the arguments
        Returns:
        joined string from arguments with the separator as delimiter
      • joinArguments

        public java.lang.String joinArguments​(int from,
                                              java.lang.CharSequence separator)
        Joins the specified arguments with the specified characters.
        Parameters:
        from - from which argument the joiner should start
        separator - the characters used to join the arguments
        Returns:
        joined string from arguments with the characters separator as delimiter
      • size

        public int size()
        Returns the count of the specified arguments. This count will decrement whenever a argument was got from any of the methods except joinArguments(int, char)
        Returns:
        specified arguments count
      • getArgsLeft

        @Nullable
        public @Nullable java.lang.String[] getArgsLeft()
        Returns the raw arguments array. If any method in this class containing "next" in his name is being called before this method, this method won't return all of the arguments.

        It is generally preferable to not use this method

        Returns:
        raw arguments left or null if none
      • getArgsLeftList

        @NotNull
        public @NotNull java.util.List<java.lang.String> getArgsLeftList()
        Returns the raw list of arguments left. If any method in this class contains "next" in his name is being called before this method, the list won't have all the arguments.

        It is generally preferable to not use this method

        Returns:
        list of arguments left or empty list if none
      • copy

        @NotNull
        public @NotNull CommandArguments copy()
        Creates a new copy of this command arguments.
        Returns:
        instance copy