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

A general container class storing information needed to invoke a command. More...

Public Member Functions

 CommandContext (final S source, final String input, final Map< String, ParsedArgument< S, ?> > arguments, final Command< S > command, final CommandNode< S > rootNode, final List< ParsedCommandNode< S > > nodes, final StringRange range, final CommandContext< S > child, final RedirectModifier< S > modifier, boolean forks)
 Creates a new CommandContext. More...
 
CommandContext< S > copyFor (final S source)
 Creates a copy of this CommandContext with a different command source but otherwise identical. More...
 
CommandContext< S > getChild ()
 Returns the child context, if it is present. More...
 
CommandContext< S > getLastChild ()
 Returns the last child command context in the chain, i.e. More...
 
Command< S > getCommand ()
 Returns the command that should be executed. More...
 
getSource ()
 The command source to invoke the command for. More...
 
boolean equals (final Object o)
 
int hashCode ()
 
RedirectModifier< S > getRedirectModifier ()
 Returns the RedirectModifier to apply when invoking the command. More...
 
StringRange getRange ()
 Returns the range this context takes up in the input string. More...
 
String getInput ()
 Returns the full input, of which this command context is a part. More...
 
CommandNode< S > getRootNode ()
 Returns the root command node in the command tree. More...
 
List< ParsedCommandNode< S > > getNodes ()
 Returns all nodes associated with this context. More...
 
boolean hasNodes ()
 Returns true if this context has any CommandNode associated with it. More...
 
boolean isForked ()
 Returns true if this command is forked. More...
 

Detailed Description

A general container class storing information needed to invoke a command.

This consists of e.g. the command source to invoke it for, the command to invoke, child contexts (for subcommands) or arguments parsed by ArgumentTypes.


This class is immutable. Use copyFor(Object) to create copies with a different command source.

Parameters
<S>the type of the command source

Constructor & Destructor Documentation

◆ CommandContext()

com.mojang.brigadier.context.CommandContext< S >.CommandContext ( final S  source,
final String  input,
final Map< String, ParsedArgument< S, ?> >  arguments,
final Command< S >  command,
final CommandNode< S >  rootNode,
final List< ParsedCommandNode< S > >  nodes,
final StringRange  range,
final CommandContext< S >  child,
final RedirectModifier< S >  modifier,
boolean  forks 
)

Creates a new CommandContext.

Parameters
sourcethe command source to invoke the command for
inputthe full input
argumentsthe parsed arguments
commandthe command to invoke
rootNodethe root node of the command tree
nodesall nodes associated with this context
rangethe string range indicating what part in the input this context covers
childthe child context, or null if none
modifierthe RedirectModifier to apply when invoking the command
forkswhether this command forks. See CommandDispatcher#execute(ParseResults) for an explanation

Member Function Documentation

◆ copyFor()

CommandContext< S > com.mojang.brigadier.context.CommandContext< S >.copyFor ( final S  source)

Creates a copy of this CommandContext with a different command source but otherwise identical.

Parameters
sourcethe command source to copy it for
Returns
a CommandContext that is identical to this one, except for the command source

◆ getChild()

Returns the child context, if it is present.

Returns
the child context, or null if there is none

◆ getCommand()

Returns the command that should be executed.

Returns
the command to execute or null if not set

◆ getInput()

Returns the full input, of which this command context is a part.

Returns
the full input, of which this command context is a part

◆ getLastChild()

Returns the last child command context in the chain, i.e.

the lowest child you can reach from this context.

As each CommandContext can have a child, you can have a child of a child. This method returns the lowest possible child you can reach, i.e. the last command context that has no children. This can be this command context instance, if it has no child.

Returns
the last child command context

◆ getNodes()

Returns all nodes associated with this context.

That is the node that getCommand() comes from any anything else that nodes pushes onto it in its CommandNode#parse method.

TODO: Why is this a List?

Returns
all nodes associated with this context

◆ getRange()

Returns the range this context takes up in the input string.

Returns
the range this context takes up in the input string

◆ getRedirectModifier()

Returns the RedirectModifier to apply when invoking the command.

Returns
the RedirectModifier to apply when invoking the command or null if none is set

◆ getRootNode()

Returns the root command node in the command tree.

Returns
the root command node in the command tree

◆ getSource()

The command source to invoke the command for.

Returns
the command source to invoke the command for

◆ hasNodes()

Returns true if this context has any CommandNode associated with it.

Returns
true if this context has any CommandNode associated with it

◆ isForked()

Returns true if this command is forked.

See CommandDispatcher#execute(ParseResults) for a detailed explanation.

Returns
true if this command is forked
See also
CommandDispatcher::execute(ParseResults)