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 <Argument extends AbstractArgument<?,?, Argument, ?>>
com.mojang.brigadier.builder.RequiredArgumentBuilderfromArgument(Argument argument) Constructs a RequiredArgumentBuilder from a given argumentstatic <Argument extends AbstractArgument<?,?, Argument, ?>>
com.mojang.brigadier.builder.RequiredArgumentBuilderfromArgument(List<Argument> args, Argument argument) Constructs a RequiredArgumentBuilder from a given argument within a command declaration.static <Argument extends AbstractArgument<?,?, Argument, CommandSender>, CommandSender>
com.mojang.brigadier.CommandfromCommand(AbstractCommandAPICommand<?, Argument, CommandSender> command) Converts a CommandAPICommand into a Brigadier Commandstatic <CommandSender,Argument extends AbstractArgument<String, ?, ?, CommandSender>>
com.mojang.brigadier.builder.LiteralArgumentBuilderfromLiteralArgument(Literal<Argument> literalArgument) Creates a new literal argument builder from a CommandAPI LiteralArgumentstatic <CommandSender,Argument extends AbstractArgument<?, ?, Argument, CommandSender>>
com.mojang.brigadier.RedirectModifierfromPredicate(BiPredicate<CommandSender, Object[]> predicate, List<Argument> args) Constructs a RedirectModifier from a predicate that uses a command sender and some arguments.static <CommandSender>
ObjectgetBrigadierSourceFromCommandSender(CommandSender sender) Gets a Brigadier source object (e.g.static com.mojang.brigadier.CommandDispatcherReturns the Brigadier CommandDispatcher tree that is used internally by the CommandAPI.static <CommandSender>
CommandSendergetCommandSenderFromContext(com.mojang.brigadier.context.CommandContext cmdCtx) Returns a Bukkit CommandSender from a Brigadier CommandContextstatic com.mojang.brigadier.tree.RootCommandNodeReturns the root node of the current CommandDispatcher.static <Argument extends AbstractArgument<?,?, Argument, ?>>
Object[]parseArguments(com.mojang.brigadier.context.CommandContext cmdCtx, List<Argument> args) Parses arguments into their respective objects with a given command context.static <Argument extends AbstractArgument<?,?, Argument, ?>>
com.mojang.brigadier.suggestion.SuggestionProvidertoSuggestions(Argument argument, List<Argument> args) Converts an argument 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 <CommandSender,Argument extends AbstractArgument<String, com.mojang.brigadier.builder.LiteralArgumentBuilder fromLiteralArgument?, ?, CommandSender>> (Literal<Argument> 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 <CommandSender,Argument extends AbstractArgument<?, com.mojang.brigadier.RedirectModifier fromPredicate?, Argument, CommandSender>> (BiPredicate<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
public static <Argument extends AbstractArgument<?,?, com.mojang.brigadier.Command fromCommandArgument, CommandSender>, CommandSender> (AbstractCommandAPICommand<?, Argument, CommandSender> command) 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 <Argument extends AbstractArgument<?,?, com.mojang.brigadier.builder.RequiredArgumentBuilder fromArgumentArgument, ?>> (List<Argument> args, Argument argument) 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 commandsargument- the argument you want to specify- Returns:
- a RequiredArgumentBuilder that represents the provided argument
-
fromArgument
public static <Argument extends AbstractArgument<?,?, com.mojang.brigadier.builder.RequiredArgumentBuilder fromArgumentArgument, ?>> (Argument argument) 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 <Argument extends AbstractArgument<?,?, com.mojang.brigadier.suggestion.SuggestionProvider toSuggestionsArgument, ?>> (Argument argument, List<Argument> args) Converts an argument and a list of arguments to a Brigadier SuggestionProvider- Parameters:
argument- the argument to convert to suggestionsargs- the list of arguments- Returns:
- a SuggestionProvider that suggests the overridden suggestions for the specified argument
-
parseArguments
public static <Argument extends AbstractArgument<?,?, Object[] parseArgumentsArgument, ?>> (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
-
getCommandSenderFromContext
public static <CommandSender> CommandSender getCommandSenderFromContext(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
-