Class CloudBrigadierManager<C,S>

java.lang.Object
cloud.commandframework.brigadier.CloudBrigadierManager<C,S>
Type Parameters:
C - Command sender type
S - Brigadier sender type

public final class CloudBrigadierManager<C,S> extends Object
Manager used to map cloud Command

The structure of this class is largely inspired by ACFBrigadiermanager in the ACF project, which was originally written by MiniDigger and licensed under the MIT license.

  • Constructor Summary

    Constructors
    Constructor
    Description
    CloudBrigadierManager(@NonNull cloud.commandframework.CommandManager<C> commandManager, @NonNull Supplier<@NonNull cloud.commandframework.context.CommandContext<C>> dummyContextProvider)
    Create a new cloud brigadier manager
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    backwardsBrigadierSenderMapper(@NonNull Function<@NonNull C,@Nullable S> mapper)
    Set the backwards mapper from Cloud to Brigadier command senders.
    @Nullable Function<@NonNull S,@Nullable C>
    Get the mapper between Brigadier and Cloud command senders, if one exists
    void
    brigadierSenderMapper(@NonNull Function<@NonNull S,@Nullable C> mapper)
    Set the mapper between the Brigadier command sender type and the Cloud command sender type
    @NonNull com.mojang.brigadier.tree.LiteralCommandNode<S>
    createLiteralCommandNode(@NonNull cloud.commandframework.CommandTree.Node<@NonNull cloud.commandframework.arguments.CommandArgument<C,?>> cloudCommand, @NonNull com.mojang.brigadier.tree.LiteralCommandNode<S> root, @NonNull com.mojang.brigadier.suggestion.SuggestionProvider<S> suggestionProvider, @NonNull com.mojang.brigadier.Command<S> executor, @NonNull BiPredicate<@NonNull S,@NonNull cloud.commandframework.permission.CommandPermission> permissionChecker)
    Create a literal command from Brigadier command info, and a cloud command instance
    @NonNull com.mojang.brigadier.tree.LiteralCommandNode<S>
    createLiteralCommandNode(@NonNull String label, @NonNull cloud.commandframework.Command<C> cloudCommand, @NonNull BiPredicate<@NonNull S,@NonNull cloud.commandframework.permission.CommandPermission> permissionChecker, boolean forceRegister, @NonNull com.mojang.brigadier.Command<S> executor)
    Create a new literal command node
    void
    registerDefaultArgumentTypeSupplier(@NonNull Class<?> clazz, @NonNull Supplier<@Nullable com.mojang.brigadier.arguments.ArgumentType<?>> supplier)
    Register a default mapping to between a class and a Brigadier argument type
    <T, K extends cloud.commandframework.arguments.parser.ArgumentParser<C, T>, O>
    void
    registerMapping(@NonNull io.leangen.geantyref.TypeToken<K> argumentType, boolean nativeSuggestions, @NonNull Function<@NonNull ? extends K,@NonNull ? extends com.mojang.brigadier.arguments.ArgumentType<O>> mapper)
    Deprecated.
    for removal since 1.5.0, use registerMapping(TypeToken, Consumer) instead.
    <K extends cloud.commandframework.arguments.parser.ArgumentParser<C, ?>>
    void
    registerMapping(@NonNull io.leangen.geantyref.TypeToken<K> parserType, Consumer<BrigadierMappingBuilder<K,S>> configurer)
    Register a cloud-Brigadier mapping.
    void
    setNativeNumberSuggestions(boolean nativeNumberSuggestions)
    Set whether to use Brigadier's native suggestions for number argument types.
    <T, K extends cloud.commandframework.arguments.parser.ArgumentParser<C, T>>
    void
    setNativeSuggestions(@NonNull io.leangen.geantyref.TypeToken<K> argumentType, boolean nativeSuggestions)
    Set whether to use Brigadier's native suggestions for an argument type with an already registered mapper.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CloudBrigadierManager

      public CloudBrigadierManager(@NonNull cloud.commandframework.CommandManager<C> commandManager, @NonNull Supplier<@NonNull cloud.commandframework.context.CommandContext<C>> dummyContextProvider)
      Create a new cloud brigadier manager
      Parameters:
      commandManager - Command manager
      dummyContextProvider - Provider of dummy context for completions
  • Method Details

    • brigadierSenderMapper

      public void brigadierSenderMapper(@NonNull Function<@NonNull S,@Nullable C> mapper)
      Set the mapper between the Brigadier command sender type and the Cloud command sender type
      Parameters:
      mapper - Mapper
      Since:
      1.2.0
    • brigadierSenderMapper

      public @Nullable Function<@NonNull S,@Nullable C> brigadierSenderMapper()
      Get the mapper between Brigadier and Cloud command senders, if one exists
      Returns:
      Mapper
      Since:
      1.2.0
    • backwardsBrigadierSenderMapper

      public void backwardsBrigadierSenderMapper(@NonNull Function<@NonNull C,@Nullable S> mapper)
      Set the backwards mapper from Cloud to Brigadier command senders.

      This is passed to completion requests for mapped argument types.

      Parameters:
      mapper - the reverse brigadier sender mapper
      Since:
      1.5.0
    • setNativeNumberSuggestions

      public void setNativeNumberSuggestions(boolean nativeNumberSuggestions)
      Set whether to use Brigadier's native suggestions for number argument types.

      If Brigadier's suggestions are not used, cloud's default number suggestion provider will be used.

      Parameters:
      nativeNumberSuggestions - Whether or not Brigadier suggestions should be used for numbers
      Since:
      1.2.0
    • setNativeSuggestions

      public <T, K extends cloud.commandframework.arguments.parser.ArgumentParser<C, T>> void setNativeSuggestions(@NonNull io.leangen.geantyref.TypeToken<K> argumentType, boolean nativeSuggestions) throws IllegalArgumentException
      Set whether to use Brigadier's native suggestions for an argument type with an already registered mapper.

      If Brigadier's suggestions are not used, suggestions will fall back to the cloud suggestion provider.

      Type Parameters:
      T - argument type
      K - cloud argument parser type
      Parameters:
      argumentType - cloud argument parser type
      nativeSuggestions - Whether or not Brigadier suggestions should be used
      Throws:
      IllegalArgumentException - when there is no mapper registered for the provided argument type
      Since:
      1.2.0
    • registerMapping

      @Deprecated public <T, K extends cloud.commandframework.arguments.parser.ArgumentParser<C, T>, O> void registerMapping(@NonNull io.leangen.geantyref.TypeToken<K> argumentType, boolean nativeSuggestions, @NonNull Function<@NonNull ? extends K,@NonNull ? extends com.mojang.brigadier.arguments.ArgumentType<O>> mapper)
      Deprecated.
      for removal since 1.5.0, use registerMapping(TypeToken, Consumer) instead.
      Register a cloud-Brigadier mapping
      Type Parameters:
      T - cloud argument value type
      K - cloud argument type
      O - Brigadier argument type value
      Parameters:
      argumentType - cloud argument parser type
      nativeSuggestions - Whether or not Brigadier suggestions should be used
      mapper - mapper function
    • registerMapping

      public <K extends cloud.commandframework.arguments.parser.ArgumentParser<C, ?>> void registerMapping(@NonNull io.leangen.geantyref.TypeToken<K> parserType, Consumer<BrigadierMappingBuilder<K,S>> configurer)
      Register a cloud-Brigadier mapping.
      Type Parameters:
      K - cloud argument parser type
      Parameters:
      parserType - The cloud argument parser type
      configurer - a callback that will configure the mapping attributes
      Since:
      1.5.0
    • registerDefaultArgumentTypeSupplier

      public void registerDefaultArgumentTypeSupplier(@NonNull Class<?> clazz, @NonNull Supplier<@Nullable com.mojang.brigadier.arguments.ArgumentType<?>> supplier)
      Register a default mapping to between a class and a Brigadier argument type
      Parameters:
      clazz - Type to map
      supplier - Supplier that supplies the argument type
    • createLiteralCommandNode

      public @NonNull com.mojang.brigadier.tree.LiteralCommandNode<S> createLiteralCommandNode(@NonNull String label, @NonNull cloud.commandframework.Command<C> cloudCommand, @NonNull BiPredicate<@NonNull S,@NonNull cloud.commandframework.permission.CommandPermission> permissionChecker, boolean forceRegister, @NonNull com.mojang.brigadier.Command<S> executor)
      Create a new literal command node
      Parameters:
      label - Command label
      cloudCommand - Cloud command instance
      permissionChecker - Permission checker
      forceRegister - Whether or not to force register an executor at every node
      executor - Command executor
      Returns:
      Literal command node
    • createLiteralCommandNode

      public @NonNull com.mojang.brigadier.tree.LiteralCommandNode<S> createLiteralCommandNode(@NonNull cloud.commandframework.CommandTree.Node<@NonNull cloud.commandframework.arguments.CommandArgument<C,?>> cloudCommand, @NonNull com.mojang.brigadier.tree.LiteralCommandNode<S> root, @NonNull com.mojang.brigadier.suggestion.SuggestionProvider<S> suggestionProvider, @NonNull com.mojang.brigadier.Command<S> executor, @NonNull BiPredicate<@NonNull S,@NonNull cloud.commandframework.permission.CommandPermission> permissionChecker)
      Create a literal command from Brigadier command info, and a cloud command instance
      Parameters:
      cloudCommand - Cloud root command
      root - Brigadier root command
      suggestionProvider - Brigadier suggestions provider
      executor - Brigadier command executor
      permissionChecker - Permission checker
      Returns:
      Constructed literal command node