CommandAPI 9.7.0
An API for the command UI introduced in Minecraft 1.13
com.mojang.brigadier.builder.ArgumentBuilder< S, T > Class Template Referenceabstract

A skeleton implementation of a Builder for CommandNodes. More...

Public Member Functions

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...
 
abstract CommandNode< S > build ()
 Builds the CommandNode based on this builder. More...
 

Protected Member Functions

abstract T getThis ()
 Returns this argument builder. More...
 

Detailed Description

A skeleton implementation of a Builder for CommandNodes.

Parameters
<S>the type of the command source
<T>the type of the builder. Used to realize an emulated self type

Member Function Documentation

◆ build()

abstract CommandNode< S > com.mojang.brigadier.builder.ArgumentBuilder< S, T >.build ( )
abstract

Builds the CommandNode based on this builder.

Returns
the built command node

◆ executes()

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

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 
)

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 
)

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 ( )

Returns all registered child command nodes.

Returns
all registered child command nodes

◆ getCommand()

Returns the Command the built command node will execute.

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

◆ getRedirect()

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 ( )

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 ( )

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

◆ getThis()

abstract T com.mojang.brigadier.builder.ArgumentBuilder< S, T >.getThis ( )
abstractprotected

Returns this argument builder.

This returns T and is therefore suitable to allow chained calls to also call methods of the subclass it was invoked on. This is possible as this emulates a "self" type in java, which would always resolve to the type of the object you call it on.

Returns
this object

◆ isFork()

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)

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 
)

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)

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

◆ then() [1/2]

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

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)

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)