Cache Bukkit Command when wrapping CommandNodes#11385
Conversation
Resolves PaperMC#11378 by "restoring" the Spigot behavior where VanillaCommandNodes are only created once. This allows command frameworks that insert CommandNodes directly into the Brigadier dispatcher to change the permission String of the VanillaCommandNodes created for their commands, rather than it always being the default `"minecraft.commands.<name>"`. Previously, BukkitBrigForwardingMap would create a new VanillaCommandWrapper each time a CommandNode was requested via the Bukkit CommandMap. This means that calls to `Command#setPermission` would not persist between retrievals from the map.
|
It's not possible to properly represent a tree of requirements as a permission string. To solve the linked issue properly we need to reimplement dispatchCommand without using the legacy command map. We could also set the permission to null for plugin commands and override hasPermission(Silent) to improve the legacy representation. |
Fair point. I imagine Paper will eventually remove the CommandMap after hard forking from Spigot, so it would be useful to get started on that by changing the command dispatch and suggestions logic available in the API to use Brigadier directly.
Note that this is indeed the case for commands registered using #11378 only applies to commands registered through While not a requirement of the |
Resolves #11378 by "restoring" the Spigot behavior where VanillaCommandNodes are only created once. This allows command frameworks that insert CommandNodes directly into the Brigadier dispatcher to change the permission String of the VanillaCommandNodes created for their commands, rather than it always being the default
"minecraft.commands.<name>".For example, the test plugin described in #11378 can do something like this now:
When the
/testcommand is ran usingBukkit#dispatchCommand, Bukkit will now see that its permission isnulland allow a Player without any permission to run it, which is the case when the same Player runs the command directly.Without this PR, BukkitBrigForwardingMap creates a new VanillaCommandWrapper each time a CommandNode is requested via the Bukkit CommandMap. This meant that calls to
Command#setPermissiondid not persist between retrievals from the map.I can squash this into the
Brigadier-based-command-APIpatch file if desired, but I figured it would be easier initially to review the changes when they are in a separate patch.