From 5cd1518c9a34da4acbb652d10d923439883c05cd Mon Sep 17 00:00:00 2001 From: Rick Date: Sun, 8 Dec 2024 22:43:09 +0100 Subject: [PATCH] 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. --- ...mmand-serialization-by-creating-new-.patch | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 patches/server/Fix-incorrect-command-serialization-by-creating-new-.patch diff --git a/patches/server/Fix-incorrect-command-serialization-by-creating-new-.patch b/patches/server/Fix-incorrect-command-serialization-by-creating-new-.patch new file mode 100644 index 0000000000..8e30461820 --- /dev/null +++ b/patches/server/Fix-incorrect-command-serialization-by-creating-new-.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Rick +Date: Tue, 26 Nov 2024 20:45:52 +0100 +Subject: [PATCH] Fix incorrect command serialization by creating new Command + +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. + +diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/commands/Commands.java ++++ b/src/main/java/net/minecraft/commands/Commands.java +@@ -0,0 +0,0 @@ public class Commands { + return true; + }); + if (argumentbuilder.getCommand() != null) { +- argumentbuilder.executes((commandcontext) -> { +- return 0; ++ // Paper start - fix suggestions due to falsely equal nodes ++ argumentbuilder.executes(new com.mojang.brigadier.Command() { ++ @Override ++ public int run(com.mojang.brigadier.context.CommandContext commandContext) throws CommandSyntaxException { ++ return 0; ++ } + }); ++ // Paper end + } + + if (argumentbuilder instanceof RequiredArgumentBuilder) {