Package dev.jorel.commandapi
Class Brigadier
java.lang.Object
dev.jorel.commandapi.Brigadier
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.mojang.brigadier.builder.RequiredArgumentBuilderfromArgument(Argument argument) Constructs a RequiredArgumentBuilder from a given argumentstatic com.mojang.brigadier.builder.RequiredArgumentBuilderfromArgument(List<Argument> args, String nodeName) Constructs a RequiredArgumentBuilder from a given argument within a command declaration.static com.mojang.brigadier.CommandfromCommand(CommandAPICommand command) Converts a CommandAPICommand into a Brigadier Commandstatic com.mojang.brigadier.builder.LiteralArgumentBuilderfromLiteralArgument(LiteralArgument literalArgument) Creates a new literal argument builder from a CommandAPI LiteralArgumentstatic com.mojang.brigadier.RedirectModifierfromPredicate(BiPredicate<org.bukkit.command.CommandSender, Object[]> predicate, List<Argument> args) Constructs a RedirectModifier from a predicate that uses a command sender and some arguments.static ObjectgetBrigadierSourceFromCommandSender(org.bukkit.command.CommandSender sender) Gets a Brigadier source object (e.g.static org.bukkit.command.CommandSendergetBukkitCommandSenderFromContext(com.mojang.brigadier.context.CommandContext cmdCtx) Returns a Bukkit CommandSender from a Brigadier CommandContextstatic com.mojang.brigadier.CommandDispatcherReturns the Brigadier CommandDispatcher tree that is used internally by the CommandAPI.static com.mojang.brigadier.tree.RootCommandNodeReturns the root node of the current CommandDispatcher.static Object[]parseArguments(com.mojang.brigadier.context.CommandContext cmdCtx, List<Argument> args) Parses arguments into their respective objects with a given command context.static com.mojang.brigadier.suggestion.SuggestionProvidertoSuggestions(String nodeName, List<Argument> args) Converts an argument name and a list of arguments to a Brigadier SuggestionProvider
-
Method Details
-
getCommandDispatcher
public static com.mojang.brigadier.CommandDispatcher getCommandDispatcher()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
-
getRootNode
public static com.mojang.brigadier.tree.RootCommandNode getRootNode()Returns the root node of the current CommandDispatcher. This is the equivalent of runningBrigadier.getCommandDispatcher().getRoot();- Returns:
- The Brigadier CommandDispatcher's root node
-
fromLiteralArgument
public static com.mojang.brigadier.builder.LiteralArgumentBuilder fromLiteralArgument(LiteralArgument literalArgument) Creates a new literal argument builder from a CommandAPI LiteralArgument- Parameters:
literalArgument- the LiteralArgument to convert from- Returns:
- a LiteralArgumentBuilder that represents the literal
-
fromPredicate
public static com.mojang.brigadier.RedirectModifier fromPredicate(BiPredicate<org.bukkit.command.CommandSender, Object[]> predicate, List<Argument> args) Constructs a RedirectModifier from a predicate that uses a command sender and some arguments. RedirectModifiers can be used with Brigadier'sfork()method to invoke other nodes in the CommandDispatcher tree. You would use this method as shown:Brigadier.fromPredicate((sender, args) -> { ... }, arguments);- Parameters:
predicate- the predicate to testargs- the arguments that the sender has filled in- Returns:
- a RedirectModifier that encapsulates the provided predicate
-
fromCommand
Converts a CommandAPICommand into a Brigadier Command- Parameters:
command- the command to convert- Returns:
- a Brigadier Command object that represents the provided command
-
fromArgument
public static com.mojang.brigadier.builder.RequiredArgumentBuilder fromArgument(List<Argument> args, String nodeName) 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:
args- the List of arguments which you typically declare for commandsnodeName- the name of the argument you want to specify- Returns:
- a RequiredArgumentBuilder that represents the provided argument
-
fromArgument
Constructs a RequiredArgumentBuilder from a given argument- Parameters:
argument- the argument to create a RequiredArgumentBuilder from- Returns:
- a RequiredArgumentBuilder that represents the provided argument
-
toSuggestions
public static com.mojang.brigadier.suggestion.SuggestionProvider toSuggestions(String nodeName, List<Argument> args) Converts an argument name and a list of arguments to a Brigadier SuggestionProvider- Parameters:
nodeName- the name (prompt) of the argument as declared by its node nameargs- the list of arguments- Returns:
- a SuggestionProvider that suggests the overridden suggestions for the argument declared in the List with key argumentName
-
parseArguments
public static Object[] parseArguments(com.mojang.brigadier.context.CommandContext cmdCtx, List<Argument> args) throws com.mojang.brigadier.exceptions.CommandSyntaxException 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:
cmdCtx- the command context used to parse the command argumentsargs- the list of arguments to parse- Returns:
- an array of Objects which hold the results of the argument parsing step
- Throws:
com.mojang.brigadier.exceptions.CommandSyntaxException- if there was an error during parsing
-
getBrigadierSourceFromCommandSender
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:
sender- the Bukkit CommandSender to convert into a Brigadier source object- Returns:
- a Brigadier source object representing the provided Bukkit CommandSender
-
getBukkitCommandSenderFromContext
public static org.bukkit.command.CommandSender getBukkitCommandSenderFromContext(com.mojang.brigadier.context.CommandContext cmdCtx) Returns a Bukkit CommandSender from a Brigadier CommandContext- Parameters:
cmdCtx- the command context to get the CommandSender from- Returns:
- a Bukkit CommandSender from the provided Brigadier CommandContext
-