Interface Commands
- All Superinterfaces:
Registrar
BasicCommand
.
An example of a command being registered is below
class YourPluginClass extends JavaPlugin {
@Override
public void onEnable() {
LifecycleEventManager<Plugin> manager = this.getLifecycleManager();
manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> {
final Commands commands = event.registrar();
commands.register(
Commands.literal("new-command")
.executes(ctx -> {
ctx.getSource().getSender().sendPlainMessage("some message");
return Command.SINGLE_SUCCESS;
})
.build(),
"some bukkit help description string",
List.of("an-alias")
);
});
}
}
You can also register commands in PluginBootstrap
by getting the LifecycleEventManager
from
BootstrapContext
.
Commands registered in the PluginBootstrap
will be available for datapack's
command function parsing.
Note that commands registered via PluginBootstrap
with the same literals as a vanilla command will override
that command within all loaded datapacks.
The register
methods that do not have PluginMeta
as a parameter will
implicitly use the PluginMeta
for the plugin that the LifecycleEventHandler
was registered with.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @NotNull com.mojang.brigadier.builder.RequiredArgumentBuilder
<CommandSourceStack, T> argument
(@NotNull String name, @NotNull com.mojang.brigadier.arguments.ArgumentType<T> argumentType) Utility to create a required argument builder with the correct generic.@NotNull com.mojang.brigadier.CommandDispatcher
<CommandSourceStack> Gets the underlyingCommandDispatcher
.static @NotNull com.mojang.brigadier.builder.LiteralArgumentBuilder
<CommandSourceStack> Utility to create a literal command node builder with the correct generic.default @Unmodifiable @NotNull Set
<String> register
(@NotNull com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node) Registers a command for the current plugin context.default @Unmodifiable @NotNull Set
<String> register
(@NotNull com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable String description) Registers a command for the current plugin context.register
(@NotNull com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable String description, @NotNull Collection<String> aliases) Registers a command for the current plugin context.default @Unmodifiable @NotNull Set
<String> register
(@NotNull com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @NotNull Collection<String> aliases) Registers a command for the current plugin context.register
(@NotNull PluginMeta pluginMeta, @NotNull com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable String description, @NotNull Collection<String> aliases) Registers a command for a plugin.register
(@NotNull PluginMeta pluginMeta, @NotNull String label, @Nullable String description, @NotNull Collection<String> aliases, @NotNull BasicCommand basicCommand) Registers a command under the same logic asregister(PluginMeta, LiteralCommandNode, String, Collection)
.default @Unmodifiable @NotNull Set
<String> register
(@NotNull String label, @NotNull BasicCommand basicCommand) Registers a command under the same logic asregister(LiteralCommandNode, String, Collection)
.default @Unmodifiable @NotNull Set
<String> Registers a command under the same logic asregister(LiteralCommandNode, String, Collection)
.register
(@NotNull String label, @Nullable String description, @NotNull Collection<String> aliases, @NotNull BasicCommand basicCommand) Registers a command under the same logic asregister(LiteralCommandNode, String, Collection)
.default @Unmodifiable @NotNull Set
<String> register
(@NotNull String label, @NotNull Collection<String> aliases, @NotNull BasicCommand basicCommand) Registers a command under the same logic asregister(LiteralCommandNode, String, Collection)
.registerWithFlags
(@NotNull PluginMeta pluginMeta, @NotNull com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable String description, @NotNull Collection<String> aliases, @NotNull Set<CommandRegistrationFlag> flags) This allows configuring the registration of your command, which is not intended for public use.
-
Method Details
-
literal
@NotNull static @NotNull com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSourceStack> literal(@NotNull @NotNull String literal) Utility to create a literal command node builder with the correct generic.- Parameters:
literal
- literal name- Returns:
- a new builder instance
-
argument
@NotNull static <T> @NotNull com.mojang.brigadier.builder.RequiredArgumentBuilder<CommandSourceStack,T> argument(@NotNull @NotNull String name, @NotNull @NotNull com.mojang.brigadier.arguments.ArgumentType<T> argumentType) Utility to create a required argument builder with the correct generic.- Type Parameters:
T
- the generic type of the argument value- Parameters:
name
- the name of the argumentargumentType
- the type of the argument- Returns:
- a new required argument builder
-
getDispatcher
@Experimental @NotNull @NotNull com.mojang.brigadier.CommandDispatcher<CommandSourceStack> getDispatcher()Gets the underlyingCommandDispatcher
.Note: This is a delicate API that must be used with care to ensure a consistent user experience.
When registering commands, it should be preferred to use the
register methods
over directly registering to the dispatcher wherever possible.Register methods
automatically handle command namespacing, command help, plugin association with commands, and more.Example use cases for this method may include:
- Implementing integration between an external command framework and Paper (although
register methods
should still be preferred where possible) - Registering new child nodes to an existing plugin command (for example an "addon" plugin to another plugin may want to do this)
- Retrieving existing command nodes to build redirects
- Returns:
- the dispatcher instance
- Implementing integration between an external command framework and Paper (although
-
register
@NotNull default @Unmodifiable @NotNull Set<String> register(@NotNull @NotNull com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node) Registers a command for the current plugin context.Commands have certain overriding behavior:
- Aliases will not override already existing commands (excluding namespaced ones)
- The main command/namespaced label will override already existing commands
- Parameters:
node
- the built literal command node- Returns:
- successfully registered root command labels (including aliases and namespaced variants)
-
register
@NotNull default @Unmodifiable @NotNull Set<String> register(@NotNull @NotNull com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable @Nullable String description) Registers a command for the current plugin context.Commands have certain overriding behavior:
- Aliases will not override already existing commands (excluding namespaced ones)
- The main command/namespaced label will override already existing commands
- Parameters:
node
- the built literal command nodedescription
- the help description for the root literal node- Returns:
- successfully registered root command labels (including aliases and namespaced variants)
-
register
@NotNull default @Unmodifiable @NotNull Set<String> register(@NotNull @NotNull com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @NotNull @NotNull Collection<String> aliases) Registers a command for the current plugin context.Commands have certain overriding behavior:
- Aliases will not override already existing commands (excluding namespaced ones)
- The main command/namespaced label will override already existing commands
- Parameters:
node
- the built literal command nodealiases
- a collection of aliases to register the literal node's command to- Returns:
- successfully registered root command labels (including aliases and namespaced variants)
-
register
@NotNull @Unmodifiable @NotNull Set<String> register(@NotNull @NotNull com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable @Nullable String description, @NotNull @NotNull Collection<String> aliases) Registers a command for the current plugin context.Commands have certain overriding behavior:
- Aliases will not override already existing commands (excluding namespaced ones)
- The main command/namespaced label will override already existing commands
- Parameters:
node
- the built literal command nodedescription
- the help description for the root literal nodealiases
- a collection of aliases to register the literal node's command to- Returns:
- successfully registered root command labels (including aliases and namespaced variants)
-
register
@NotNull @Unmodifiable @NotNull Set<String> register(@NotNull @NotNull PluginMeta pluginMeta, @NotNull @NotNull com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable @Nullable String description, @NotNull @NotNull Collection<String> aliases) Registers a command for a plugin.Commands have certain overriding behavior:
- Aliases will not override already existing commands (excluding namespaced ones)
- The main command/namespaced label will override already existing commands
- Parameters:
pluginMeta
- the owning plugin's metanode
- the built literal command nodedescription
- the help description for the root literal nodealiases
- a collection of aliases to register the literal node's command to- Returns:
- successfully registered root command labels (including aliases and namespaced variants)
-
registerWithFlags
@Internal @NotNull @Unmodifiable @NotNull Set<String> registerWithFlags(@NotNull @NotNull PluginMeta pluginMeta, @NotNull @NotNull com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable @Nullable String description, @NotNull @NotNull Collection<String> aliases, @NotNull @NotNull Set<CommandRegistrationFlag> flags) This allows configuring the registration of your command, which is not intended for public use. Seeregister(PluginMeta, LiteralCommandNode, String, Collection)
for more information.- Parameters:
pluginMeta
- the owning plugin's metanode
- the built literal command nodedescription
- the help description for the root literal nodealiases
- a collection of aliases to register the literal node's command toflags
- a collection of registration flags that control registration behaviour.- Returns:
- successfully registered root command labels (including aliases and namespaced variants)
- API Note:
- This method is not guaranteed to be stable as it is not intended for public use.
See
CommandRegistrationFlag
for a more indepth explanation of this method's use-case.
-
register
@NotNull default @Unmodifiable @NotNull Set<String> register(@NotNull @NotNull String label, @NotNull @NotNull BasicCommand basicCommand) Registers a command under the same logic asregister(LiteralCommandNode, String, Collection)
.- Parameters:
label
- the label of the to-be-registered commandbasicCommand
- the basic command instance to register- Returns:
- successfully registered root command labels (including aliases and namespaced variants)
-
register
@NotNull default @Unmodifiable @NotNull Set<String> register(@NotNull @NotNull String label, @Nullable @Nullable String description, @NotNull @NotNull BasicCommand basicCommand) Registers a command under the same logic asregister(LiteralCommandNode, String, Collection)
.- Parameters:
label
- the label of the to-be-registered commanddescription
- the help description for the root literal nodebasicCommand
- the basic command instance to register- Returns:
- successfully registered root command labels (including aliases and namespaced variants)
-
register
@NotNull default @Unmodifiable @NotNull Set<String> register(@NotNull @NotNull String label, @NotNull @NotNull Collection<String> aliases, @NotNull @NotNull BasicCommand basicCommand) Registers a command under the same logic asregister(LiteralCommandNode, String, Collection)
.- Parameters:
label
- the label of the to-be-registered commandaliases
- a collection of aliases to register the basic command under.basicCommand
- the basic command instance to register- Returns:
- successfully registered root command labels (including aliases and namespaced variants)
-
register
@NotNull @Unmodifiable @NotNull Set<String> register(@NotNull @NotNull String label, @Nullable @Nullable String description, @NotNull @NotNull Collection<String> aliases, @NotNull @NotNull BasicCommand basicCommand) Registers a command under the same logic asregister(LiteralCommandNode, String, Collection)
.- Parameters:
label
- the label of the to-be-registered commanddescription
- the help description for the root literal nodealiases
- a collection of aliases to register the basic command under.basicCommand
- the basic command instance to register- Returns:
- successfully registered root command labels (including aliases and namespaced variants)
-
register
@NotNull @Unmodifiable @NotNull Set<String> register(@NotNull @NotNull PluginMeta pluginMeta, @NotNull @NotNull String label, @Nullable @Nullable String description, @NotNull @NotNull Collection<String> aliases, @NotNull @NotNull BasicCommand basicCommand) Registers a command under the same logic asregister(PluginMeta, LiteralCommandNode, String, Collection)
.- Parameters:
pluginMeta
- the owning plugin's metalabel
- the label of the to-be-registered commanddescription
- the help description for the root literal nodealiases
- a collection of aliases to register the basic command under.basicCommand
- the basic command instance to register- Returns:
- successfully registered root command labels (including aliases and namespaced variants)
-