Skip to content

Commit 07ef2bb

Browse files
authored
Fix incorrect command serialization by creating new Command (#11671)
Fixes #11649 - As noted in the issue, when CommandNodes are serialized they are used as the key in a Map. Their equals()/hashcode() should only match if they are equal nodes (name & command), but due to the erasure of the command field pre-serialization, nodes with different commands can be mapped onto the same value. This causes the client to interpret both nodes as the same, causing suggestions where they should not. This is fixed by creating a different no-op command for the erasure, instead of them holding the same lambda.
1 parent fabd859 commit 07ef2bb

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Rick <rickw320@hotmail.com>
3+
Date: Tue, 26 Nov 2024 20:45:52 +0100
4+
Subject: [PATCH] Fix incorrect command serialization by creating new Command
5+
6+
Fixes #11649 - As noted in the issue, when CommandNodes are serialized
7+
they are used as the key in a Map. Their equals()/hashcode() should only
8+
match if they are equal nodes (name & command), but due to the erasure of the command field pre-serialization, nodes with different commands can be mapped onto the same value. This causes the client to interpret both nodes as the same, causing suggestions where they should not.
9+
10+
This is fixed by creating a different no-op command for the
11+
erasure, instead of them holding the same lambda.
12+
13+
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
14+
index 64bf4444ffba25cb40743a32267aa790ad1738f9..517cb238ec280aadd1fc54bcb675ed386e798eaf 100644
15+
--- a/src/main/java/net/minecraft/commands/Commands.java
16+
+++ b/src/main/java/net/minecraft/commands/Commands.java
17+
@@ -587,9 +587,14 @@ public class Commands {
18+
return true;
19+
});
20+
if (argumentbuilder.getCommand() != null) {
21+
- argumentbuilder.executes((commandcontext) -> {
22+
- return 0;
23+
+ // Paper start - fix suggestions due to falsely equal nodes
24+
+ argumentbuilder.executes(new com.mojang.brigadier.Command<io.papermc.paper.command.brigadier.CommandSourceStack>() {
25+
+ @Override
26+
+ public int run(com.mojang.brigadier.context.CommandContext<io.papermc.paper.command.brigadier.CommandSourceStack> commandContext) throws CommandSyntaxException {
27+
+ return 0;
28+
+ }
29+
});
30+
+ // Paper end
31+
}
32+
33+
if (argumentbuilder instanceof RequiredArgumentBuilder) {

0 commit comments

Comments
 (0)