PaperMC / PaperMC/Paper

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

Open
#11,891 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: accepted version: 1.21.4
Dominant language
Java
Stars
12.7k
Forks
3.5k
Avg merge
3d 13h
Merged PRs (30d)
11

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported permission-gated Brigadier command with the supplied TestPlugin example, then trace how HelpMap handles commands registered through Commands#register. Compare that path with the requirement predicate on the Brigadier ArgumentBuilder, and verify that /help testcmd is hidden for an unauthorized sender without breaking accessible commands.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.