CommandAPI 9.6.0
An API for the command UI introduced in Minecraft 1.13
com.mojang.brigadier.builder.RequiredArgumentBuilder< S, T > Class Template Reference

An ArgumentBuilder for a ArgumentCommandNode that is triggered by an argument, like a number. More...

+ Inheritance diagram for com.mojang.brigadier.builder.RequiredArgumentBuilder< S, T >:

Public Member Functions

RequiredArgumentBuilder< S, T > suggests (final SuggestionProvider< S > provider)
 Sets the SuggestionProvider that provides the user with suggestions about what the next value could be. More...
 
SuggestionProvider< S > getSuggestionsProvider ()
 Returns the SuggestionProvider the command node uses to advice the user on possible completions. More...
 
ArgumentType< T > getType ()
 Returns the ArgumentType the built command node will use. More...
 
String getName ()
 Returns the name of the argument the built command node will have. More...
 
ArgumentCommandNode< S, T > build ()
 
then (final ArgumentBuilder< S, ?> argument)
 Builds the given ArgumentBuilder and adds the result as new child node. More...
 
then (final CommandNode< S > argument)
 Adds the given command node as a child. More...
 
Collection< CommandNode< S > > getArguments ()
 Returns all registered child command nodes. More...
 
executes (final Command< S > command)
 Sets the command that will be executed by the built command node. More...
 
Command< S > getCommand ()
 Returns the Command the built command node will execute. More...
 
requires (final Predicate< S > requirement)
 Sets the predicate that must be true for a command source in order to be able to use the built command node or its children. More...
 
Predicate< S > getRequirement ()
 Returns the requirement each command source must meet in order to be able to use this command node. More...
 
redirect (final CommandNode< S > target)
 Redirects this command node to the target CommandNode. More...
 
redirect (final CommandNode< S > target, final SingleRedirectModifier< S > modifier)
 Redirects this command node to the target CommandNode. More...
 
fork (final CommandNode< S > target, final RedirectModifier< S > modifier)
 Forks this command node, i.e. More...
 
forward (final CommandNode< S > target, final RedirectModifier< S > modifier, final boolean fork)
 Forwards this command in some way to a given target command. More...
 
CommandNode< S > getRedirect ()
 Returns the command node that the built command node redirects to. More...
 
RedirectModifier< S > getRedirectModifier ()
 Returns the redirect modifier for the built command node. More...
 
boolean isFork ()
 Returns whether the built command node forks. More...
 

Static Public Member Functions

static< S, T > RequiredArgumentBuilder< S, T > argument (final String name, final ArgumentType< T > type)
 A factory method to create a new builder for an argument command node. More...
 

Protected Member Functions

RequiredArgumentBuilder< S, T > getThis ()
 

Detailed Description

An ArgumentBuilder for a ArgumentCommandNode that is triggered by an argument, like a number.

The type of the argument is set via an ArgumentType, which takes care of parsing the stringified argument passed by users.


A short example:
A subcommand for a delete command, taking the number of messages to delete. The ArgumentType would be an IntegerArgumentType then and the built command would parse things like "20" or "-230".

Parameters
<S>the type of the command source
<T>the ArgumentType the built command node will use

Member Function Documentation

◆ argument()

static< S, T > RequiredArgumentBuilder< S, T > com.mojang.brigadier.builder.RequiredArgumentBuilder< S, T >.argument ( final String  name,
final ArgumentType< T >  type 
)
static

A factory method to create a new builder for an argument command node.

This method is intended for static importing, so you can just use "argument(<name>, <type>)" in your code.

Parameters
namethe name of the argument. Used with CommandContext#getArgument to retrieve the parsed argument out of a CommandContext
typethe ArgumentType this command builder takes
<S>the type of the command source
<T>the type of the argument this command builder takes
Returns
a RequiredArgumentBuilder with a given name and argument type

◆ executes()

T com.mojang.brigadier.builder.ArgumentBuilder< S, T >.executes ( final Command< S >  command)
inherited

Sets the command that will be executed by the built command node.

Parameters
commandthe Command to execute
Returns
this object

◆ fork()

T com.mojang.brigadier.builder.ArgumentBuilder< S, T >.fork ( final CommandNode< S >  target,
final RedirectModifier< S >  modifier 
)
inherited

Forks this command node, i.e.

it splits execution and calls the target command node multiple times with different sources.

Forking means that the target command will be invoked multiple times, once for each source in the list of sources generated by the passed RedirectModifier.

Parameters
targetthe command node that will be invoked when the built command node is executed
modifierthe redirect modifier to use to generate the command source list
Returns
this object
See also
forward

◆ forward()

T com.mojang.brigadier.builder.ArgumentBuilder< S, T >.forward ( final CommandNode< S >  target,
final RedirectModifier< S >  modifier,
final boolean  fork 
)
inherited

Forwards this command in some way to a given target command.

It will call the target command node for each command source in the list the modifier returns, but the semantics differ slightly. Please have a look at CommandDispatcher#execute(ParseResults) for a more detailed explanation.

Parameters
targetthe command node that will be invoked when the built command node is executed
modifierthe redirect modifier to use to generate the command source list
forkwhether the command node should be forked
Returns
this object
See also
CommandDispatcher::execute(ParseResults)

◆ getArguments()

Collection< CommandNode< S > > com.mojang.brigadier.builder.ArgumentBuilder< S, T >.getArguments ( )
inherited

Returns all registered child command nodes.

Returns
all registered child command nodes

◆ getCommand()

Command< S > com.mojang.brigadier.builder.ArgumentBuilder< S, T >.getCommand ( )
inherited

Returns the Command the built command node will execute.

Returns
the Command the built command node will execute or null if not set

◆ getName()

Returns the name of the argument the built command node will have.

Can be used with CommandContext#getArgument to retrieve the parsed argument

Returns
the name of the argument the built command node will have

◆ getRedirect()

CommandNode< S > com.mojang.brigadier.builder.ArgumentBuilder< S, T >.getRedirect ( )
inherited

Returns the command node that the built command node redirects to.

Returns
the command node that the built command node redirects to or null if not set

◆ getRedirectModifier()

RedirectModifier< S > com.mojang.brigadier.builder.ArgumentBuilder< S, T >.getRedirectModifier ( )
inherited

Returns the redirect modifier for the built command node.

Returns
the redirect modifier for the built command node or null if none

◆ getRequirement()

Predicate< S > com.mojang.brigadier.builder.ArgumentBuilder< S, T >.getRequirement ( )
inherited

Returns the requirement each command source must meet in order to be able to use this command node.

Returns
the requirement each command source must meet in order to be able to use this command node

◆ getSuggestionsProvider()

Returns the SuggestionProvider the command node uses to advice the user on possible completions.

Returns
the registered SuggestionProvider or null if not set

◆ getType()

Returns the ArgumentType the built command node will use.

Returns
the ArgumentType the built command node will use

◆ isFork()

boolean com.mojang.brigadier.builder.ArgumentBuilder< S, T >.isFork ( )
inherited

Returns whether the built command node forks.

Returns
true if the built command node forks

◆ redirect() [1/2]

T com.mojang.brigadier.builder.ArgumentBuilder< S, T >.redirect ( final CommandNode< S >  target)
inherited

Redirects this command node to the target CommandNode.

A redirected node will appear in usage listings, but will otherwise behave just like an alias to the command node it points to.

This method sets isFork() to false and applies no RedirectModifier.

Parameters
targetthe command node that will be invoked when the built command node is executed
Returns
this object
See also
forward

◆ redirect() [2/2]

T com.mojang.brigadier.builder.ArgumentBuilder< S, T >.redirect ( final CommandNode< S >  target,
final SingleRedirectModifier< S >  modifier 
)
inherited

Redirects this command node to the target CommandNode.

A redirected node will appear in usage listings, but will otherwise behave just like an alias to the command node it points to.

This method sets isFork() to false and applies the given SingleRedirectModifier.

Parameters
targetthe command node that will be invoked when the built command node is executed
modifierthe redirect modifier to apply
Returns
this object
See also
forward

◆ requires()

T com.mojang.brigadier.builder.ArgumentBuilder< S, T >.requires ( final Predicate< S >  requirement)
inherited

Sets the predicate that must be true for a command source in order to be able to use the built command node or its children.

The default requirement, if you set none, is always true.

Parameters
requirementthe requirement each command source needs to fulfill in order to be able to use the built command node or its children
Returns
this object

◆ suggests()

Sets the SuggestionProvider that provides the user with suggestions about what the next value could be.

Parameters
providerthe SuggestionProvider to use
Returns
this argument builder

◆ then() [1/2]

T com.mojang.brigadier.builder.ArgumentBuilder< S, T >.then ( final ArgumentBuilder< S, ?>  argument)
inherited

Builds the given ArgumentBuilder and adds the result as new child node.

Parameters
argumentthe ArgumentBuilder to add
Returns
this object
Exceptions
IllegalStateExceptionif getRedirect() is set (i.e. not null)
See also
#then(CommandNode)

◆ then() [2/2]

T com.mojang.brigadier.builder.ArgumentBuilder< S, T >.then ( final CommandNode< S >  argument)
inherited

Adds the given command node as a child.

Parameters
argumentthe command node to add
Returns
this object
Exceptions
IllegalStateExceptionif getRedirect() is set (i.e. not null)