Class Brigadier

java.lang.Object
dev.jorel.commandapi.Brigadier

public final class Brigadier extends Object
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 Type
    Method
    Description
    static <Argument extends AbstractArgument<?, ?, Argument, ?>>
    com.mojang.brigadier.builder.RequiredArgumentBuilder
    fromArgument(Argument argument)
    Constructs a RequiredArgumentBuilder from a given argument
    static <Argument extends AbstractArgument<?, ?, Argument, ?>>
    com.mojang.brigadier.builder.RequiredArgumentBuilder
    fromArgument(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.Command
    fromCommand(AbstractCommandAPICommand<?,Argument,CommandSender> command)
    Converts a CommandAPICommand into a Brigadier Command
    static <CommandSender, Argument extends AbstractArgument<String, ?, ?, CommandSender>>
    com.mojang.brigadier.builder.LiteralArgumentBuilder
    fromLiteralArgument(Literal<Argument> literalArgument)
    Creates a new literal argument builder from a CommandAPI LiteralArgument
    static <CommandSender, Argument extends AbstractArgument<?, ?, Argument, CommandSender>>
    com.mojang.brigadier.RedirectModifier
    fromPredicate(BiPredicate<CommandSender,Object[]> predicate, List<Argument> args)
    Constructs a RedirectModifier from a predicate that uses a command sender and some arguments.
    static <CommandSender>
    Object
    Gets a Brigadier source object (e.g.
    static com.mojang.brigadier.CommandDispatcher
    Returns the Brigadier CommandDispatcher tree that is used internally by the CommandAPI.
    static <CommandSender>
    CommandSender
    getCommandSenderFromContext(com.mojang.brigadier.context.CommandContext cmdCtx)
    Returns a Bukkit CommandSender from a Brigadier CommandContext
    static com.mojang.brigadier.tree.RootCommandNode
    Returns 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.SuggestionProvider
    toSuggestions(Argument argument, List<Argument> args)
    Converts an argument and a list of arguments to a Brigadier SuggestionProvider

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 running Brigadier.getCommandDispatcher().getRoot();
      Returns:
      The Brigadier CommandDispatcher's root node
    • fromLiteralArgument

      public static <CommandSender, Argument extends AbstractArgument<String, ?, ?, CommandSender>> com.mojang.brigadier.builder.LiteralArgumentBuilder fromLiteralArgument(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<?, ?, Argument, CommandSender>> com.mojang.brigadier.RedirectModifier fromPredicate(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's fork() 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 test
      args - the arguments that the sender has filled in
      Returns:
      a RedirectModifier that encapsulates the provided predicate
    • fromCommand

      public static <Argument extends AbstractArgument<?, ?, Argument, CommandSender>, CommandSender> com.mojang.brigadier.Command fromCommand(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<?, ?, Argument, ?>> com.mojang.brigadier.builder.RequiredArgumentBuilder fromArgument(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 commands
      argument - the argument you want to specify
      Returns:
      a RequiredArgumentBuilder that represents the provided argument
    • fromArgument

      public static <Argument extends AbstractArgument<?, ?, Argument, ?>> com.mojang.brigadier.builder.RequiredArgumentBuilder fromArgument(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<?, ?, Argument, ?>> com.mojang.brigadier.suggestion.SuggestionProvider toSuggestions(Argument argument, List<Argument> args)
      Converts an argument and a list of arguments to a Brigadier SuggestionProvider
      Parameters:
      argument - the argument to convert to suggestions
      args - the list of arguments
      Returns:
      a SuggestionProvider that suggests the overridden suggestions for the specified argument
    • parseArguments

      public static <Argument extends AbstractArgument<?, ?, Argument, ?>> 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 arguments
      args - 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

      public static <CommandSender> Object getBrigadierSourceFromCommandSender(CommandSender sender)
      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