Class BukkitCommandManager<C>

java.lang.Object
cloud.commandframework.CommandManager<C>
cloud.commandframework.bukkit.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
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
     
    static enum 
    Reasons to explain why Brigadier failed to initialize

    Nested classes/interfaces inherited from class cloud.commandframework.CommandManager

    cloud.commandframework.CommandManager.ManagerSettings, cloud.commandframework.CommandManager.RegistrationState
  • Constructor Summary

    Constructors
    Constructor
    Description
    BukkitCommandManager(@NonNull org.bukkit.plugin.Plugin owningPlugin, @NonNull Function<@NonNull cloud.commandframework.CommandTree<@NonNull C>,@NonNull cloud.commandframework.execution.CommandExecutionCoordinator<@NonNull C>> commandExecutionCoordinator, @NonNull Function<@NonNull org.bukkit.command.CommandSender,@NonNull C> commandSenderMapper, @NonNull 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,?>
    protected final void
    Check whether Brigadier can be used on the server instance
    Create default command meta data
    static @NonNull BukkitCommandManager<@NonNull org.bukkit.command.CommandSender>
    createNative(@NonNull org.bukkit.plugin.Plugin owningPlugin, @NonNull Function<@NonNull cloud.commandframework.CommandTree<@NonNull org.bukkit.command.CommandSender>,@NonNull cloud.commandframework.execution.CommandExecutionCoordinator<@NonNull org.bukkit.command.CommandSender>> commandExecutionCoordinator)
    Create a command manager using Bukkit's CommandSender as the sender type.
    final @NonNull Function<@NonNull C,@NonNull org.bukkit.command.CommandSender>
    Get the backwards command sender plugin
    final @NonNull Function<@NonNull org.bukkit.command.CommandSender,@NonNull C>
    Get the command sender mapper
    @NonNull org.bukkit.plugin.Plugin
    Get the plugin that owns the manager
    protected final boolean
     
    final boolean
    hasPermission(@NonNull C sender, @NonNull String permission)
     
    final @NonNull Set<@NonNull CloudBukkitCapabilities>
    Check for the platform capabilities
    final boolean
    Deprecated.
    for removal since 1.7.0.
    void
    Attempt to register the Brigadier mapper, and return it.
    protected final void
    setSplitAliases(boolean value)
     
    final @NonNull String
    stripNamespace(@NonNull String command)
    Strip the plugin namespace from a plugin namespaced command.
    @NonNull cloud.commandframework.tasks.TaskRecipe
    Create a new task recipe.

    Methods inherited from class cloud.commandframework.CommandManager

    argumentBuilder, capabilities, captionRegistry, captionRegistry, captionVariableReplacementHandler, captionVariableReplacementHandler, command, command, commandBuilder, commandBuilder, commandBuilder, commandBuilder, commandBuilder, commandBuilder, commandBuilder, commandBuilder, commandBuilder, commandExecutionCoordinator, commandRegistrationHandler, commandRegistrationHandler, commands, commandSuggestionProcessor, commandSuggestionProcessor, commandSyntaxFormatter, commandSyntaxFormatter, commandTree, createCommandHelpHandler, createCommandHelpHandler, deleteRootCommand, executeCommand, flagBuilder, getCaptionRegistry, getCommandHelpHandler, getCommandHelpHandler, getCommandRegistrationHandler, getCommands, getCommandSuggestionProcessor, getCommandSyntaxFormatter, getCommandTree, getExceptionHandler, getParserRegistry, getRegistrationState, getSetting, handleException, hasCapability, hasPermission, isCommandRegistrationAllowed, lockRegistration, parameterInjectorRegistry, parserRegistry, postprocessContext, preprocessContext, registerCapability, registerCommandPostProcessor, registerCommandPreProcessor, registerDefaultCaptions, registerExceptionHandler, registrationState, requireState, rootCommands, 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 Details

    • BukkitCommandManager

      public BukkitCommandManager(@NonNull org.bukkit.plugin.Plugin owningPlugin, @NonNull Function<@NonNull cloud.commandframework.CommandTree<@NonNull C>,@NonNull cloud.commandframework.execution.CommandExecutionCoordinator<@NonNull C>> commandExecutionCoordinator, @NonNull Function<@NonNull org.bukkit.command.CommandSender,@NonNull C> commandSenderMapper, @NonNull Function<@NonNull C,@NonNull org.bukkit.command.CommandSender> backwardsCommandSenderMapper) throws 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:
      Exception - If the construction of the manager fails
  • Method Details

    • createNative

      public static @NonNull BukkitCommandManager<@NonNull org.bukkit.command.CommandSender> createNative(@NonNull org.bukkit.plugin.Plugin owningPlugin, @NonNull Function<@NonNull cloud.commandframework.CommandTree<@NonNull org.bukkit.command.CommandSender>,@NonNull cloud.commandframework.execution.CommandExecutionCoordinator<@NonNull org.bukkit.command.CommandSender>> commandExecutionCoordinator) throws Exception
      Create a command manager using Bukkit's CommandSender as the sender type.
      Parameters:
      owningPlugin - plugin owning the command manager
      commandExecutionCoordinator - execution coordinator instance
      Returns:
      a new command manager
      Throws:
      Exception - If the construction of the manager fails
      Since:
      1.5.0
      See Also:
    • 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 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 String permission)
      Specified by:
      hasPermission in class cloud.commandframework.CommandManager<C>
    • getSplitAliases

      protected final boolean getSplitAliases()
    • setSplitAliases

      protected final void setSplitAliases(boolean value)
    • checkBrigadierCompatibility

      protected final void checkBrigadierCompatibility() throws BukkitCommandManager.BrigadierFailureException
      Check whether Brigadier can be used on the server instance
      Throws:
      BukkitCommandManager.BrigadierFailureException - An exception is thrown if Brigadier isn't available. The exception will contain the reason for this.
    • queryCapability

      @Deprecated @API(status=DEPRECATED, since="1.7.0") public final boolean queryCapability(@NonNull CloudBukkitCapabilities capability)
      Deprecated.
      for removal since 1.7.0. Use the new standard CommandManager.hasCapability(CloudCapability) instead.
      Query for a specific capability
      Parameters:
      capability - Capability
      Returns:
      true if the manager has the given capability, else false
    • queryCapabilities

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

      public void registerBrigadier() throws BukkitCommandManager.BrigadierFailureException
      Attempt to register the Brigadier mapper, and return it.
      Throws:
      BukkitCommandManager.BrigadierFailureException - If Brigadier isn't supported by the platform
    • 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 String stripNamespace(@NonNull 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 Function<@NonNull C,@NonNull org.bukkit.command.CommandSender> getBackwardsCommandSenderMapper()
      Get the backwards command sender plugin
      Returns:
      The backwards command sender mapper