Interface CommandRegistry
public interface CommandRegistry
Handles the registration and execution of commands.
- Since:
- 0.1.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordThe outcome of a command dispatch. -
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<Boolean> dispatchAsync(CommandSource source, String cmdLine) Attempts to asynchronously execute a command from the givencmdLine.dispatchAsyncResult(CommandSource source, String cmdLine) Attempts to asynchronously execute a command from the givencmdLine, returning the raw brigadier result alongside anexecutedflag.booleanhasCommand(String alias) Returns whether the given alias is registered on this manager.booleanhasCommand(String alias, CommandSource source) Returns whether the given alias is registered on this manager and can be used by the givenCommandSource.CompletableFuture<com.mojang.brigadier.suggestion.Suggestions> offerSuggestions(CommandSource source, String cmdLine) Asynchronously collects suggestions to fill in the given commandcmdLine.default voidregister(PluginMeta meta, com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSource> command) Registers a command from the given builder.default voidregister(PluginMeta meta, com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSource> command, Set<String> aliases) Registers a command from the given builder with the specified aliases.default voidregister(PluginMeta meta, com.mojang.brigadier.tree.LiteralCommandNode<CommandSource> command) Registers a command node without aliases.default voidregister(PluginMeta meta, com.mojang.brigadier.tree.LiteralCommandNode<CommandSource> command, Set<String> aliases) Registers a command node with the specified aliases.default voidregister(String namespace, com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSource> command) Registers a command from the given builder.default voidregister(String namespace, com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSource> command, Set<String> aliases) Registers a command from the given builder with the specified aliases.default voidregister(String namespace, com.mojang.brigadier.tree.LiteralCommandNode<CommandSource> command) Registers a command node without aliases.voidregister(String namespace, com.mojang.brigadier.tree.LiteralCommandNode<CommandSource> command, Set<String> aliases) Registers a command node with the specified aliases.voidunregister(String namespace, String alias) Unregisters the specified command alias from the manager, if registered.default voidUnregisters all command aliases from the manager under the namespace provided byPluginMeta.id().voidunregisterNamespace(String namespace) Unregisters all command aliases from the manager under this namespace.
-
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 namespacecommand- 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 metacommand- 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 namespacecommand- 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 metacommand- 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 namespacecommand- the command builder to registeraliases- 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 metacommand- the command builder to registeraliases- 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 namespacecommand- the command node to registeraliases- 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 metacommand- the command node to registeraliases- additional aliases that should point to this command- Since:
- 0.1.0
-
unregister
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 unregisteralias- 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:aliasand plainaliascommand nodes.
-
unregisterNamespace
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:aliasand plainaliascommand nodes.
-
unregisterNamespace
Unregisters all command aliases from the manager under the namespace provided byPluginMeta.id().- Parameters:
meta- the plugin meta to unregister- Since:
- 0.1.0
- API Note:
- This removes both the namespaced
namespace:aliasand plainaliascommand nodes.
-
dispatchAsyncResult
CompletableFuture<CommandRegistry.CommandResult> dispatchAsyncResult(CommandSource source, String cmdLine) Attempts to asynchronously execute a command from the givencmdLine, returning the raw brigadier result alongside anexecutedflag.Useful for getting the amount of targets affected by the execution of the command.
- Parameters:
source- the source to execute the command forcmdLine- the command to run- Returns:
- a future completed with the
CommandRegistry.CommandResult; never completes exceptionally - Since:
- 0.1.0
-
dispatchAsync
Attempts to asynchronously execute a command from the givencmdLine.- Parameters:
source- the source to execute the command forcmdLine- 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 commandcmdLine. Returns the brigadierSuggestionswith tooltips for each result.- Parameters:
source- the source to execute the command forcmdLine- the partially completed command- Returns:
- a
CompletableFutureeventually completed withSuggestions, possibly empty - Since:
- 0.1.0
-
hasCommand
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
aliascontainsKey.DEFAULT_SEPARATOR, it is treated as a namespacednamespace:aliaslookup; otherwise it is treated as a plain-alias lookup
-
hasCommand
Returns whether the given alias is registered on this manager and can be used by the givenCommandSource. SeeArgumentBuilder.requires(Predicate)- Parameters:
alias- the command alias to checksource- the command source- Returns:
- true if the alias is registered and usable; false otherwise
- Since:
- 0.1.0
-