Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BasicCommand permission is not visible through the CommandMap #11092

Closed
willkroboth opened this issue Jul 16, 2024 · 1 comment
Closed

BasicCommand permission is not visible through the CommandMap #11092

willkroboth opened this issue Jul 16, 2024 · 1 comment
Labels
resolution: works as intended Working as it should / expected to type: bug Something doesn't work as it was intended to. version: 1.21 Game version 1.21

Comments

@willkroboth
Copy link
Contributor

Expected behavior

Using Paper's BasicCommand API, I can define a permission string that is required for my command (#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.

@willkroboth willkroboth added status: needs triage type: bug Something doesn't work as it was intended to. labels Jul 16, 2024
@papermc-sniffer papermc-sniffer bot added the version: 1.21 Game version 1.21 label Jul 16, 2024
@papermc-projects papermc-projects bot moved this to 🕑 Needs Triage in Issues: Bugs Jul 16, 2024
@lynxplay
Copy link
Contributor

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.

@lynxplay lynxplay closed this as not planned Won't fix, can't repro, duplicate, stale Jul 22, 2024
@github-project-automation github-project-automation bot moved this from 🕑 Needs Triage to Done in Issues: Bugs Jul 22, 2024
@lynxplay lynxplay added resolution: works as intended Working as it should / expected to and removed status: needs triage labels Jul 22, 2024
@papermc-projects papermc-projects bot moved this from Done to Invalid in Issues: Bugs Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution: works as intended Working as it should / expected to type: bug Something doesn't work as it was intended to. version: 1.21 Game version 1.21
Projects
Status: Invalid
Development

No branches or pull requests

2 participants