Brigadier commands registered through Commands#getDispatcher
require incorrect permission when executed by Bukkit#dispatchCommand
#11378
Labels
status: needs triage
type: bug
Something doesn't work as it was intended to.
version: 1.21.1
Game version 1.21.1
Expected behavior
When I execute my
/test
command as a player with no permissions, it runs successfully.Observed/Actual behavior
When I execute my
/test
command usingBukkit#dispatchCommand
, the command fails with the messageI'm sorry, but you do not have permission to ...
Steps/models to reproduce
I created this plugin that registers two commands:
The
/test
command can be executed without any permissions. The/run
command executes the given command string usingBukkit#dispatchCommand
.Plugin and Datapack List
Paper version
Other
Server log: https://paste.gg/p/anonymous/19898849d44b4a5e884d147aeb2882ad
I'm looking into this problem to try to resolve CommandAPI/CommandAPI#583. My analysis of the Paper code that causes that issue and the one here can be found in this comment on that issue. In summary, when
Bukkit#dispatchCommand
is run, theBukkitBrigForwardingMap
added by #8235 converts theCommandNode
s in the Brigadier dispatcher into BukkitCommand
s. For vanilla commands, CommandAPI commands, and my/test
and/run
commands mentioned above, this constructor inVanillaCommandWrapper
is used:This constructor calls
setPermission
. In the case of my/test
command, this means the permissionminecraft.commands.test
is required to run it throughBukkit#dispatchCommand
, rather than beingnull
, or no permission required.On Spigot, the CommandAPI fixes this by looping through the
CommandMap
and callingsetPermission
again to give CommandAPI commands the correct permission String. This works because Spigot only creates theVanillaCommandWrappers
once, just before the server finishes start up. The same does not work on Paper, because a newVanillaCommandWrapper
is created each time a vanilla node is retrieved from theBukkitBrigForwardingMap
, so calls tosetPermission
do not persist to the next time theCommand
is retrieved and used.The text was updated successfully, but these errors were encountered: