CommandAPI 9.3.0
An API for the command UI introduced in Minecraft 1.13
dev.jorel.commandapi.Brigadier Class Reference

The Brigadier class is used to access some of the internals of the CommandAPI so you can use the CommandAPI alongside Mojang's com.mojang.brigadier package. More...

Static Public Member Functions

static CommandDispatcher getCommandDispatcher ()
 Returns the Brigadier CommandDispatcher tree that is used internally by the CommandAPI. More...
 
static RootCommandNode getRootNode ()
 Returns the root node of the current CommandDispatcher. More...
 
static< CommandSender, Argument extends AbstractArgument< String, ?, ?, CommandSender > LiteralArgumentBuilder fromLiteralArgument (Literal< Argument > literalArgument)
 Creates a new literal argument builder from a CommandAPI LiteralArgument. More...
 
static< CommandSender, Argument extends AbstractArgument<?, ?, Argument, CommandSender > RedirectModifier fromPredicate (BiPredicate< CommandSender, Object[]> predicate, List< Argument > args)
 Constructs a RedirectModifier from a predicate that uses a command sender and some arguments. More...
 
static< Argument extends AbstractArgument<?, ?, Argument, CommandSender > CommandSender Command fromCommand (AbstractCommandAPICommand<?, Argument, CommandSender > command)
 
static< Argument extends AbstractArgument<?, ?, Argument, ?> RequiredArgumentBuilder fromArgument (List< Argument > args, Argument argument)
 Constructs a RequiredArgumentBuilder from a given argument within a command declaration. More...
 
static< Argument extends AbstractArgument<?, ?, Argument, ?> RequiredArgumentBuilder fromArgument (Argument argument)
 Constructs a RequiredArgumentBuilder from a given argument. More...
 
static< Argument extends AbstractArgument<?, ?, Argument, ?> SuggestionProvider toSuggestions (Argument argument, List< Argument > args)
 Converts an argument and a list of arguments to a Brigadier SuggestionProvider. More...
 
static< Argument extends AbstractArgument<?, ?, Argument, ?> Object[] parseArguments (CommandContext cmdCtx, List< Argument > args) throws CommandSyntaxException
 Parses arguments into their respective objects with a given command context. More...
 
static< CommandSender > Object getBrigadierSourceFromCommandSender (CommandSender sender)
 Gets a Brigadier source object (e.g. More...
 
static< CommandSender > CommandSender getCommandSenderFromContext (CommandContext cmdCtx)
 Returns a Bukkit CommandSender from a Brigadier CommandContext. More...
 

Detailed Description

The Brigadier class is used to access some of the internals of the CommandAPI so you can use the CommandAPI alongside Mojang's com.mojang.brigadier package.

Member Function Documentation

◆ fromArgument() [1/2]

static< Argument extends AbstractArgument<?, ?, Argument, ?> RequiredArgumentBuilder dev.jorel.commandapi.Brigadier.fromArgument ( Argument  argument)
static

Constructs a RequiredArgumentBuilder from a given argument.

Parameters
argumentthe argument to create a RequiredArgumentBuilder from
Returns
a RequiredArgumentBuilder that represents the provided argument

◆ fromArgument() [2/2]

static< Argument extends AbstractArgument<?, ?, Argument, ?> RequiredArgumentBuilder dev.jorel.commandapi.Brigadier.fromArgument ( List< Argument args,
Argument  argument 
)
static

Constructs a RequiredArgumentBuilder from a given argument within a command declaration.

For example:

List<Argument> arguments = new ArrayList<>();
arguments.add(new IntegerArgument("hello"));

RequiredArgumentBuilder argBuilder = Brigadier.fromArguments(arguments, "hello");
Parameters
argsthe List of arguments which you typically declare for commands
argumentthe argument you want to specify
Returns
a RequiredArgumentBuilder that represents the provided argument

◆ fromLiteralArgument()

static< CommandSender, Argument extends AbstractArgument< String, ?, ?, CommandSender > LiteralArgumentBuilder dev.jorel.commandapi.Brigadier.fromLiteralArgument ( Literal< Argument literalArgument)
static

Creates a new literal argument builder from a CommandAPI LiteralArgument.

Parameters
literalArgumentthe LiteralArgument to convert from
Returns
a LiteralArgumentBuilder that represents the literal

◆ fromPredicate()

static< CommandSender, Argument extends AbstractArgument<?, ?, Argument, CommandSender > RedirectModifier dev.jorel.commandapi.Brigadier.fromPredicate ( BiPredicate< CommandSender, Object[]>  predicate,
List< Argument args 
)
static

Constructs a RedirectModifier from a predicate that uses a command sender and some arguments.

RedirectModifiers can be used with Brigadier's fork() method to invoke other nodes in the CommandDispatcher tree. You would use this method as shown:

Brigadier.fromPredicate((sender, args) -> {
    ...
}, arguments);
Parameters
predicatethe predicate to test
argsthe arguments that the sender has filled in
Returns
a RedirectModifier that encapsulates the provided predicate

◆ getBrigadierSourceFromCommandSender()

static< CommandSender > Object dev.jorel.commandapi.Brigadier.getBrigadierSourceFromCommandSender ( CommandSender  sender)
static

Gets a Brigadier source object (e.g.

CommandListenerWrapper or CommandSourceStack) from a Bukkit CommandSender. This source object is the same object you would get from a command context.

Parameters
senderthe Bukkit CommandSender to convert into a Brigadier source object
Returns
a Brigadier source object representing the provided Bukkit CommandSender

◆ getCommandDispatcher()

static CommandDispatcher dev.jorel.commandapi.Brigadier.getCommandDispatcher ( )
static

Returns the Brigadier CommandDispatcher tree that is used internally by the CommandAPI.

Modifying this CommandDispatcher tree before the server finishes loading will still keep any changes made to it. For example, adding a new node to this tree will keep the node once the server has finished loading.

Returns
The CommandAPI's internal CommandDispatcher instance

◆ getCommandSenderFromContext()

static< CommandSender > CommandSender dev.jorel.commandapi.Brigadier.getCommandSenderFromContext ( CommandContext  cmdCtx)
static

Returns a Bukkit CommandSender from a Brigadier CommandContext.

Parameters
cmdCtxthe command context to get the CommandSender from
Returns
a Bukkit CommandSender from the provided Brigadier CommandContext

◆ getRootNode()

static RootCommandNode dev.jorel.commandapi.Brigadier.getRootNode ( )
static

Returns the root node of the current CommandDispatcher.

This is the equivalent of running

Brigadier.getCommandDispatcher().getRoot();

Returns
The Brigadier CommandDispatcher's root node

◆ parseArguments()

static< Argument extends AbstractArgument<?, ?, Argument, ?> Object[] dev.jorel.commandapi.Brigadier.parseArguments ( CommandContext  cmdCtx,
List< Argument args 
) throws CommandSyntaxException
static

Parses arguments into their respective objects with a given command context.

This method effectively performs the "parse" step in an argument's class and returns an Object[] which maps directly to the input List with the values generated via parsing.

Parameters
cmdCtxthe command context used to parse the command arguments
argsthe list of arguments to parse
Returns
an array of Objects which hold the results of the argument parsing step
Exceptions
CommandSyntaxExceptionif there was an error during parsing

◆ toSuggestions()

static< Argument extends AbstractArgument<?, ?, Argument, ?> SuggestionProvider dev.jorel.commandapi.Brigadier.toSuggestions ( Argument  argument,
List< Argument args 
)
static

Converts an argument and a list of arguments to a Brigadier SuggestionProvider.

Parameters
argumentthe argument to convert to suggestions
argsthe list of arguments
Returns
a SuggestionProvider that suggests the overridden suggestions for the specified argument