-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Cache Bukkit Command when wrapping CommandNodes #11789
base: main
Are you sure you want to change the base?
Conversation
Resolves PaperMC#11378 by "restoring" the Spigot behavior where VanillaCommandNodes are only created once. Before this commit, BukkitBrigForwardingMap would create a new VanillaCommandWrapper each time a CommandNode was requested via the Bukkit CommandMap. This meant that calls to `Command#setPermission` would not persist between retrievals from the map. 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>"`.
The issue that if at any point |
Indeed, if This PR only fixes But yeah, again, if we just want to fix #11378 by changing the implementation of |
@@ -13,6 +13,7 @@ | |||
+ public CommandNode<net.minecraft.commands.CommandSourceStack> clientNode; // Paper - Brigadier API | |||
+ public CommandNode<io.papermc.paper.command.brigadier.CommandSourceStack> unwrappedCached = null; // Paper - Brigadier Command API | |||
+ public CommandNode<io.papermc.paper.command.brigadier.CommandSourceStack> wrappedCached = null; // Paper - Brigadier Command API | |||
+ public org.bukkit.command.Command wrappedBukkitCommandCached = null; // Paper - Brigadier Command API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semantics but, I think cachedWrappedBukkitCommand would read better than what's currently there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, makes sense to me. I think I originally went with wrappedBukkitCommand
+ Cached
to match the naming of unwrapped
+ Cached
and wrapped
+ Cache
directly above.
Maybe Owen had a reason to go with the original naming, but in isolation I prefer cached
+ WrappedBukkitCommand
.
Reopens #11385.
Resolves #11378 by "restoring" the Spigot behavior where VanillaCommandNodes are only created once. Before this commit,
BukkitBrigForwardingMap
would create a newVanillaCommandWrapper
each time aCommandNode
was requested via the BukkitCommandMap
. This meant that calls toCommand#setPermission
would not persist between retrievals from the map.This allows command frameworks that insert
CommandNode
s directly into the Brigadier dispatcher to change the permission String of theVanillaCommandNode
s created for their commands, rather than it always being the default"minecraft.commands.<name>"
.As discussed on the original PR, it's probably a good idea to eventually migrate the behavior of
Bukkit#dispatchCommand
to use Brigadier directly rather than working via the BukkitCommandMap
, which causes issues like this. Now that the hardfork is real, Paper may eventually fully removeCommandMap
in favor of direct Brigadier API, which would make fixingCommandMap
behavior like this PR does irrelevant. However, I feel like while Paper is still using theCommandMap
fixes like this are still valuable.If we'd rather fix #11378 by changing the implementation of
Bukkit#dispatchCommand
to use Brigadier directly, feel free to close this PR. Although, while not a requirement of the Map interface, it is also neat whenmap.get(a) == map.get(a)
for alla
, which isn't necessarily true for theBukkitBrigForwardingMap
before this PR.