BasicCommand permission is not visible through the CommandMap
Expected behavior
Using Paper's BasicCommand API, I can define a permission string that is required for my command (https://github.com/PaperMC/Paper/pull/11047). When I check the permission of this command in the CommandMap, I expect it to return the value I defined.
Observed/Actual behavior
The result of Command#getPermission is null.
Steps/models to reproduce
This is the only code in my plugin:
public class BukkitTestPlugin extends JavaPlugin {
@Override
public void onEnable() {
getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> {
final Commands commands = event.registrar();
commands.register("test", new BasicCommand() {
@Override
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] strings) {
commandSourceStack.getSender().sendMessage("Ran command");
}
@Override
public @Nullable String permission() {
return "custom.permission";
}
});
Command command = Bukkit.getCommandMap().getCommand("test");
if (command == null) {
getLogger().info("Command was not found in CommandMap");
return;
}
getLogger().info("Command: " + command);
String permission = command.getPermission();
if (permission == null) {
getLogger().info("Permission is null");
return;
}
getLogger().info("Permission: " + permission);
});
}
}
When I add this plugin to the server and start it, I get these log messages:
[18:14:42 INFO]: [BukkitTestPlugin] Enabling BukkitTestPlugin v1.0-SNAPSHOT
[18:14:42 INFO]: [BukkitTestPlugin] Command: io.papermc.paper.command.brigadier.PluginVanillaCommandWrapper(test)
[18:14:42 INFO]: [BukkitTestPlugin] Permission is null
I expect it to tell me Permission: custom.permission, but it actually says Permission is null.
Plugin and Datapack List
> plugins
[18:16:34 INFO]: Server Plugins (1):
[18:16:34 INFO]: Bukkit Plugins:
[18:16:34 INFO]: - BukkitTestPlugin
> datapack list
[18:16:37 INFO]: There are 3 data pack(s) enabled: [vanilla (built-in)], [file/bukkit (world)], [paper (built-in)]
[18:16:37 INFO]: There are no more data packs available
Paper version
> version
[18:17:15 INFO]: Checking version, please wait...
[18:17:16 INFO]: This server is running Paper version 1.21-79-master@a6ceda1 (2024-07-16T18:42:09Z) (Implementing API version 1.21-R0.1-SNAPSHOT)
You are running the latest version
Other
I added LuckPerms to my server and confirmed that my player can only access the /test command if they have the permission custom.permission.
I am unsure if we are inclined to fix this. The new system is supposed to replace the old, not co-exist forever.
Having the already cursed command map implementation also attempt to find the permission of a brig node sounds kinda dumb. Especially when BasicCommand is only supposed to be a "simple" way to create a brigadier node, not a command framework exposed.
This is also generally not possible as plugins could just do this check in canUse in BasicCommand and skip the utility method.
E.g.
final class Example implements BasicCommand {
int execute(...) {}
boolean canUse(CommandSender sender) { return sender.hasPermission("testplugin.example") }.
}
Given we cannot promise consistency there (due to the pure nature of how brigadier's required works) I'll be closing this as "works-as-intended`. Obviously if you have more arguments for it, feel free to post them here, I'll gladly reopen for more of a discussion, but rn I cannot see a solid implementation for this.