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> com.mojang.brigadier.builder.RequiredArgumentBuilder
<CommandSourceStack, T> Utility to create a required argument builder with the correct generic.com.mojang.brigadier.CommandDispatcher
<CommandSourceStack> Gets the underlyingCommandDispatcher
.static com.mojang.brigadier.builder.LiteralArgumentBuilder
<CommandSourceStack> Utility to create a literal command node builder with the correct generic.default @Unmodifiable Set
<String> register
(com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node) Registers a command for the current plugin context.default @Unmodifiable Set
<String> register
(com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable String description) Registers a command for the current plugin context.register
(com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable String description, Collection<String> aliases) Registers a command for the current plugin context.default @Unmodifiable Set
<String> register
(com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, Collection<String> aliases) Registers a command for the current plugin context.register
(PluginMeta pluginMeta, com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable String description, Collection<String> aliases) Registers a command for a plugin.register
(PluginMeta pluginMeta, String label, @Nullable String description, Collection<String> aliases, BasicCommand basicCommand) Registers a command under the same logic asregister(PluginMeta, LiteralCommandNode, String, Collection)
.default @Unmodifiable Set
<String> register
(String label, BasicCommand basicCommand) Registers a command under the same logic asregister(LiteralCommandNode, String, Collection)
.default @Unmodifiable Set
<String> register
(String label, @Nullable String description, BasicCommand basicCommand) Registers a command under the same logic asregister(LiteralCommandNode, String, Collection)
.register
(String label, @Nullable String description, Collection<String> aliases, BasicCommand basicCommand) Registers a command under the same logic asregister(LiteralCommandNode, String, Collection)
.default @Unmodifiable Set
<String> register
(String label, Collection<String> aliases, BasicCommand basicCommand) Registers a command under the same logic asregister(LiteralCommandNode, String, Collection)
.registerWithFlags
(PluginMeta pluginMeta, com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable String description, Collection<String> aliases, Set<CommandRegistrationFlag> flags) This allows configuring the registration of your command, which is not intended for public use.
-
Method Details
-
literal
static com.mojang.brigadier.builder.LiteralArgumentBuilder<CommandSourceStack> literal(String literal) Utility to create a literal command node builder with the correct generic.- Parameters:
literal
- literal name- Returns:
- a new builder instance
-
argument
static <T> com.mojang.brigadier.builder.RequiredArgumentBuilder<CommandSourceStack,T> argument(String name, 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
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
default @Unmodifiable Set<String> register(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
default @Unmodifiable Set<String> register(com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @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
default @Unmodifiable Set<String> register(com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, 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
@Unmodifiable Set<String> register(com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable String description, 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
@Unmodifiable Set<String> register(PluginMeta pluginMeta, com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable String description, 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 @Unmodifiable Set<String> registerWithFlags(PluginMeta pluginMeta, com.mojang.brigadier.tree.LiteralCommandNode<CommandSourceStack> node, @Nullable String description, Collection<String> aliases, 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
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
default @Unmodifiable Set<String> register(String label, @Nullable String description, 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
default @Unmodifiable Set<String> register(String label, Collection<String> aliases, 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
@Unmodifiable Set<String> register(String label, @Nullable String description, Collection<String> aliases, 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
@Unmodifiable Set<String> register(PluginMeta pluginMeta, String label, @Nullable String description, Collection<String> aliases, 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)
-