Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<>();
Expand All @@ -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
Copy link
Member

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

Copy link
Contributor Author

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.

+ // CraftBukkit start
+ public void removeCommand(String name) {
+ this.children.remove(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ public Command get(Object key) {
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"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private BukkitCommandNode(String literal, Command command, BukkitBrigCommand buk
null, null, false
);
this.command = command;
this.wrappedBukkitCommandCached = command;
}

public static BukkitCommandNode of(String name, Command command) {
Expand Down
Loading