CommandAPI 9.3.0
An API for the command UI introduced in Minecraft 1.13
com.mojang.brigadier.tree.LiteralCommandNode< S > Class Template Reference

An CommandNode that is triggered by a literal (i.e. More...

+ Inheritance diagram for com.mojang.brigadier.tree.LiteralCommandNode< S >:

Public Member Functions

 LiteralCommandNode (final String literal, final Command< S > command, final Predicate< S > requirement, final CommandNode< S > redirect, final RedirectModifier< S > modifier, final boolean forks)
 
String getLiteral ()
 Returns the literal this command represents. More...
 
String getName ()
 Returns the name of this command node. More...
 
void parse (final StringReader reader, final CommandContextBuilder< S > contextBuilder) throws CommandSyntaxException
 Tries to parse the command given by the reader and stores the results in the contextBuilder. More...
 
CompletableFuture< SuggestionslistSuggestions (final CommandContext< S > context, final SuggestionsBuilder builder)
 Lists suggestions for this command node, given the context and uses the passed SuggestionsBuilder to build them. More...
 
boolean isValidInput (final String input)
 Checks if the given input is valid for this command node, i.e. More...
 
boolean equals (final Object o)
 
String getUsageText ()
 Returns some usage text for this command node. More...
 
int hashCode ()
 
LiteralArgumentBuilder< S > createBuilder ()
 Creates a builder for this command node. More...
 
Collection< String > getExamples ()
 Returns example usages for this command node, which are used to find ambiguities. More...
 
String toString ()
 
Command< S > getCommand ()
 Returns the command to execute when executing this command node. More...
 
Collection< CommandNode< S > > getChildren ()
 Returns all child command nodes. More...
 
CommandNode< S > getChild (final String name)
 Returns a child with the given getName. More...
 
CommandNode< S > getRedirect ()
 Returns the command node to redirect to. More...
 
RedirectModifier< S > getRedirectModifier ()
 Returns the redirect modifier to apply when redirecting. More...
 
boolean canUse (final S source)
 Checks whether the given command source can use this command node. More...
 
void addChild (final CommandNode< S > node)
 Adds a new child node to this command node. More...
 
void findAmbiguities (final AmbiguityConsumer< S > consumer)
 Tries to find ambiguities in the children of this command node and recurses down. More...
 
Predicate< S > getRequirement ()
 Returns the requirement for this command node, that is used by canUse(Object). More...
 
Collection<? extends CommandNode< S > > getRelevantNodes (final StringReader input)
 Returns all relevant command nodes for the input, so all nodes that are probably able to parse the input. More...
 
int compareTo (final CommandNode< S > o)
 
boolean isFork ()
 Checks whether this command node forks. More...
 

Protected Member Functions

String getSortedKey ()
 Returns a key for this command node, that is used for ordering the command nodes. More...
 

Detailed Description

An CommandNode that is triggered by a literal (i.e.

fixed) keyword.

An example would be a command like "ping", that is identified by its keyword.

Parameters
<S>the type of the command source

Member Function Documentation

◆ addChild()

void com.mojang.brigadier.tree.CommandNode< S >.addChild ( final CommandNode< S >  node)
inherited

Adds a new child node to this command node.


This will replace a command node with the same name, but there exist some bugs and some design decisions are not final as of now. Subsequently the exact behaviour in this case is not mandated. For a more detailed post about the problems, read this github issue.


You are not allowed to add children to commands with a getRedirect() target!

Parameters
nodethe child command node to add
Exceptions
UnsupportedOperationExceptionif you try to add a RootCommandNode to any other command node

◆ canUse()

boolean com.mojang.brigadier.tree.CommandNode< S >.canUse ( final S  source)
inherited

Checks whether the given command source can use this command node.

This just checks the getRequirement() predicate, which could e.g. check for permissions.

Parameters
sourcethe command source to check for
Returns
true if the given command source can use this command node

◆ createBuilder()

Creates a builder for this command node.

Returns
a builder for this command node

Reimplemented from com.mojang.brigadier.tree.CommandNode< S >.

◆ equals()

boolean com.mojang.brigadier.tree.LiteralCommandNode< S >.equals ( final Object  o)

◆ findAmbiguities()

void com.mojang.brigadier.tree.CommandNode< S >.findAmbiguities ( final AmbiguityConsumer< S >  consumer)
inherited

Tries to find ambiguities in the children of this command node and recurses down.

This can be used to detect whether multiple paths could be taken with a single input, which is not an ideal state for parsing commands. See CommandDispatcher#findAmbiguities for more information.

Parameters
consumerthe AmbiguityConsumer to call when ambiguities are found

◆ getChild()

CommandNode< S > com.mojang.brigadier.tree.CommandNode< S >.getChild ( final String  name)
inherited

Returns a child with the given getName.

Parameters
namethe name of the child command node
Returns
the child with that name or null if not found

◆ getChildren()

Collection< CommandNode< S > > com.mojang.brigadier.tree.CommandNode< S >.getChildren ( )
inherited

Returns all child command nodes.

Returns
all child command nodes

◆ getCommand()

Command< S > com.mojang.brigadier.tree.CommandNode< S >.getCommand ( )
inherited

Returns the command to execute when executing this command node.

Returns
the command to execute when executing this command node or null if not set

◆ getExamples()

Collection< String > com.mojang.brigadier.tree.LiteralCommandNode< S >.getExamples ( )

Returns example usages for this command node, which are used to find ambiguities.

Returns
some example usages for this command node, which are used to find ambiguities
See also
findAmbiguities

Reimplemented from com.mojang.brigadier.tree.CommandNode< S >.

◆ getLiteral()

Returns the literal this command represents.

Returns
the literal this command represents

◆ getName()

Returns the name of this command node.

Returns
the name of this command node

Reimplemented from com.mojang.brigadier.tree.CommandNode< S >.

◆ getRedirect()

CommandNode< S > com.mojang.brigadier.tree.CommandNode< S >.getRedirect ( )
inherited

Returns the command node to redirect to.

Returns
the command node to redirect to or null if none

◆ getRedirectModifier()

RedirectModifier< S > com.mojang.brigadier.tree.CommandNode< S >.getRedirectModifier ( )
inherited

Returns the redirect modifier to apply when redirecting.

Returns
the redirect modifier to apply when redirecting or null if none

◆ getRelevantNodes()

Collection<? extends CommandNode< S > > com.mojang.brigadier.tree.CommandNode< S >.getRelevantNodes ( final StringReader  input)
inherited

Returns all relevant command nodes for the input, so all nodes that are probably able to parse the input.

Parameters
inputthe input to check for
Returns
all relevant command nodes for the input, so all nodes that are probably able to parse the input

◆ getRequirement()

Predicate< S > com.mojang.brigadier.tree.CommandNode< S >.getRequirement ( )
inherited

Returns the requirement for this command node, that is used by canUse(Object).

Returns
the requirement for this command node, that is used by canUse(Object)

◆ getSortedKey()

String com.mojang.brigadier.tree.LiteralCommandNode< S >.getSortedKey ( )
protected

Returns a key for this command node, that is used for ordering the command nodes.

Returns
a key for this command node, that is used for ordering command nodes

Reimplemented from com.mojang.brigadier.tree.CommandNode< S >.

◆ getUsageText()

String com.mojang.brigadier.tree.LiteralCommandNode< S >.getUsageText ( )

Returns some usage text for this command node.

Returns
some usage text for this command node

Reimplemented from com.mojang.brigadier.tree.CommandNode< S >.

◆ hashCode()

◆ isFork()

boolean com.mojang.brigadier.tree.CommandNode< S >.isFork ( )
inherited

Checks whether this command node forks.

See CommandDispatcher#execute(ParseResults) for an explanation of what it does.

Returns
true if this command node forks

◆ isValidInput()

boolean com.mojang.brigadier.tree.LiteralCommandNode< S >.isValidInput ( final String  input)

Checks if the given input is valid for this command node, i.e.

if it is what the command expects.

This is used to find ambiguities.

Parameters
inputthe input to check
Returns
true if the given input is valid
See also
findAmbiguities

Reimplemented from com.mojang.brigadier.tree.CommandNode< S >.

◆ listSuggestions()

CompletableFuture< Suggestions > com.mojang.brigadier.tree.LiteralCommandNode< S >.listSuggestions ( final CommandContext< S >  context,
final SuggestionsBuilder  builder 
)

Lists suggestions for this command node, given the context and uses the passed SuggestionsBuilder to build them.

Parameters
contextthe CommandContext to use for finding suggestions
builderthe suggestions builder
Returns
a completable future that might complete sometime in the future, as finding suggestions could involve I/O or other slow things
Exceptions
CommandSyntaxExceptionif the command is not well formed

Reimplemented from com.mojang.brigadier.tree.CommandNode< S >.

◆ parse()

void com.mojang.brigadier.tree.LiteralCommandNode< S >.parse ( final StringReader  reader,
final CommandContextBuilder< S >  contextBuilder 
) throws CommandSyntaxException

Tries to parse the command given by the reader and stores the results in the contextBuilder.

Parameters
readerthe reader to read from
contextBuilderthe context builder to store the results in
Exceptions
CommandSyntaxExceptionif the input was malformed

Reimplemented from com.mojang.brigadier.tree.CommandNode< S >.