public interface IArgConsumer
IArgConsumer
is how ICommand
s read the arguments passed to them. This class has many benefits:
IArgConsumer
} is to let you gradually consume arguments in any way
you'd like. You can change your consumption based on earlier arguments, for subcommands for example.IArgConsumer
} keeps track of the arguments you
consume so that it can throw detailed exceptions whenever something is out of the ordinary. Additionally, if you
need to retrieve an argument after you've already consumed it - look no further than consumed()
!getAs(Class)
. If you need a more powerful way of retrieving data, try out the many
getDatatype...
methods.IArgConsumer
} has many different methods that can
enforce the number of arguments, the type of arguments, and more, throwing different types of
CommandException
s if something seems off. You're recommended to do all validation and store all needed
data in variables BEFORE logging any data to chat via Helper.logDirect(String)
, so that the error
handlers can do their job and log the error to chat.Modifier and Type | Method and Description |
---|---|
ICommandArgument |
consumed() |
java.lang.String |
consumedString() |
IArgConsumer |
copy() |
ICommandArgument |
get()
Gets the next argument and returns it.
|
java.util.LinkedList<ICommandArgument> |
getArgs() |
<T> T |
getAs(java.lang.Class<T> type)
Tries to use a stateless
IArgParser to parse the next argument into the specified class |
<T> T |
getAsOrDefault(java.lang.Class<T> type,
T def)
Tries to use a stateless
IArgParser to parse the next argument into the specified class |
<T> T |
getAsOrNull(java.lang.Class<T> type)
Tries to use a stateless
IArgParser to parse the next argument into the specified class |
java.util.Deque<ICommandArgument> |
getConsumed() |
<T,D extends IDatatypeFor<T>> |
getDatatypeFor(D datatype) |
<T,D extends IDatatypeFor<T>> |
getDatatypeForOrDefault(D datatype,
T def) |
<T,D extends IDatatypeFor<T>> |
getDatatypeForOrNull(D datatype) |
<T,O,D extends IDatatypePost<T,O>> |
getDatatypePost(D datatype,
O original) |
<T,O,D extends IDatatypePost<T,O>> |
getDatatypePostOrDefault(D datatype,
O original,
T _default) |
<T,O,D extends IDatatypePost<T,O>> |
getDatatypePostOrNull(D datatype,
O original) |
<E extends java.lang.Enum<?>> |
getEnum(java.lang.Class<E> enumClass)
Gets an enum value from the enum class with the same name as the next argument's value
|
<E extends java.lang.Enum<?>> |
getEnumOrDefault(java.lang.Class<E> enumClass,
E def)
Gets an enum value from the enum class with the same name as the next argument's value
|
<E extends java.lang.Enum<?>> |
getEnumOrNull(java.lang.Class<E> enumClass)
Gets an enum value from the enum class with the same name as the next argument's value
|
java.lang.String |
getString()
Gets the value of the next argument and returns it.
|
boolean |
has(int num) |
boolean |
hasAny() |
boolean |
hasAtMost(int num) |
boolean |
hasAtMostOne() |
boolean |
hasConsumed() |
boolean |
hasExactly(int num) |
boolean |
hasExactlyOne() |
boolean |
is(java.lang.Class<?> type) |
boolean |
is(java.lang.Class<?> type,
int index) |
ICommandArgument |
peek() |
ICommandArgument |
peek(int index) |
<T> T |
peekAs(java.lang.Class<T> type)
Tries to use a stateless
IArgParser to parse the next argument into the specified class |
<T> T |
peekAs(java.lang.Class<T> type,
int index)
Tries to use a stateless
IArgParser to parse the argument at the specified index into the specified
class |
<T> T |
peekAsOrDefault(java.lang.Class<T> type,
T def)
Tries to use a stateless
IArgParser to parse the next argument into the specified class |
<T> T |
peekAsOrDefault(java.lang.Class<T> type,
T def,
int index)
Tries to use a stateless
IArgParser to parse the argument at the specified index into the specified
class |
<T> T |
peekAsOrNull(java.lang.Class<T> type)
Tries to use a stateless
IArgParser to parse the next argument into the specified class |
<T> T |
peekAsOrNull(java.lang.Class<T> type,
int index)
Tries to use a stateless
IArgParser to parse the argument at the specified index into the specified
class |
<T> T |
peekDatatype(IDatatypeFor<T> datatype) |
<T,O> T |
peekDatatype(IDatatypePost<T,O> datatype) |
<T,O> T |
peekDatatype(IDatatypePost<T,O> datatype,
O original) |
<T,D extends IDatatypeFor<T>> |
peekDatatypeFor(java.lang.Class<D> datatype)
Attempts to get the specified
IDatatypeFor from this ArgConsumer |
<T,D extends IDatatypeFor<T>> |
peekDatatypeForOrDefault(java.lang.Class<D> datatype,
T def)
Attempts to get the specified
IDatatypeFor from this ArgConsumer |
<T,D extends IDatatypeFor<T>> |
peekDatatypeForOrNull(java.lang.Class<D> datatype)
Attempts to get the specified
IDatatypeFor from this ArgConsumer |
<T> T |
peekDatatypeOrNull(IDatatypeFor<T> datatype) |
<T,O> T |
peekDatatypeOrNull(IDatatypePost<T,O> datatype) |
<T,O,D extends IDatatypePost<T,O>> |
peekDatatypePost(D datatype,
O original) |
<T,O,D extends IDatatypePost<T,O>> |
peekDatatypePostOrDefault(D datatype,
O original,
T def) |
<T,O,D extends IDatatypePost<T,O>> |
peekDatatypePostOrNull(D datatype,
O original) |
<E extends java.lang.Enum<?>> |
peekEnum(java.lang.Class<E> enumClass) |
<E extends java.lang.Enum<?>> |
peekEnum(java.lang.Class<E> enumClass,
int index) |
<E extends java.lang.Enum<?>> |
peekEnumOrNull(java.lang.Class<E> enumClass) |
<E extends java.lang.Enum<?>> |
peekEnumOrNull(java.lang.Class<E> enumClass,
int index) |
java.lang.String |
peekString() |
java.lang.String |
peekString(int index) |
java.lang.String |
rawRest()
Returns the "raw rest" of the string.
|
void |
requireExactly(int args) |
void |
requireMax(int max) |
void |
requireMin(int min) |
<T extends IDatatype> |
tabCompleteDatatype(T datatype) |
java.util.LinkedList<ICommandArgument> getArgs()
java.util.Deque<ICommandArgument> getConsumed()
boolean has(int num)
num
- The number of arguments to check fortrue
if there are at least num
arguments left in this IArgConsumer
}hasAny()
,
hasAtMost(int)
,
hasExactly(int)
boolean hasAny()
true
if there is at least 1 argument left in this IArgConsumer
}has(int)
,
hasAtMostOne()
,
hasExactlyOne()
boolean hasAtMost(int num)
num
- The number of arguments to check fortrue
if there are at most num
arguments left in this IArgConsumer
}has(int)
,
hasAtMost(int)
,
hasExactly(int)
boolean hasAtMostOne()
true
if there is at most 1 argument left in this IArgConsumer
}hasAny()
,
hasAtMostOne()
,
hasExactlyOne()
boolean hasExactly(int num)
num
- The number of arguments to check fortrue
if there are exactly num
arguments left in this IArgConsumer
}has(int)
,
hasAtMost(int)
boolean hasExactlyOne()
true
if there is exactly 1 argument left in this IArgConsumer
}hasAny()
,
hasAtMostOne()
ICommandArgument peek(int index) throws CommandNotEnoughArgumentsException
index
- The index to peekindex
in this IArgConsumer
}, with 0 being the next one. This does not
mutate the IArgConsumer
}CommandNotEnoughArgumentsException
- If there is less than index + 1
arguments leftpeek()
,
peekString(int)
,
peekAs(Class, int)
,
get()
ICommandArgument peek() throws CommandNotEnoughArgumentsException
IArgConsumer
}. This does not mutate the IArgConsumer
}CommandNotEnoughArgumentsException
- If there is less than one argument leftpeek(int)
,
peekString()
,
peekAs(Class)
,
get()
boolean is(java.lang.Class<?> type, int index) throws CommandNotEnoughArgumentsException
index
- The index to peektype
- The type to check fortype
would succeed in parsing the next
argumentCommandNotEnoughArgumentsException
- If there is less than index + 1
arguments leftpeek()
,
getAs(Class)
boolean is(java.lang.Class<?> type) throws CommandNotEnoughArgumentsException
type
- The type to check fortype
would succeed in parsing the next
argumentCommandNotEnoughArgumentsException
- If there is less than one argument leftpeek()
,
getAs(Class)
java.lang.String peekString(int index) throws CommandNotEnoughArgumentsException
index
- The index to peekindex
in this IArgConsumer
}, with 0 being the next one
This does not mutate the IArgConsumer
}CommandNotEnoughArgumentsException
- If there is less than index + 1
arguments leftpeek()
,
peekString()
java.lang.String peekString() throws CommandNotEnoughArgumentsException
IArgConsumer
}. This does not mutate the IArgConsumer
}CommandNotEnoughArgumentsException
- If there is less than one argument leftpeekString(int)
,
getString()
<E extends java.lang.Enum<?>> E peekEnum(java.lang.Class<E> enumClass, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException
index
- The index to peekenumClass
- The class to searchjava.util.NoSuchElementException
- If the constant couldn't be foundCommandInvalidTypeException
CommandNotEnoughArgumentsException
peekEnumOrNull(Class)
,
getEnum(Class)
,
ICommandArgument.getEnum(Class)
<E extends java.lang.Enum<?>> E peekEnum(java.lang.Class<E> enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException
enumClass
- The class to searchCommandInvalidTypeException
- If the constant couldn't be foundCommandNotEnoughArgumentsException
peekEnumOrNull(Class)
,
getEnum(Class)
,
ICommandArgument.getEnum(Class)
<E extends java.lang.Enum<?>> E peekEnumOrNull(java.lang.Class<E> enumClass, int index) throws CommandNotEnoughArgumentsException
index
- The index to peekenumClass
- The class to searchCommandNotEnoughArgumentsException
peekEnum(Class)
,
getEnumOrNull(Class)
,
ICommandArgument.getEnum(Class)
<E extends java.lang.Enum<?>> E peekEnumOrNull(java.lang.Class<E> enumClass) throws CommandNotEnoughArgumentsException
enumClass
- The class to searchCommandNotEnoughArgumentsException
peekEnum(Class)
,
getEnumOrNull(Class)
,
ICommandArgument.getEnum(Class)
<T> T peekAs(java.lang.Class<T> type, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException
IArgParser
to parse the argument at the specified index into the specified
class
A critical difference between IDatatype
s and IArgParser
s is how many arguments they can take.
While IArgParser
s always operate on a single argument's value, IDatatype
s get access to the entire
IArgConsumer
}.
type
- The type to peek asindex
- The index to peekCommandInvalidTypeException
- If the parsing failedCommandNotEnoughArgumentsException
IArgParser
,
peekAs(Class)
,
peekAsOrDefault(Class, Object, int)
,
peekAsOrNull(Class, int)
<T> T peekAs(java.lang.Class<T> type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException
IArgParser
to parse the next argument into the specified class
A critical difference between IDatatype
s and IArgParser
s is how many arguments they can take.
While IArgParser
s always operate on a single argument's value, IDatatype
s get access to the entire
IArgConsumer
}.
type
- The type to peek asCommandInvalidTypeException
- If the parsing failedCommandNotEnoughArgumentsException
IArgParser
,
peekAs(Class, int)
,
peekAsOrDefault(Class, Object)
,
peekAsOrNull(Class)
<T> T peekAsOrDefault(java.lang.Class<T> type, T def, int index) throws CommandNotEnoughArgumentsException
IArgParser
to parse the argument at the specified index into the specified
class
A critical difference between IDatatype
s and IArgParser
s is how many arguments they can take.
While IArgParser
s always operate on a single argument's value, IDatatype
s get access to the entire
IArgConsumer
}.
type
- The type to peek asdef
- The value to return if the argument can't be parsedindex
- The index to peekdef
if it couldn't be parsedCommandNotEnoughArgumentsException
IArgParser
,
peekAsOrDefault(Class, Object)
,
peekAs(Class, int)
,
peekAsOrNull(Class, int)
<T> T peekAsOrDefault(java.lang.Class<T> type, T def) throws CommandNotEnoughArgumentsException
IArgParser
to parse the next argument into the specified class
A critical difference between IDatatype
s and IArgParser
s is how many arguments they can take.
While IArgParser
s always operate on a single argument's value, IDatatype
s get access to the entire
IArgConsumer
}.
type
- The type to peek asdef
- The value to return if the argument can't be parseddef
if it couldn't be parsedCommandNotEnoughArgumentsException
IArgParser
,
peekAsOrDefault(Class, Object, int)
,
peekAs(Class)
,
peekAsOrNull(Class)
<T> T peekAsOrNull(java.lang.Class<T> type, int index) throws CommandNotEnoughArgumentsException
IArgParser
to parse the argument at the specified index into the specified
class
A critical difference between IDatatype
s and IArgParser
s is how many arguments they can take.
While IArgParser
s always operate on a single argument's value, IDatatype
s get access to the entire
IArgConsumer
}.
type
- The type to peek asindex
- The index to peeknull
if it couldn't be parsedCommandNotEnoughArgumentsException
IArgParser
,
peekAsOrNull(Class)
,
peekAs(Class, int)
,
peekAsOrDefault(Class, Object, int)
<T> T peekAsOrNull(java.lang.Class<T> type) throws CommandNotEnoughArgumentsException
IArgParser
to parse the next argument into the specified class
A critical difference between IDatatype
s and IArgParser
s is how many arguments they can take.
While IArgParser
s always operate on a single argument's value, IDatatype
s get access to the entire
IArgConsumer
}.
type
- The type to peek asnull
if it couldn't be parsedCommandNotEnoughArgumentsException
IArgParser
,
peekAsOrNull(Class, int)
,
peekAs(Class)
,
peekAsOrDefault(Class, Object)
<T> T peekDatatype(IDatatypeFor<T> datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException
<T,O> T peekDatatype(IDatatypePost<T,O> datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException
<T,O> T peekDatatype(IDatatypePost<T,O> datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException
<T> T peekDatatypeOrNull(IDatatypeFor<T> datatype)
<T,O> T peekDatatypeOrNull(IDatatypePost<T,O> datatype)
<T,O,D extends IDatatypePost<T,O>> T peekDatatypePost(D datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException
<T,O,D extends IDatatypePost<T,O>> T peekDatatypePostOrDefault(D datatype, O original, T def)
<T,O,D extends IDatatypePost<T,O>> T peekDatatypePostOrNull(D datatype, O original)
<T,D extends IDatatypeFor<T>> T peekDatatypeFor(java.lang.Class<D> datatype)
IDatatypeFor
from this ArgConsumer
A critical difference between IDatatype
s and IArgParser
s is how many arguments they can take.
While IArgParser
s always operate on a single argument's value, IDatatype
s get access to the entire
IArgConsumer
}.
Since this is a peek operation, this ArgConsumer will not be mutated by any call to this method.
datatype
- The datatype to getIDatatype
,
IDatatypeFor
<T,D extends IDatatypeFor<T>> T peekDatatypeForOrDefault(java.lang.Class<D> datatype, T def)
IDatatypeFor
from this ArgConsumer
A critical difference between IDatatype
s and IArgParser
s is how many arguments they can take.
While IArgParser
s always operate on a single argument's value, IDatatype
s get access to the entire
IArgConsumer
}.
Since this is a peek operation, this ArgConsumer will not be mutated by any call to this method.
datatype
- The datatype to getdef
- The default valuedef
if it throws an exceptionIDatatype
,
IDatatypeFor
<T,D extends IDatatypeFor<T>> T peekDatatypeForOrNull(java.lang.Class<D> datatype)
IDatatypeFor
from this ArgConsumer
A critical difference between IDatatype
s and IArgParser
s is how many arguments they can take.
While IArgParser
s always operate on a single argument's value, IDatatype
s get access to the entire
IArgConsumer
}.
Since this is a peek operation, this ArgConsumer will not be mutated by any call to this method.
datatype
- The datatype to getnull
if it throws an exceptionIDatatype
,
IDatatypeFor
ICommandArgument get() throws CommandNotEnoughArgumentsException
CommandNotEnoughArgumentsException
- If there's less than one argument leftjava.lang.String getString() throws CommandNotEnoughArgumentsException
CommandNotEnoughArgumentsException
- If there's less than one argument left<E extends java.lang.Enum<?>> E getEnum(java.lang.Class<E> enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException
For example if you getEnum as an EnumFacing
, and the next argument's value is "up", this will return
EnumFacing.UP
enumClass
- The enum class to searchCommandInvalidTypeException
- If the constant couldn't be foundCommandNotEnoughArgumentsException
peekEnum(Class)
,
getEnumOrNull(Class)
,
ICommandArgument.getEnum(Class)
<E extends java.lang.Enum<?>> E getEnumOrDefault(java.lang.Class<E> enumClass, E def) throws CommandNotEnoughArgumentsException
For example if you getEnum as an EnumFacing
, and the next argument's value is "up", this will return
EnumFacing.UP
enumClass
- The enum class to searchdef
- The default valuedef
if it
couldn't be foundCommandNotEnoughArgumentsException
getEnum(Class)
,
getEnumOrNull(Class)
,
peekEnumOrNull(Class)
,
ICommandArgument.getEnum(Class)
<E extends java.lang.Enum<?>> E getEnumOrNull(java.lang.Class<E> enumClass) throws CommandNotEnoughArgumentsException
For example if you getEnum as an EnumFacing
, and the next argument's value is "up", this will return
EnumFacing.UP
enumClass
- The enum class to searchnull
if it
couldn't be foundCommandNotEnoughArgumentsException
getEnum(Class)
,
getEnumOrDefault(Class, Enum)
,
peekEnumOrNull(Class)
,
ICommandArgument.getEnum(Class)
<T> T getAs(java.lang.Class<T> type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException
IArgParser
to parse the next argument into the specified class
A critical difference between IDatatype
s and IArgParser
s is how many arguments they can take.
While IArgParser
s always operate on a single argument's value, IDatatype
s get access to the entire
IArgConsumer
}.
type
- The type to peek asCommandInvalidTypeException
- If the parsing failedCommandNotEnoughArgumentsException
IArgParser
,
get()
,
getAsOrDefault(Class, Object)
,
getAsOrNull(Class)
,
peekAs(Class)
,
peekAsOrDefault(Class, Object, int)
,
peekAsOrNull(Class, int)
<T> T getAsOrDefault(java.lang.Class<T> type, T def) throws CommandNotEnoughArgumentsException
IArgParser
to parse the next argument into the specified class
A critical difference between IDatatype
s and IArgParser
s is how many arguments they can take.
While IArgParser
s always operate on a single argument's value, IDatatype
s get access to the entire
IArgConsumer
}.
type
- The type to peek asdef
- The default valuedef
if it couldn't be parsedCommandNotEnoughArgumentsException
IArgParser
,
get()
,
getAs(Class)
,
getAsOrNull(Class)
,
peekAs(Class)
,
peekAsOrDefault(Class, Object, int)
,
peekAsOrNull(Class, int)
<T> T getAsOrNull(java.lang.Class<T> type) throws CommandNotEnoughArgumentsException
IArgParser
to parse the next argument into the specified class
A critical difference between IDatatype
s and IArgParser
s is how many arguments they can take.
While IArgParser
s always operate on a single argument's value, IDatatype
s get access to the entire
IArgConsumer
}.
type
- The type to peek asnull
if it couldn't be parsedCommandNotEnoughArgumentsException
IArgParser
,
get()
,
getAs(Class)
,
getAsOrDefault(Class, Object)
,
peekAs(Class)
,
peekAsOrDefault(Class, Object, int)
,
peekAsOrNull(Class, int)
<T,O,D extends IDatatypePost<T,O>> T getDatatypePost(D datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException
<T,O,D extends IDatatypePost<T,O>> T getDatatypePostOrDefault(D datatype, O original, T _default)
<T,O,D extends IDatatypePost<T,O>> T getDatatypePostOrNull(D datatype, O original)
<T,D extends IDatatypeFor<T>> T getDatatypeFor(D datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException
<T,D extends IDatatypeFor<T>> T getDatatypeForOrDefault(D datatype, T def)
<T,D extends IDatatypeFor<T>> T getDatatypeForOrNull(D datatype)
<T extends IDatatype> java.util.stream.Stream<java.lang.String> tabCompleteDatatype(T datatype)
java.lang.String rawRest()
arg1 arg2 arg3
, split
into three ICommandArgument
s "arg1"
, "arg2"
, and "arg3"
:
void requireMin(int min) throws CommandNotEnoughArgumentsException
min
- The minimum amount of arguments to require.CommandNotEnoughArgumentsException
- If there are less than min
arguments left.requireMax(int)
,
requireExactly(int)
void requireMax(int max) throws CommandTooManyArgumentsException
max
- The maximum amount of arguments allowed.CommandTooManyArgumentsException
- If there are more than max
arguments left.requireMin(int)
,
requireExactly(int)
void requireExactly(int args) throws CommandException
args
- The exact amount of arguments to require.CommandNotEnoughArgumentsException
- If there are less than args
arguments left.CommandTooManyArgumentsException
- If there are more than args
arguments left.CommandException
requireMin(int)
,
requireMax(int)
boolean hasConsumed()
IArgConsumer
} has consumed at least one argument.consumed()
,
consumedString()
ICommandArgument consumed()
IArgConsumer
} has consumed, or an "unknown" argument, indicated by a
comamnd argument index that has a value of -1
, if no arguments have been consumed yet.consumedString()
,
hasConsumed()
java.lang.String consumedString()
IArgConsumer
} has consumed, or an empty string if no arguments
have been consumed yetconsumed()
,
hasConsumed()
IArgConsumer copy()
IArgConsumer
}. It has the same arguments (both consumed and not), but does not
affect or mutate this instance. Useful for the various peek
functions