Class CloudBrigadierManager<C,​S>

  • Type Parameters:
    C - Command sender type
    S - Brigadier sender type

    public final class CloudBrigadierManager<C,​S>
    extends java.lang.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 java.util.function.Supplier<@NonNull cloud.commandframework.context.CommandContext<C>> dummyContextProvider)
      Create a new cloud brigadier manager
    • Method Summary

      Modifier and Type Method Description
      @Nullable java.util.function.Function<@NonNull S,​@Nullable C> brigadierSenderMapper()
      Get the mapper between Brigadier and Cloud command senders, if one exists
      void brigadierSenderMapper​(@NonNull java.util.function.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 java.util.function.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 java.lang.String label, @NonNull cloud.commandframework.Command<C> cloudCommand, @NonNull java.util.function.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 java.lang.Class<?> clazz, @NonNull java.util.function.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 java.util.function.Function<? extends K,​? extends com.mojang.brigadier.arguments.ArgumentType<O>> mapper)
      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 Detail

      • CloudBrigadierManager

        public CloudBrigadierManager​(@NonNull cloud.commandframework.CommandManager<C> commandManager,
                                     @NonNull java.util.function.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 Detail

      • brigadierSenderMapper

        public void brigadierSenderMapper​(@NonNull java.util.function.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 java.util.function.Function<@NonNull S,​@Nullable C> brigadierSenderMapper()
        Get the mapper between Brigadier and Cloud command senders, if one exists
        Returns:
        Mapper
        Since:
        1.2.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 java.lang.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:
        java.lang.IllegalArgumentException - when there is no mapper registered for the provided argument type
        Since:
        1.2.0
      • registerMapping

        public <T,​K extends cloud.commandframework.arguments.parser.ArgumentParser<C,​T>,​O> void registerMapping​(@NonNull io.leangen.geantyref.TypeToken<K> argumentType,
                                                                                                                                  boolean nativeSuggestions,
                                                                                                                                  @NonNull java.util.function.Function<? extends K,​? extends com.mojang.brigadier.arguments.ArgumentType<O>> mapper)
        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 type
        nativeSuggestions - Whether or not Brigadier suggestions should be used
        mapper - mapper function
      • registerDefaultArgumentTypeSupplier

        public void registerDefaultArgumentTypeSupplier​(@NonNull java.lang.Class<?> clazz,
                                                        @NonNull java.util.function.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 java.lang.String label,
                                                                                                 @NonNull cloud.commandframework.Command<C> cloudCommand,
                                                                                                 @NonNull java.util.function.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 java.util.function.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