Class BukkitCommandManager<C>

  • Type Parameters:
    C - Command sender type
    All Implemented Interfaces:
    cloud.commandframework.brigadier.BrigadierManagerHolder<C>

    public class BukkitCommandManager<C>
    extends cloud.commandframework.CommandManager<C>
    implements cloud.commandframework.brigadier.BrigadierManagerHolder<C>
    Command manager for the Bukkit platform
    • Constructor Summary

      Constructors 
      Constructor Description
      BukkitCommandManager​(@NonNull org.bukkit.plugin.Plugin owningPlugin, @NonNull java.util.function.Function<@NonNull cloud.commandframework.CommandTree<C>,​@NonNull cloud.commandframework.execution.CommandExecutionCoordinator<C>> commandExecutionCoordinator, @NonNull java.util.function.Function<@NonNull org.bukkit.command.CommandSender,​@NonNull C> commandSenderMapper, @NonNull java.util.function.Function<@NonNull C,​@NonNull org.bukkit.command.CommandSender> backwardsCommandSenderMapper)
      Construct a new Bukkit command manager
    • Method Summary

      Modifier and Type Method Description
      @Nullable cloud.commandframework.brigadier.CloudBrigadierManager<C,​?> brigadierManager()
      protected void checkBrigadierCompatibility()
      Check whether or not Brigadier can be used on the server instance
      @NonNull BukkitCommandMeta createDefaultCommandMeta()
      Create default command meta data
      @NonNull java.util.function.Function<@NonNull C,​@NonNull org.bukkit.command.CommandSender> getBackwardsCommandSenderMapper()
      Get the backwards command sender plugin
      @NonNull java.util.function.Function<@NonNull org.bukkit.command.CommandSender,​@NonNull C> getCommandSenderMapper()
      Get the command sender mapper
      @NonNull org.bukkit.plugin.Plugin getOwningPlugin()
      Get the plugin that owns the manager
      protected boolean getSplitAliases()  
      boolean hasPermission​(@NonNull C sender, @NonNull java.lang.String permission)  
      @NonNull java.util.Set<@NonNull CloudBukkitCapabilities> queryCapabilities()
      Check for the platform capabilities
      boolean queryCapability​(@NonNull CloudBukkitCapabilities capability)
      Query for a specific capability
      void registerBrigadier()
      Attempt to register the Brigadier mapper, and return it.
      protected void setSplitAliases​(boolean value)  
      @NonNull java.lang.String stripNamespace​(@NonNull java.lang.String command)
      Strip the plugin namespace from a plugin namespaced command.
      @NonNull cloud.commandframework.tasks.TaskRecipe taskRecipe()
      Create a new task recipe.
      • Methods inherited from class cloud.commandframework.CommandManager

        argumentBuilder, command, command, commandBuilder, commandBuilder, commandBuilder, commandBuilder, commandBuilder, commandBuilder, executeCommand, flagBuilder, getCaptionRegistry, getCommandHelpHandler, getCommandRegistrationHandler, getCommands, getCommandSuggestionProcessor, getCommandSyntaxFormatter, getCommandTree, getExceptionHandler, getParserRegistry, getRegistrationState, getSetting, handleException, hasPermission, isCommandRegistrationAllowed, parameterInjectorRegistry, postprocessContext, preprocessContext, registerCommandPostProcessor, registerCommandPreProcessor, registerDefaultCaptions, registerExceptionHandler, requireState, setCaptionRegistry, setCommandRegistrationHandler, setCommandSuggestionProcessor, setCommandSyntaxFormatter, setSetting, suggest, transitionIfPossible, transitionOrThrow
      • Methods inherited from class java.lang.Object

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

      • BukkitCommandManager

        public BukkitCommandManager​(@NonNull org.bukkit.plugin.Plugin owningPlugin,
                                    @NonNull java.util.function.Function<@NonNull cloud.commandframework.CommandTree<C>,​@NonNull cloud.commandframework.execution.CommandExecutionCoordinator<C>> commandExecutionCoordinator,
                                    @NonNull java.util.function.Function<@NonNull org.bukkit.command.CommandSender,​@NonNull C> commandSenderMapper,
                                    @NonNull java.util.function.Function<@NonNull C,​@NonNull org.bukkit.command.CommandSender> backwardsCommandSenderMapper)
                             throws java.lang.Exception
        Construct a new Bukkit command manager
        Parameters:
        owningPlugin - Plugin that is constructing the manager. This will be used when registering the commands to the Bukkit command map.
        commandExecutionCoordinator - Execution coordinator instance. The coordinator is in charge of executing incoming commands. Some considerations must be made when picking a suitable execution coordinator. For example, an entirely asynchronous coordinator is not suitable when the parsers used in your commands are not thread safe. If you have commands that perform blocking operations, however, it might not be a good idea to use a synchronous execution coordinator. In most cases you will want to pick between CommandExecutionCoordinator.simpleCoordinator() and AsynchronousCommandExecutionCoordinator.

        A word of caution: When using the asynchronous command executor in Bukkit, it is very likely that you will have to perform manual synchronization when executing the commands in many cases, as Bukkit makes no guarantees of thread safety in common classes. To make this easier, taskRecipe() is provided. Furthermore, it may be unwise to use asynchronous command parsing, especially when dealing with things such as players and entities. To make this more safe, the asynchronous command execution allows you to state that you want synchronous command parsing.

        commandSenderMapper - Function that maps CommandSender to the command sender type
        backwardsCommandSenderMapper - Function that maps the command sender type to CommandSender
        Throws:
        java.lang.Exception - If the construction of the manager fails
    • Method Detail

      • taskRecipe

        public @NonNull cloud.commandframework.tasks.TaskRecipe taskRecipe()
        Create a new task recipe. This can be used to create chains of synchronous/asynchronous method calls
        Returns:
        Task recipe
      • getOwningPlugin

        public @NonNull org.bukkit.plugin.Plugin getOwningPlugin()
        Get the plugin that owns the manager
        Returns:
        Owning plugin
      • createDefaultCommandMeta

        public @NonNull BukkitCommandMeta createDefaultCommandMeta()
        Create default command meta data
        Specified by:
        createDefaultCommandMeta in class cloud.commandframework.CommandManager<C>
        Returns:
        Meta data
      • getCommandSenderMapper

        public final @NonNull java.util.function.Function<@NonNull org.bukkit.command.CommandSender,​@NonNull C> getCommandSenderMapper()
        Get the command sender mapper
        Returns:
        Command sender mapper
      • hasPermission

        public final boolean hasPermission​(@NonNull C sender,
                                           @NonNull java.lang.String permission)
        Specified by:
        hasPermission in class cloud.commandframework.CommandManager<C>
      • getSplitAliases

        protected final boolean getSplitAliases()
      • setSplitAliases

        protected final void setSplitAliases​(boolean value)
      • queryCapability

        public final boolean queryCapability​(@NonNull CloudBukkitCapabilities capability)
        Query for a specific capability
        Parameters:
        capability - Capability
        Returns:
        true if the manager has the given capability, else false
      • queryCapabilities

        public final @NonNull java.util.Set<@NonNull CloudBukkitCapabilities> queryCapabilities()
        Check for the platform capabilities
        Returns:
        A set containing all capabilities of the instance
      • brigadierManager

        public @Nullable cloud.commandframework.brigadier.CloudBrigadierManager<C,​?> brigadierManager()
        Specified by:
        brigadierManager in interface cloud.commandframework.brigadier.BrigadierManagerHolder<C>
        Since:
        1.2.0
      • stripNamespace

        public final @NonNull java.lang.String stripNamespace​(@NonNull java.lang.String command)
        Strip the plugin namespace from a plugin namespaced command. This will also strip the leading '/' if it's present
        Parameters:
        command - Command
        Returns:
        Stripped command
      • getBackwardsCommandSenderMapper

        public final @NonNull java.util.function.Function<@NonNull C,​@NonNull org.bukkit.command.CommandSender> getBackwardsCommandSenderMapper()
        Get the backwards command sender plugin
        Returns:
        The backwards command sender mapper