public final class GenericArguments extends Object
Modifier and Type | Method and Description |
---|---|
static CommandElement |
allOf(CommandElement element)
Require all remaining args to match as many instances of
CommandElement as will fit. |
static CommandElement |
bigDecimal(Text key)
Expect an argument to return a
BigDecimal . |
static CommandElement |
bigInteger(Text key)
Expect an argument to return a
BigInteger . |
static CommandElement |
bool(Text key)
Require an argument to be a boolean.
|
static <T extends CatalogType> |
catalogedElement(Text key,
Class<T> catalogType)
Expect an argument that is a member of the specified
CatalogType
T. |
static CommandElement |
choices(Text key,
Map<String,?> choices)
Return an argument that allows selecting from a limited set of values.
|
static CommandElement |
choices(Text key,
Map<String,?> choices,
boolean choicesInUsage)
Return an argument that allows selecting from a limited set of values.
|
static CommandElement |
choices(Text key,
Map<String,?> choices,
boolean choicesInUsage,
boolean caseSensitive)
Return an argument that allows selecting from a limited set of values.
|
static CommandElement |
choices(Text key,
Supplier<Collection<String>> keys,
Function<String,?> values)
Return an argument that allows selecting from a limited set of values.
|
static CommandElement |
choices(Text key,
Supplier<Collection<String>> keys,
Function<String,?> values,
boolean choicesInUsage)
Return an argument that allows selecting from a limited set of values.
|
static CommandElement |
choicesInsensitive(Text key,
Map<String,?> choices)
Return an argument that allows selecting from a limited set of values.
|
static CommandElement |
dataContainer(Text key)
Expect an argument to be a valid
DataContainer . |
static CommandElement |
dateTime(Text key)
Expect an argument to be a date-time, in the form of a
LocalDateTime . |
static CommandElement |
dateTimeOrNow(Text key)
Expect an argument to be a date-time, in the form of a
LocalDateTime . |
static CommandElement |
dimension(Text key)
Expect an argument to represent a dimension.
|
static CommandElement |
doubleNum(Text key)
Require an argument to be an double-precision floating point number.
|
static CommandElement |
duration(Text key)
Expect an argument to be a
Duration . |
static CommandElement |
entity(Text key)
Expect an argument to represent an
Entity . |
static CommandElement |
entity(Text key,
Class<? extends Entity> clazz)
Expect an argument to represent an
Entity of the specified type. |
static CommandElement |
entity(Text key,
EntityType type)
Expect an argument to represent an
Entity of the specified
EntityType . |
static CommandElement |
entityOrSource(Text key)
Expect an argument to represent an
Entity , or if the argument is
not present and the CommandSource is an entity, return the
source. |
static CommandElement |
entityOrTarget(Text key)
Expect an argument to represent an
Entity , or if the argument is
not present and the CommandSource is looking at an entity,
return that entity. |
static CommandElement |
entityOrTarget(Text key,
Class<? extends Entity> clazz)
Expect an argument to represent an
Entity of the specified type,
or if the argument is not present and the CommandSource is
looking at an applicable entity, return that entity. |
static CommandElement |
entityOrTarget(Text key,
EntityType type)
Expect an argument to represent an
Entity of the specified
EntityType , or if the argument is not present and the
CommandSource is looking at an applicable entity, return that
entity. |
static <T extends Enum<T>> |
enumValue(Text key,
Class<T> type)
Require the argument to be a key under the provided enum.
|
static CommandElement |
firstParsing(CommandElement... elements)
Returns a command element that matches the first of the provided elements
that parses tab completion matches from all options.
|
static CommandFlags.Builder |
flags()
Gets a builder to create a command element that parses flags.
|
static CommandElement |
integer(Text key)
Require an argument to be an integer (base 10).
|
static CommandElement |
ip(Text key)
Expect an argument to return an IP address, in the form of an
InetAddress . |
static CommandElement |
ipOrSource(Text key)
Expect an argument to return an IP address, in the form of an
InetAddress , or if nothing matches and the source is a
RemoteSource , return the source's address. |
static CommandElement |
literal(Text key,
Object putValue,
String... expectedArgs)
Expect a literal sequence of arguments.
|
static CommandElement |
literal(Text key,
String... expectedArgs)
Expect a literal sequence of arguments.
|
static CommandElement |
location(Text key)
Expect an argument to represent a
Location . |
static CommandElement |
longNum(Text key)
Require an argument to be a long (base 10).
|
static CommandElement |
markTrue(Text key)
Expects no arguments.
|
static CommandElement |
none()
Expects no arguments, returns no values.
|
static CommandElement |
onlyOne(CommandElement element)
Restricts the given command element to only insert one value into the
context at the provided key.
|
static CommandElement |
optional(CommandElement element)
Make the provided command element optional.
|
static CommandElement |
optional(CommandElement element,
Object value)
Make the provided command element optional.
|
static CommandElement |
optionalWeak(CommandElement element)
Make the provided command element optional
This means the command element is not required.
|
static CommandElement |
optionalWeak(CommandElement element,
Object value)
Make the provided command element optional.
|
static CommandElement |
player(Text key)
Expect an argument to represent online players.
|
static CommandElement |
playerOrSource(Text key)
Expect an argument to represent online players, or if nothing matches
and the source is a
Player , give the player. |
static CommandElement |
plugin(Text key)
Expect an argument to represent a
PluginContainer 's id. |
static CommandElement |
remainingJoinedStrings(Text key)
Require one or more strings, which are combined into a single,
space-separated string.
|
static CommandElement |
remainingRawJoinedStrings(Text key)
Require one or more strings, without any processing, which are combined
into a single, space-separated string.
|
static CommandElement |
repeated(CommandElement element,
int times)
Require a given command element to be provided a certain number of times.
|
static CommandElement |
requiringPermission(CommandElement element,
String permission)
Checks a permission for a given command argument to be used.
|
static CommandElement |
requiringPermissionWeak(CommandElement element,
String permission)
Checks a permission for a given command argument to be used.
|
static CommandElement |
seq(CommandElement... elements)
Consumes a series of arguments.
|
static CommandElement |
string(Text key)
Require an argument to be a string.
|
static CommandElement |
text(Text key,
TextSerializer serializer,
boolean allRemaining)
Expect an argument to be valid
Text . |
static CommandElement |
url(Text key)
Expect an argument to represent a
URL . |
static CommandElement |
user(Text key)
Expect an argument to represent players who have been online at some
point, as a
User . |
static CommandElement |
userOrSource(Text key)
|
static CommandElement |
uuid(Text key)
Expect an argument to be a
UUID . |
static CommandElement |
vector3d(Text key)
Expect an argument to represent a
Vector3d . |
static CommandElement |
withConstrainedSuggestions(CommandElement argument,
Predicate<String> predicate)
Filters an argument's suggestions.
|
static CommandElement |
withSuggestions(CommandElement argument,
Function<CommandSource,Iterable<String>> suggestions)
Uses a custom set of suggestions for an argument.
|
static CommandElement |
withSuggestions(CommandElement argument,
Function<CommandSource,Iterable<String>> suggestions,
boolean requireBegin)
Uses a custom set of suggestions for an argument.
|
static CommandElement |
withSuggestions(CommandElement argument,
Iterable<String> suggestions)
Uses a custom set of suggestions for an argument.
|
static CommandElement |
withSuggestions(CommandElement argument,
Iterable<String> suggestions,
boolean requireBegin)
Uses a custom set of suggestions for an argument.
|
static CommandElement |
world(Text key)
Expect an argument to represent a world.
|
public static CommandElement none()
public static CommandElement markTrue(Text key)
This will return only one value.
key
- the key to store 'true' underpublic static CommandElement playerOrSource(Text key)
Player
, give the player. If nothing matches
and the source is not a player, throw an exception.
Gives values of type Player
.
This argument accepts the following inputs:
This may return multiple players. If you must only return one, wrap
this element in an onlyOne(CommandElement)
call.
key
- The key to store underpublic static CommandElement player(Text key)
Player
.
This argument accepts the following inputs:
This may return multiple players. If you must only return one, wrap
this element in an onlyOne(CommandElement)
call.
key
- The key to store underpublic static CommandElement user(Text key)
User
.
This argument accepts the following inputs:
This may return multiple User
s. If you must only return one,
wrap this element in an onlyOne(CommandElement)
call.
This may not return the Player
object for an online user. If
you wish to operate on an associated Player
object if the user is
online, use User.getPlayer()
.
key
- The key to store underpublic static CommandElement userOrSource(Text key)
User
, or if nothing matches and the source is a
User
, give the user. If nothing matches and the source is not
a User
, throw an exception.
This argument accepts the following inputs:
This may return multiple User
s. If you must only return one,
wrap this element in an onlyOne(CommandElement)
call.
This may not return the Player
object for an online user. If
you wish to operate on an associated Player
object if the user is
online, use User.getPlayer()
.
key
- The key to store underpublic static CommandElement world(Text key)
WorldProperties
objects rather than an actual World
in
order to include unloaded worlds.
This argument accepts the following inputs:
This may return multiple WorldProperties
s. If you must only
return one, wrap this element in an onlyOne(CommandElement)
call.
key
- The key to store underpublic static CommandElement dimension(Text key)
DimensionType
.
This argument accepts the following inputs:
This may return multiple DimensionType
s. If you must only
return one, wrap this element in an onlyOne(CommandElement)
call.
key
- The key to store underpublic static CommandElement vector3d(Text key)
Vector3d
.
This will return one value.
key
- The key to store underpublic static CommandElement location(Text key)
Location
.
This will return one value.
key
- The key to store underpublic static <T extends CatalogType> CommandElement catalogedElement(Text key, Class<T> catalogType)
CatalogType
T.
This argument accepts the following inputs:
CatalogType.getId()
This may return multiple instances of T. If you must only return one,
wrap this element in an onlyOne(CommandElement)
call.
T
- The type to returnkey
- The key to store the resolved value undercatalogType
- The expected CatalogType
public static CommandElement plugin(Text key)
PluginContainer
's id.
This argument accepts the following inputs:
PluginContainer
's idThis may return multiple PluginContainer
s. If you must only
return one, wrap this element in an onlyOne(CommandElement)
call.
key
- The key to store underpublic static CommandFlags.Builder flags()
There should only be ONE of these in a command element sequence if you
wish to use flags. A CommandFlags.Builder
can handle multiple
flags that have different behaviors. Using multiple builders in the same
sequence may cause unexpected behavior.
Any command elements that are not associated with flags should be
placed into the CommandFlags.Builder.buildWith(CommandElement)
parameter, allowing the flags to be used throughout the argument string.
public static CommandElement seq(CommandElement... elements)
elements
- The series of arguments to expectpublic static CommandElement choices(Text key, Map<String,?> choices)
If there are 5 or fewer choices available, the choices will be shown in the command usage. Otherwise, the usage will only display only the key.
Choices are case sensitive. If you do not require
case sensitivity, see choicesInsensitive(Text, Map)
.
To override this behavior, see
choices(Text, Map, boolean, boolean)
.
When parsing, only one choice may be selected, returning its associated value.
key
- The key to store the resulting value underchoices
- The choices users can choose frompublic static CommandElement choicesInsensitive(Text key, Map<String,?> choices)
If there are 5 or fewer choices available, the choices will be shown in the command usage. Otherwise, the usage will only display only the key.
Choices are not case sensitive. If you require
case sensitivity, see choices(Text, Map)
To override this behavior, see
choices(Text, Map, boolean, boolean)
.
When parsing, only one choice may be selected, returning its associated value.
key
- The key to store the resulting value underchoices
- The choices users can choose frompublic static CommandElement choices(Text key, Map<String,?> choices, boolean choicesInUsage)
Unless choicesInUsage
is true, general command usage will only
display the provided key.
Choices are case sensitive. If you do not require
case sensitivity, see choices(Text, Map, boolean, boolean)
When parsing, only one choice may be selected, returning its associated value.
key
- The key to store the resulting value underchoices
- The choices users can choose fromchoicesInUsage
- Whether to display the available choices, or simply
the provided key, as part of usagepublic static CommandElement choices(Text key, Map<String,?> choices, boolean choicesInUsage, boolean caseSensitive)
Unless choicesInUsage
is true, general command usage will only
display the provided key.
When parsing, only one choice may be selected, returning its associated value.
key
- The key to store the resulting value underchoices
- The choices users can choose fromchoicesInUsage
- Whether to display the available choices, or simply
the provided key, as part of usagecaseSensitive
- Whether the matches should be case sensitivepublic static CommandElement choices(Text key, Supplier<Collection<String>> keys, Function<String,?> values)
If there are 5 or fewer choices available, the choices will be shown in the command usage. Otherwise, the usage will only display only the key.
To override this behavior, see choices(Text, Map, boolean)
.
Only one choice may be selected, returning its associated value.
key
- The key to store the resulting value underkeys
- The function that will supply available keysvalues
- The function that maps an element of key
to a value
and any other key to null
public static CommandElement choices(Text key, Supplier<Collection<String>> keys, Function<String,?> values, boolean choicesInUsage)
choicesInUsage
is true, general command usage will only
display the provided key.
Only one choice may be selected, returning its associated value.
key
- The key to store the resulting value underkeys
- The function that will supply available keysvalues
- The function that maps an element of key
to a value
and any other key to null
choicesInUsage
- Whether to display the available choices, or simply
the provided key, as part of usagepublic static CommandElement firstParsing(CommandElement... elements)
elements
- The elements to check againstpublic static CommandElement optional(CommandElement element)
This means the command element is not required. However, if the element is provided with invalid format and there are no more args specified, any errors will still be passed on.
element
- The element to optionally requirepublic static CommandElement optional(CommandElement element, Object value)
This means the command element is not required. However, if the
element is provided with invalid format and there are no more args
specified, any errors will still be passed on. If the given element's key
and value
are not null and this element is not provided the
element's key will be set to the given value.
element
- The element to optionally requirevalue
- The default value to setpublic static CommandElement optionalWeak(CommandElement element)
element
- The element to optionally requirepublic static CommandElement optionalWeak(CommandElement element, Object value)
Make the provided command element optional.
This means the command element is not required.
value
are not null and
this element is not provided the element's key will be set to the
given value.element
- The element to optionally requirevalue
- The default value to setpublic static CommandElement repeated(CommandElement element, int times)
Command values will be stored under their provided keys in the CommandContext.
element
- The element to repeattimes
- The number of times to repeat the element.public static CommandElement allOf(CommandElement element)
CommandElement
as will fit. Command element values will be stored
under their provided keys in the CommandContext.element
- The element to repeatpublic static CommandElement string(Text key)
Gives values of type String
. This will return only one value.
key
- The key to store the parsed argument underpublic static CommandElement integer(Text key)
Gives values of type Integer
. This will return only one value.
key
- The key to store the parsed argument underpublic static CommandElement longNum(Text key)
Gives values of type Long
. This will return only one value.
key
- The key to store the parsed argument underpublic static CommandElement doubleNum(Text key)
Gives values of type Double
. This will return only one value.
key
- The key to store the parsed argument underpublic static CommandElement bool(Text key)
The recognized true values are:
The recognized false values are:
Gives values of type Boolean
. This will return only one value.
key
- The key to store the parsed argument underpublic static <T extends Enum<T>> CommandElement enumValue(Text key, Class<T> type)
Gives values of type T. This will return only one value.
T
- The type of enumkey
- The key to store the matched enum value undertype
- The enum class to get enum constants frompublic static CommandElement remainingJoinedStrings(Text key)
Gives values of type String
. This will return only one value.
key
- The key to store the parsed argument underpublic static CommandElement remainingRawJoinedStrings(Text key)
Gives values of type String
. This will return only one value.
key
- The key to store the parsed argument underpublic static CommandElement literal(Text key, String... expectedArgs)
This will return only one value.
key
- The key to add to the context. Will be set to a value of true
if this element matchesexpectedArgs
- The sequence of arguments expectedpublic static CommandElement literal(Text key, @Nullable Object putValue, String... expectedArgs)
This will return only one value.
key
- The key to store this argument asputValue
- The value to put at key if this argument matches. May be
nullexpectedArgs
- The sequence of arguments expectedpublic static CommandElement onlyOne(CommandElement element)
If more than one value is returned by an element, or the target key
already contains a value, this will throw an
ArgumentParseException
element
- The element to restrictpublic static CommandElement requiringPermission(CommandElement element, String permission)
If the element attempts to parse an argument and the user does not
have the permission, an ArgumentParseException
will be thrown.
element
- The element to wrappermission
- The permission to checkpublic static CommandElement requiringPermissionWeak(CommandElement element, String permission)
If the element attempts to parse an argument and the user does not have the permission, the element will be skipped over.
If the invoking CommandSource
has permission to use the
element, but the wrapped element fails to parse, an exception will
be reported in the normal way. If you require this element to be
truly optional, wrap this element in either
optional(CommandElement)
or
optionalWeak(CommandElement)
, as required.
element
- The element to wrappermission
- The permission to checkpublic static CommandElement entity(Text key)
Entity
.
This argument accepts the following inputs:
UUID
key
- The key to store underpublic static CommandElement entity(Text key, Class<? extends Entity> clazz)
Entity
of the specified type.
This argument accepts the following inputs:
UUID
key
- The key to store underclazz
- The type which the entity must subclasspublic static CommandElement entity(Text key, EntityType type)
Entity
of the specified
EntityType
.
This argument accepts the following inputs:
UUID
key
- The key to store undertype
- The type which the entity must bepublic static CommandElement entityOrSource(Text key)
Entity
, or if the argument is
not present and the CommandSource
is an entity, return the
source.
This argument accepts the following inputs:
UUID
key
- The key to store underpublic static CommandElement entityOrTarget(Text key)
Entity
, or if the argument is
not present and the CommandSource
is looking at an entity,
return that entity.
This argument accepts the following inputs:
UUID
key
- The key to store underpublic static CommandElement entityOrTarget(Text key, Class<? extends Entity> clazz)
Entity
of the specified type,
or if the argument is not present and the CommandSource
is
looking at an applicable entity, return that entity.
This argument accepts the following inputs:
UUID
key
- The key to store underclazz
- The type which the entity must subclasspublic static CommandElement entityOrTarget(Text key, EntityType type)
Entity
of the specified
EntityType
, or if the argument is not present and the
CommandSource
is looking at an applicable entity, return that
entity.
This argument accepts the following inputs:
UUID
key
- The key to store undertype
- The type which the entity must bepublic static CommandElement url(Text key)
URL
.
This will return only one value.
key
- The key to store underpublic static CommandElement ip(Text key)
InetAddress
.
This will return only one value.
key
- The key to store underpublic static CommandElement ipOrSource(Text key)
InetAddress
, or if nothing matches and the source is a
RemoteSource
, return the source's address.
This will return only one value.
key
- The key to store underpublic static CommandElement bigDecimal(Text key)
BigDecimal
.key
- The key to store underpublic static CommandElement bigInteger(Text key)
BigInteger
.
This will return only one value.
key
- The key to store underpublic static CommandElement dataContainer(Text key)
DataContainer
.
This will return only one value.
key
- The key to store underpublic static CommandElement uuid(Text key)
UUID
.
This will return only one value.
key
- The key to store underpublic static CommandElement text(Text key, TextSerializer serializer, boolean allRemaining)
Text
.
This will return only one value.
key
- The key to store underserializer
- The serializer to parse the text withallRemaining
- If true, consumes all remaining arguments; if false,
uses a single argumentpublic static CommandElement dateTime(Text key)
LocalDateTime
. If no date is specified, LocalDate.now()
is used; if no time is specified, LocalTime.MIDNIGHT
is used.
Date-times are expected in the ISO-8601 format.
This will return only one value.
key
- The key to store underpublic static CommandElement dateTimeOrNow(Text key)
LocalDateTime
. If no date is specified, LocalDate.now()
is used; if no time is specified, LocalTime.MIDNIGHT
is used.
If no argument at all is specified, defaults to
LocalDateTime.now()
.
Date-times are expected in the ISO-8601 format.
This will return only one value.
key
- The key to store underpublic static CommandElement duration(Text key)
Duration
.
Durations are expected in the following format: #D#H#M#S
.
This is not case sensitive.
This will return only one value.
key
- The key to store underpublic static CommandElement withSuggestions(CommandElement argument, Iterable<String> suggestions)
argument
- The element to replace the suggestions ofsuggestions
- The suggestions to usepublic static CommandElement withSuggestions(CommandElement argument, Iterable<String> suggestions, boolean requireBegin)
If requireBegin
is false, then the already typed argument
will not be used to filter the provided suggestions.
argument
- The element to replace the suggestions ofsuggestions
- The suggestions to userequireBegin
- Whether or not to require the current argument to
begin provided argumentspublic static CommandElement withSuggestions(CommandElement argument, Function<CommandSource,Iterable<String>> suggestions)
argument
- The element to replace the suggestions ofsuggestions
- A function to return the suggestions to usepublic static CommandElement withSuggestions(CommandElement argument, Function<CommandSource,Iterable<String>> suggestions, boolean requireBegin)
If requireBegin
is false, then the already typed argument
will not be used to filter the provided suggestions.
argument
- The element to replace the suggestions ofsuggestions
- A function to return the suggestions to userequireBegin
- Whether or not to require the current argument to
begin provided argumentspublic static CommandElement withConstrainedSuggestions(CommandElement argument, Predicate<String> predicate)
argument
- The element to filter the suggestions ofpredicate
- The predicate to test suggestions against