Question Can't register command

uweb

New member
Jun 16, 2023
2
1
0
1
I've been trying to register a command for a few hours now. I entered this in the paper-plugin.yml (I also tried it with a plugin.yml):
YAML:
commands:
  xyz:
    description: "desc"
    usage: "/xyz"

and in the onEnable() method this:
Java:
getCommand("xyz").setExecutor(new XYZCommandExecutor());

When I start the server I get the error
"Cannot invoke "org.bukkit.command.PluginCommand.setExecutor(org.bukkit.command.CommandExecutor)" because the return value of "de.uweb95.testplugin.Testplugin.getCommand(String)" is null"

I've also tried using the onCommand() method directly in the main class (that's how I did it earlier with a working 1.13 plugin), but I just get "Unknown command. Type "/help" for help."
Java:
 @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
    if (command.getLabel().equalsIgnoreCase("xyz")) {
        getLogger().info("test");
    }

    return true;
}


It feels like the command part of the paper-plugin.yml is being ignored but i just don't know what to do next...
 
Version Output
This server is running Paper version git-Paper-31 (MC: 1.20.1) (Implementing API version 1.20.1-R0.1-SNAPSHOT) (Git: a226f44)

Machine Maker

Paper Developer
Staff member
Dec 17, 2021
133
6
19
18
California
Commands cannot be registered in the paper-plugin.yml. You have to handle registering them yourselves. If you don’t want to do that, just stick with “plugin.yml”. Support for that isn’t going away anytime soon.
 
  • Like
Reactions: uweb

TerrorByte

New member
Jul 9, 2023
1
0
1
Commands cannot be registered in the paper-plugin.yml. You have to handle registering them yourselves. If you don’t want to do that, just stick with “plugin.yml”. Support for that isn’t going away anytime soon.
So then, what is the proper way to register commands? Your docs say that paper-plugin.yml can act as a drop-in replacement:
Similarly to Bukkit plugins, you have to introduce a paper-plugin.yml file into your jar resources folder. This can act as a drop in replacement for plugin.yml, allowing you to specifically target the Paper platform.

Just a little confused on what the proper method for registering commands is. I'd like to target Paper in its entirety. Thanks!
 

Machine Maker

Paper Developer
Staff member
Dec 17, 2021
133
6
19
18
California
I think the term "drop in" is a little ambiguous. It probably means that you can have plugins on your server with either (or both).

If you are using a paper-plugin.yml, you have to manually add your commands to the CommandMap (available via Server#getCommandMap). You have to extend Command to create your custom commands. The "paper plugin" system isn't finished (which is why types are still annotated with Experimental), and there is an open PR to better handle command creation.

But if you don't want handle creating your own Command class, and making sure to check permissions yourself, you can continue to use the plugin.yml. Support for that isn't going to go away, just the new system allows more possibilities in the future.
 
  • Like
Reactions: uweb and TerrorByte