mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-25 14:00:15 +01:00
Cache Bukkit Command when wrapping CommandNodes
Resolves https://github.com/PaperMC/Paper/issues/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>"`.
This commit is contained in:
parent
bd4c235c2f
commit
08b2b8926d
3 changed files with 8 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
--- a/com/mojang/brigadier/tree/CommandNode.java
|
||||
+++ b/com/mojang/brigadier/tree/CommandNode.java
|
||||
@@ -27,11 +_,21 @@
|
||||
@@ -27,11 +_,22 @@
|
||||
private final Map<String, CommandNode<S>> children = new LinkedHashMap<>();
|
||||
private final Map<String, LiteralCommandNode<S>> literals = new LinkedHashMap<>();
|
||||
private final Map<String, ArgumentCommandNode<S, ?>> arguments = new LinkedHashMap<>();
|
||||
|
@ -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
|
||||
+ // CraftBukkit start
|
||||
+ public void removeCommand(String name) {
|
||||
+ this.children.remove(name);
|
||||
|
|
|
@ -83,11 +83,13 @@ public class BukkitBrigForwardingMap extends HashMap<String, Command> {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (node instanceof BukkitCommandNode bukkitCommandNode) {
|
||||
return bukkitCommandNode.getBukkitCommand();
|
||||
if (node.wrappedBukkitCommandCached != null) {
|
||||
return node.wrappedBukkitCommandCached;
|
||||
}
|
||||
|
||||
return PaperBrigadier.wrapNode(node);
|
||||
Command bukkitCommand = PaperBrigadier.wrapNode(node);
|
||||
node.wrappedBukkitCommandCached = bukkitCommand;
|
||||
return bukkitCommand;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
|
|
|
@ -43,6 +43,7 @@ public class BukkitCommandNode extends LiteralCommandNode<CommandSourceStack> {
|
|||
null, null, false
|
||||
);
|
||||
this.command = command;
|
||||
this.wrappedBukkitCommandCached = command;
|
||||
}
|
||||
|
||||
public static BukkitCommandNode of(String name, Command command) {
|
||||
|
|
Loading…
Reference in a new issue