Interface CommandRegistry


public interface CommandRegistry
Handles the registration and execution of commands.
Since:
0.1.0
  • Method Details

    • register

      default void register(String namespace, com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSource> command)
      Registers a command from the given builder.
      Parameters:
      namespace - the plugin namespace
      command - the command builder to register
      Since:
      0.1.0
    • register

      default void register(PluginMeta meta, com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSource> command)
      Registers a command from the given builder.
      Parameters:
      meta - the plugin meta
      command - the command builder to register
      Since:
      0.1.0
    • register

      default void register(String namespace, com.mojang.brigadier.tree.LiteralCommandNode<CommandSource> command)
      Registers a command node without aliases.
      Parameters:
      namespace - the plugin namespace
      command - the command node to register
      Since:
      0.1.0
    • register

      default void register(PluginMeta meta, com.mojang.brigadier.tree.LiteralCommandNode<CommandSource> command)
      Registers a command node without aliases.
      Parameters:
      meta - the plugin meta
      command - the command node to register
      Since:
      0.1.0
    • register

      default void register(String namespace, com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSource> command, Set<String> aliases)
      Registers a command from the given builder with the specified aliases.
      Parameters:
      namespace - the plugin namespace
      command - the command builder to register
      aliases - additional aliases that should point to this command
      Since:
      0.1.0
    • register

      default void register(PluginMeta meta, com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSource> command, Set<String> aliases)
      Registers a command from the given builder with the specified aliases.
      Parameters:
      meta - the plugin meta
      command - the command builder to register
      aliases - additional aliases that should point to this command
      Since:
      0.1.0
    • register

      void register(String namespace, com.mojang.brigadier.tree.LiteralCommandNode<CommandSource> command, Set<String> aliases)
      Registers a command node with the specified aliases.

      Aliases are additional names that can be used to execute the command besides its primary literal name.

      Parameters:
      namespace - the plugin namespace
      command - the command node to register
      aliases - additional aliases that should point to this command
      Since:
      0.1.0
    • register

      default void register(PluginMeta meta, com.mojang.brigadier.tree.LiteralCommandNode<CommandSource> command, Set<String> aliases)
      Registers a command node with the specified aliases.

      Aliases are additional names that can be used to execute the command besides its primary literal name.

      Parameters:
      meta - the plugin meta
      command - the command node to register
      aliases - additional aliases that should point to this command
      Since:
      0.1.0
    • unregister

      void unregister(String namespace, String alias)
      Unregisters the specified command alias from the manager, if registered. Root literal names are also treated as aliases in this context.
      Parameters:
      namespace - the namespace of the command to unregister
      alias - the command alias to unregister; if not currently registered, this method does nothing
      Since:
      0.1.0
      API Note:
      This removes both the namespaced namespace:alias and plain alias command nodes.
    • unregisterNamespace

      void unregisterNamespace(String namespace)
      Unregisters all command aliases from the manager under this namespace.
      Parameters:
      namespace - the namespace to unregister
      Since:
      0.1.0
      API Note:
      This removes both the namespaced namespace:alias and plain alias command nodes.
    • unregisterNamespace

      default void unregisterNamespace(PluginMeta meta)
      Unregisters all command aliases from the manager under the namespace provided by PluginMeta.id().
      Parameters:
      meta - the plugin meta to unregister
      Since:
      0.1.0
      API Note:
      This removes both the namespaced namespace:alias and plain alias command nodes.
    • dispatchAsyncResult

      CompletableFuture<CommandRegistry.CommandResult> dispatchAsyncResult(CommandSource source, String cmdLine)
      Attempts to asynchronously execute a command from the given cmdLine, returning the raw brigadier result alongside an executed flag.

      Useful for getting the amount of targets affected by the execution of the command.

      Parameters:
      source - the source to execute the command for
      cmdLine - the command to run
      Returns:
      a future completed with the CommandRegistry.CommandResult; never completes exceptionally
      Since:
      0.1.0
    • dispatchAsync

      default CompletableFuture<Boolean> dispatchAsync(CommandSource source, String cmdLine)
      Attempts to asynchronously execute a command from the given cmdLine.
      Parameters:
      source - the source to execute the command for
      cmdLine - the command to run
      Returns:
      a future completed with the result of the command execution; never completes exceptionally
      Since:
      0.1.0
    • offerSuggestions

      CompletableFuture<com.mojang.brigadier.suggestion.Suggestions> offerSuggestions(CommandSource source, String cmdLine)
      Asynchronously collects suggestions to fill in the given command cmdLine. Returns the brigadier Suggestions with tooltips for each result.
      Parameters:
      source - the source to execute the command for
      cmdLine - the partially completed command
      Returns:
      a CompletableFuture eventually completed with Suggestions, possibly empty
      Since:
      0.1.0
    • hasCommand

      boolean hasCommand(String alias)
      Returns whether the given alias is registered on this manager.
      Parameters:
      alias - the command alias to check
      Returns:
      true if the alias is registered; false otherwise
      Since:
      0.1.0
      API Note:
      If alias contains Key.DEFAULT_SEPARATOR, it is treated as a namespaced namespace:alias lookup; otherwise it is treated as a plain-alias lookup
    • hasCommand

      boolean hasCommand(String alias, CommandSource source)
      Returns whether the given alias is registered on this manager and can be used by the given CommandSource. See ArgumentBuilder.requires(Predicate)
      Parameters:
      alias - the command alias to check
      source - the command source
      Returns:
      true if the alias is registered and usable; false otherwise
      Since:
      0.1.0