Class ArgumentTypes
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ArrayArgument<T>
array
(ArgumentType<T> type) Creates an array argument for the specifiedtype
static NbtArgument<BinaryTag>
Gets the binary tag argumentstatic BlockArgument
block()
Gets the block argumentstatic BlockFilterArgument
Gets the block filter argumentstatic PositionArgument
Gets an argument that parses a 3D integer positionstatic PositionArgument
Gets an argument that parses a 2D integer positionstatic ComponentArgument
Gets the chat component argumentstatic NbtArgument<CompoundTag>
Gets the compound tag argumentstatic DoubleRangeArgument
Gets the double range argument.static RegistryArgument<Enchantment>
Delegate forregistry(Registry, String)
withRegistry.ENCHANTMENT
static EntityArgument
entities()
Gets an entity selector argument that allows for multiple entities to be returnedstatic EntityArgument
entity()
Gets an entity selector argument that is allowed to only return 1 entitystatic <E extends Enum<E>>
EnumArgument<E>Creates an enum argument for the specifiedenumType
static GameModeArgument
gameMode()
Gets the gamemode argumentstatic Duration
getDuration
(CommandContext<?> context, String argument) Gets a parsed durationgetEntities
(CommandContext<CommandSource> context, String argument) Gets a list of entities from a parsed entity selectorstatic Entity
getEntity
(CommandContext<CommandSource> context, String argument) Gets a single entity from parsed a entity selectorstatic Location
getLocation
(CommandContext<CommandSource> context, String argument) Gets a parsed location.static long
getMillis
(CommandContext<?> context, String argument) Gets a parsed duration, in millisecondsstatic Player
getPlayer
(CommandContext<CommandSource> context, String argument) Gets a single player from a parsed entity selectorgetPlayers
(CommandContext<CommandSource> context, String argument) Gets a list of players from a parsed entity selectorstatic EntitySelector
getSelector
(CommandContext<?> context, String argument) Gets an entity selector from a specifiedcontext
static long
getTicks
(CommandContext<?> context, String argument) Gets a parsed duration, in game ticksstatic IntRangeArgument
intRange()
Gets the double range argument.static ItemArgument
item()
Gets the item argumentstatic ItemFilterArgument
Gets the item filter argumentstatic KeyArgument
key()
Gets the namespaced key argumentstatic LocalDateArgument
Gets the local date argumentstatic LootTableArgument
Gets the loot table argumentstatic <F,
T> ArgumentType<T> map
(ArgumentType<F> fromType, Function<F, T> translator) Maps one argument types results to another type.static <T> MapArgument<T>
Creates a map-based argument type with the specified backing map.static ObjectiveArgument
Gets the scoreboard objective argumentstatic ParticleArgument
particle()
Gets the particle argumentstatic EntityArgument
player()
Gets an entity selector argument that only allows a single player to be returnedstatic EntityArgument
players()
Gets and entity selector argument that is only allowed to return playersstatic PositionArgument
position()
Gets an argument that parses a 3D floating point positionstatic PositionArgument
Gets an argument that parses a 2D floating point positionstatic RegistryArgument<PotionEffectType>
Delegate forregistry(Registry, String)
withRegistry.POTION_EFFECT_TYPE
static <T extends Keyed>
RegistryArgument<T>Creates a registry argument with the specified backingregistry
and specifiedname
static <T extends Keyed>
RegistryArgument<T>registry
(Registry<T> registry, RegistryArgument.UnknownFactory factory) Creates a registry argument with the specified backingregistry
and specified exception factorystatic TagPathArgument
tagPath()
Gets the NBT path argumentstatic TeamArgument
team()
Gets the scoreboard team argumentstatic TimeArgument
time()
Gets the time duration argumentstatic UuidArgument
uuid()
Gets the UUID argumentstatic WorldArgument
world()
Gets the world argument
-
Method Details
-
item
Gets the item argument- Returns:
- Item argument
-
itemFilter
Gets the item filter argument- Returns:
- Item filter argument
-
component
Gets the chat component argument- Returns:
- Chat component argument
-
key
Gets the namespaced key argument- Returns:
- Namespaced key argument
-
world
Gets the world argument- Returns:
- World argument
-
binaryTag
Gets the binary tag argument- Returns:
- Binary tag argument
-
compoundTag
Gets the compound tag argument- Returns:
- Compound tag argument
-
tagPath
Gets the NBT path argument- Returns:
- NBT path argument
-
gameMode
Gets the gamemode argument- Returns:
- Gamemode argument
-
time
Gets the time duration argument- Returns:
- Time duration argument
-
getDuration
public static Duration getDuration(CommandContext<?> context, String argument) throws IllegalArgumentException Gets a parsed duration- Parameters:
context
- Command contextargument
- Name of the argument- Returns:
- Found duration
- Throws:
IllegalArgumentException
- If the specifiedargument
doesn't exist, or if it isn't aDuration
-
getMillis
public static long getMillis(CommandContext<?> context, String argument) throws IllegalArgumentException Gets a parsed duration, in milliseconds- Parameters:
context
- Command contextargument
- Name of the argument- Returns:
- Found duration, in milliseconds
- Throws:
IllegalArgumentException
- If the specifiedargument
doesn't exist, or if it isn't aDuration
-
getTicks
public static long getTicks(CommandContext<?> context, String argument) throws IllegalArgumentException Gets a parsed duration, in game ticks- Parameters:
context
- Command contextargument
- Name of the argument- Returns:
- Found duration, in game ticks
- Throws:
IllegalArgumentException
- If the specifiedargument
doesn't exist, or if it isn't aDuration
-
objective
Gets the scoreboard objective argument- Returns:
- Scoreboard objective argument
-
team
Gets the scoreboard team argument- Returns:
- Scoreboard team argument
-
localDate
Gets the local date argument- Returns:
- Local date argument
-
block
Gets the block argument- Returns:
- Block argument
-
blockFilter
Gets the block filter argument- Returns:
- Block filter argument
-
entity
Gets an entity selector argument that is allowed to only return 1 entity- Returns:
- Entity selector argument
-
getSelector
public static EntitySelector getSelector(CommandContext<?> context, String argument) throws IllegalArgumentException Gets an entity selector from a specifiedcontext
- Parameters:
context
- Command contextargument
- Name of the argument- Returns:
- Found entity selector
- Throws:
IllegalArgumentException
- If the specifiedargument
doesn't exist, or if it isn't anEntitySelector
-
getEntity
public static Entity getEntity(CommandContext<CommandSource> context, String argument) throws CommandSyntaxException, IllegalArgumentException Gets a single entity from parsed a entity selector- Parameters:
context
- Command contextargument
- Name of the argument- Returns:
- Found entity
- Throws:
IllegalArgumentException
- If the specifiedargument
doesn't exist, or if it isn't anEntitySelector
CommandSyntaxException
- If no entity was found, or if the command source in the provided context isn't allowed to access entity selectors
-
entities
Gets an entity selector argument that allows for multiple entities to be returned- Returns:
- Entity selector argument
-
getEntities
public static List<Entity> getEntities(CommandContext<CommandSource> context, String argument) throws CommandSyntaxException, IllegalArgumentException Gets a list of entities from a parsed entity selector- Parameters:
context
- Command contextargument
- Name of the argument- Returns:
- Found entities
- Throws:
IllegalArgumentException
- If the specifiedargument
doesn't exist, or if it isn't anEntitySelector
CommandSyntaxException
- If no entity was found, or if the command source in the provided context isn't allowed to access entity selectors
-
player
Gets an entity selector argument that only allows a single player to be returned- Returns:
- Entity selector argument
-
getPlayer
public static Player getPlayer(CommandContext<CommandSource> context, String argument) throws CommandSyntaxException, IllegalArgumentException Gets a single player from a parsed entity selector- Parameters:
context
- Command contextargument
- Name of the argument- Returns:
- Found player
- Throws:
IllegalArgumentException
- If the specifiedargument
doesn't exist, or if it isn't anEntitySelector
CommandSyntaxException
- If no entity was found, or if the command source in the provided context isn't allowed to access entity selectors
-
players
Gets and entity selector argument that is only allowed to return players- Returns:
- Entity selector argument
-
getPlayers
public static List<Player> getPlayers(CommandContext<CommandSource> context, String argument) throws CommandSyntaxException, IllegalArgumentException Gets a list of players from a parsed entity selector- Parameters:
context
- Command contextargument
- Name of the argument- Returns:
- Found players
- Throws:
IllegalArgumentException
- If the specifiedargument
doesn't exist, or if it isn't anEntitySelector
CommandSyntaxException
- If no entity was found, or if the command source in the provided context isn't allowed to access entity selectors
-
lootTable
Gets the loot table argument- Returns:
- Loot table argument
-
particle
Gets the particle argument- Returns:
- Particle argument
-
uuid
Gets the UUID argument- Returns:
- UUID argument
-
doubleRange
Gets the double range argument.Argument type that returns a range between 2 double values. The range parsed by this argument type is inclusive on both ends.
Input examples:
1..2 = Between 1 and 2 ..2.5 = At most 2.5 3.1.. = At least 3.1
- Returns:
- Double range argument
-
intRange
Gets the double range argument.Argument type that returns a range between 2 integer values. The range parsed by this argument type is inclusive on both ends.
Input examples:
15..35 = Between 15 and 35 ..17 = At most 17 7.. = At least 7
- Returns:
- Int range argument
-
position
Gets an argument that parses a 3D floating point position- Returns:
- Position argument
-
blockPosition
Gets an argument that parses a 3D integer position- Returns:
- Block position argument
-
position2d
Gets an argument that parses a 2D floating point position- Returns:
- 2D position argument
-
blockPosition2d
Gets an argument that parses a 2D integer position- Returns:
- 2D block position argument
-
getLocation
public static Location getLocation(CommandContext<CommandSource> context, String argument) throws IllegalArgumentException Gets a parsed location.Gets the parsed position from the specified
context
and t hen callsParsedPosition.apply(CommandSource)
with the command source in the context- Parameters:
context
- Command contextargument
- Name of the argument- Returns:
- Gotten location
- Throws:
IllegalArgumentException
- If the specifiedargument
doesn't exist, or if it isn't aParsedPosition
-
enchantment
Delegate forregistry(Registry, String)
withRegistry.ENCHANTMENT
- Returns:
- Created argument type
-
potionType
Delegate forregistry(Registry, String)
withRegistry.POTION_EFFECT_TYPE
- Returns:
- Created argument type
-
registry
public static <T extends Keyed> RegistryArgument<T> registry(Registry<T> registry, RegistryArgument.UnknownFactory factory) Creates a registry argument with the specified backingregistry
and specified exception factory- Type Parameters:
T
- Registry type- Parameters:
registry
- Backing registryfactory
- Exception factory used to create exceptions for unknown elements- Returns:
- Created argument type
-
registry
Creates a registry argument with the specified backingregistry
and specifiedname
Uses
ExceptionProvider.unknownResource(NamespacedKey, String, StringReader)
to create the error messages- Type Parameters:
T
- Registry type- Parameters:
registry
- Backing registryname
- Registry name- Returns:
- Created argument type
- See Also:
-
enumType
Creates an enum argument for the specifiedenumType
- Type Parameters:
E
- Enum type- Parameters:
enumType
- Enum class that will be parsed- Returns:
- Created argument type
-
map
Creates a map-based argument type with the specified backing map.Note: no key in the specified
values
map may feature a whitespace character, as whitespace characters are used to detect when to stop reading input- Type Parameters:
T
- Map values- Parameters:
values
- Parse values- Returns:
- Created argument type
- Throws:
IllegalArgumentException
- If any key in the backing map contained a whitespace character
-
array
Creates an array argument for the specifiedtype
- Type Parameters:
T
- Array type- Parameters:
type
- Individual element parser- Returns:
- Created array argument
-
map
Maps one argument types results to another type.For example, say we want to map a
TimeArgument
's result from aDuration
to milliseconds, we would this like so:
The mapped type will use the same parser and provide the same suggestions as the specifiedfinal TimeArgument time = ArgumentTypes.time(); final ArgumentType<Long> mapped = ArgumentTypes.map(time, Duration::toMillis);
fromType
- Type Parameters:
F
- Base type that will be mappedT
- Target type- Parameters:
fromType
- The base type that will parse and provide suggestionstranslator
- The function that translates the base's type- Returns:
- Mapped argument type
-