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

/help showing commands that players do not have permission for (Brigadier) #11891

Open
Strokkur424 opened this issue Jan 3, 2025 · 0 comments
Labels
status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. version: 1.21.4

Comments

@Strokkur424
Copy link
Contributor

Expected behavior

When declaring a requirement (mainly a permission requirement) using an ArgumentBuilder from Brigadier using .requires(source -> source.getSender().hasPermission("plugin.permission")), it is expected that such a command, as it is not visible to the client, showing the red text saying that this command does not exist, should also not be visible using /help.

Observed/Actual behavior

Instead, when running /help, anybody can still see the command. This isn't necessarily a big problem, but it feels like unintended behavior.

Steps/models to reproduce

Defining a command like this:

package io.papermc.testplugin;

import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import org.bukkit.plugin.java.JavaPlugin;

public final class TestPlugin extends JavaPlugin {

    @Override
    public void onEnable() {
        this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS,
            event -> event.registrar().register(Commands.literal("testcmd")
                .requires(sender -> sender.getSender().hasPermission("permission.test"))
                .build()
            ));
    }
}

We can view in-game, if not opped, that we do not have access to /testcmd, yet running /help testcmd runs fine, printing the expected help block.

Plugin and Datapack List

plugins
[13:22:30 INFO]: Server Plugins (1):
[13:22:30 INFO]: Paper Plugins:
[13:22:30 INFO]:  - Paper-Test-Plugin

datapack list
[13:22:34 INFO]: There are 3 data pack(s) enabled: [vanilla (built-in)], [file/bukkit (world)], [paper (built-in)]
[13:22:34 INFO]: There are no more data packs available

Paper version

Latest, up-to-date (dev) version, as I am currently running the actual Paper project using ./gradlew runDevServer. This behavior also occurs on production builds.

version
[13:22:54 INFO]: Checking version, please wait...
[13:22:54 INFO]: This server is running Paper version 1.21.4-DEV (2025-01-03T12:22:18Z) (Implementing API version 1.21.4-R0.1-SNAPSHOT)
You are running a development version without access to version information

Other

If I understood it correctly, the current logic goes through the HelpMap. There are three possible ways I can see this fixed:

  1. The HelpMap is modified in order to account for requirements on command nodes
  2. In Commands#register, we append new overloads for a permission value, which acts like a second "requirement", which is also tracked by the HelpMap in order to not show commands the user has no access to. This does not account for nodes with permission inside a command tree.
  3. The Brigadier ArgumentBuilder gets appended with a .withPermission(String) method, which acts not only as a second requirement predicate, but also a value that the HelpMap can use.
@Malfrador Malfrador added status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. version: 1.21.4 and removed status: needs triage labels Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. version: 1.21.4
Projects
None yet
Development

No branches or pull requests

2 participants