diff --git a/leaf-server/minecraft-patches/features/0270-Paper-PR-Optimise-temptation-lookups.patch b/leaf-server/minecraft-patches/features/0270-Paper-PR-Optimise-temptation-lookups.patch index 64f239f2..c49fcb2b 100644 --- a/leaf-server/minecraft-patches/features/0270-Paper-PR-Optimise-temptation-lookups.patch +++ b/leaf-server/minecraft-patches/features/0270-Paper-PR-Optimise-temptation-lookups.patch @@ -3,6 +3,10 @@ From: okx-code Date: Thu, 6 Feb 2025 19:05:00 +0100 Subject: [PATCH] Paper PR: Optimise temptation lookups +Original license: GPLv3 +Original project: https://github.com/PaperMC/Paper +Paper pull request: https://github.com/PaperMC/Paper/pull/11942 + Both TemptGoal and TemptingSensor recheck their validity each tick. For this, they iterate all online players, checking their main and offhand items against item tags. @@ -15,10 +19,6 @@ Such cache is valid for a single tick but can be re-used by each tempt goal or sensor sharing the same non-entity specific selection predicates. -Original license: GPLv3 -Original project: https://github.com/PaperMC/Paper -Paper pull request: https://github.com/PaperMC/Paper/pull/11942 - diff --git a/io/papermc/paper/entity/temptation/GlobalTemptationLookup.java b/io/papermc/paper/entity/temptation/GlobalTemptationLookup.java new file mode 100644 index 0000000000000000000000000000000000000000..5f5cdfc538ba9aa6666c019df6706015234d7bae diff --git a/leaf-server/minecraft-patches/features/0271-Paper-PR-Fix-async-command-building-throwing-CME-in-.patch b/leaf-server/minecraft-patches/features/0271-Paper-PR-Fix-async-command-building-throwing-CME-in-.patch new file mode 100644 index 00000000..c340bb51 --- /dev/null +++ b/leaf-server/minecraft-patches/features/0271-Paper-PR-Fix-async-command-building-throwing-CME-in-.patch @@ -0,0 +1,92 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: roro1506HD +Date: Fri, 24 Oct 2025 00:19:58 +0200 +Subject: [PATCH] Paper PR: Fix async command building throwing CME in some + cases + +Original license: GPLv3 +Original project: https://github.com/PaperMC/Paper +Paper pull request: https://github.com/PaperMC/Paper/pull/13233 + +The issue is from multiple places during that sendAsync process: Anything that loops through any CommandNode's children is subject to the CME. + +The previous fix was only working for the root node, and wasn't even fully working given a few lines lower it's being added in an HashMap, which does .hashCode and loops through the root's children again. + +This PR reverts the previous fix and fixes the concurrency issue once for all: + +Changed the CommandNode's children map to a synchronized map, still backed by a LinkedHashMap +Lock everything in Commands#fillUsableCommands inside a synchronized block that uses the children map as lock object, the same lock object the synchronized map uses. +This has been tested with the test plugin published on [this branch of my fork](https://github.com/roro1506HD/Paper/tree/other/async_command_cme_fix_test_plugin) + +Fixes https://github.com/PaperMC/Paper/issues/11101 + +diff --git a/com/mojang/brigadier/tree/CommandNode.java b/com/mojang/brigadier/tree/CommandNode.java +index f05e69aaf79e47951de1506a97f56d84a4fa9f7f..42549e8ed22f5e6265fea47d1e475710a36a7bf0 100644 +--- a/com/mojang/brigadier/tree/CommandNode.java ++++ b/com/mojang/brigadier/tree/CommandNode.java +@@ -24,7 +24,7 @@ import java.util.concurrent.CompletableFuture; + import java.util.function.Predicate; + + public abstract class CommandNode implements Comparable> { +- private final Map> children = new LinkedHashMap<>(); ++ public final Map> children = Collections.synchronizedMap(new LinkedHashMap<>()); // Paper PR - Fix async command building throwing CME in some cases - Prevent concurrent modification when sending commands; public + private final Map> literals = new LinkedHashMap<>(); + private final Map> arguments = new LinkedHashMap<>(); + public Predicate requirement; // Paper - public-f +diff --git a/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java +index 5f80c7b06411e0ad9b0f71f03bb4568daea3ea4d..f7b6ed257925f909a1d418c18538c68197210f8b 100644 +--- a/net/minecraft/commands/Commands.java ++++ b/net/minecraft/commands/Commands.java +@@ -453,9 +453,7 @@ public class Commands { + // CraftBukkit start + // Register Vanilla commands into builtRoot as before + // Paper start - Perf: Async command map building +- // Copy root children to avoid concurrent modification during building +- final java.util.Collection> commandNodes = new java.util.ArrayList<>(this.dispatcher.getRoot().getChildren()); +- COMMAND_SENDING_POOL.execute(() -> this.sendAsync(player, commandNodes)); ++ COMMAND_SENDING_POOL.execute(() -> this.sendAsync(player)); // Paper PR - Fix async command building throwing CME in some cases + } + + // Fixed pool, but with discard policy +@@ -469,12 +467,12 @@ public class Commands { + new java.util.concurrent.ThreadPoolExecutor.DiscardPolicy() + ); + +- private void sendAsync(ServerPlayer player, java.util.Collection> dispatcherRootChildren) { ++ private void sendAsync(ServerPlayer player) { // Paper PR - Fix async command building throwing CME in some cases + // Paper end - Perf: Async command map building + Map, CommandNode> map = new HashMap<>(); + RootCommandNode rootCommandNode = new RootCommandNode<>(); + map.put(this.dispatcher.getRoot(), rootCommandNode); +- fillUsableCommands(dispatcherRootChildren, rootCommandNode, player.createCommandSourceStack(), map); // Paper - Perf: Async command map building; pass copy of children ++ fillUsableCommands(this.dispatcher.getRoot(), rootCommandNode, player.createCommandSourceStack(), map); // Paper PR - Fix async command building throwing CME in some cases + + java.util.Collection bukkit = new java.util.LinkedHashSet<>(); + for (CommandNode node : rootCommandNode.getChildren()) { +@@ -505,8 +503,11 @@ public class Commands { + player.connection.send(new ClientboundCommandsPacket(rootCommandNode, COMMAND_NODE_INSPECTOR)); + } + +- private static void fillUsableCommands(java.util.Collection> children, CommandNode current, S source, Map, CommandNode> output) { // Paper - Perf: Async command map building; pass copy of children +- for (CommandNode commandNode : children) { // Paper - Perf: Async command map building; pass copy of children ++ // Paper PR start - Fix async command building throwing CME in some cases ++ private static void fillUsableCommands(CommandNode root, CommandNode current, S source, Map, CommandNode> output) { // Paper - Perf: Async command map building; pass copy of children ++ synchronized (root.children) { // Paper - Perf: Async command map building ++ for (CommandNode commandNode : root.getChildren()) { ++ // Paper PR end - Fix async command building throwing CME in some cases + // Paper start - Brigadier API + if (commandNode.clientNode != null) { + commandNode = commandNode.clientNode; +@@ -558,10 +559,11 @@ public class Commands { + output.put(commandNode, commandNode1); + current.addChild(commandNode1); + if (!commandNode.getChildren().isEmpty()) { +- fillUsableCommands(commandNode.getChildren(), commandNode1, source, output); // Paper - Perf: Async command map building; pass copy of children ++ fillUsableCommands(commandNode, commandNode1, source, output); // Paper PR - Fix async command building throwing CME in some cases + } + } + } ++ } // Paper PR - Fix async command building throwing CME in some cases + } + + public static LiteralArgumentBuilder literal(String name) { diff --git a/leaf-server/minecraft-patches/features/0271-fix-temptation-lookups.patch b/leaf-server/minecraft-patches/features/0272-fix-temptation-lookups.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0271-fix-temptation-lookups.patch rename to leaf-server/minecraft-patches/features/0272-fix-temptation-lookups.patch diff --git a/leaf-server/minecraft-patches/features/0272-Lithium-combined-heightmap-update.patch b/leaf-server/minecraft-patches/features/0273-Lithium-combined-heightmap-update.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0272-Lithium-combined-heightmap-update.patch rename to leaf-server/minecraft-patches/features/0273-Lithium-combined-heightmap-update.patch diff --git a/leaf-server/minecraft-patches/features/0273-Skip-PreCreatureSpawnEvent-if-no-listeners.patch b/leaf-server/minecraft-patches/features/0274-Skip-PreCreatureSpawnEvent-if-no-listeners.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0273-Skip-PreCreatureSpawnEvent-if-no-listeners.patch rename to leaf-server/minecraft-patches/features/0274-Skip-PreCreatureSpawnEvent-if-no-listeners.patch diff --git a/leaf-server/minecraft-patches/features/0274-optimize-goal-selector.patch b/leaf-server/minecraft-patches/features/0275-optimize-goal-selector.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0274-optimize-goal-selector.patch rename to leaf-server/minecraft-patches/features/0275-optimize-goal-selector.patch diff --git a/leaf-server/minecraft-patches/features/0275-thread-unsafe-chunk-map.patch b/leaf-server/minecraft-patches/features/0276-thread-unsafe-chunk-map.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0275-thread-unsafe-chunk-map.patch rename to leaf-server/minecraft-patches/features/0276-thread-unsafe-chunk-map.patch diff --git a/leaf-server/minecraft-patches/features/0276-optimize-SimpleBitStorage-object-layout.patch b/leaf-server/minecraft-patches/features/0277-optimize-SimpleBitStorage-object-layout.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0276-optimize-SimpleBitStorage-object-layout.patch rename to leaf-server/minecraft-patches/features/0277-optimize-SimpleBitStorage-object-layout.patch diff --git a/leaf-server/minecraft-patches/features/0277-optimize-get-chunk.patch b/leaf-server/minecraft-patches/features/0278-optimize-get-chunk.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0277-optimize-get-chunk.patch rename to leaf-server/minecraft-patches/features/0278-optimize-get-chunk.patch diff --git a/leaf-server/minecraft-patches/features/0278-remove-shouldTickBlocksAt-check.patch b/leaf-server/minecraft-patches/features/0279-remove-shouldTickBlocksAt-check.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0278-remove-shouldTickBlocksAt-check.patch rename to leaf-server/minecraft-patches/features/0279-remove-shouldTickBlocksAt-check.patch diff --git a/leaf-server/minecraft-patches/features/0279-optimize-PalettedContainer-get.patch b/leaf-server/minecraft-patches/features/0280-optimize-PalettedContainer-get.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0279-optimize-PalettedContainer-get.patch rename to leaf-server/minecraft-patches/features/0280-optimize-PalettedContainer-get.patch diff --git a/leaf-server/minecraft-patches/features/0280-optimize-LevelChunk-getBlockStateFinal.patch b/leaf-server/minecraft-patches/features/0281-optimize-LevelChunk-getBlockStateFinal.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0280-optimize-LevelChunk-getBlockStateFinal.patch rename to leaf-server/minecraft-patches/features/0281-optimize-LevelChunk-getBlockStateFinal.patch diff --git a/leaf-server/minecraft-patches/features/0281-optimize-FluidState-is-TagKey.patch b/leaf-server/minecraft-patches/features/0282-optimize-FluidState-is-TagKey.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0281-optimize-FluidState-is-TagKey.patch rename to leaf-server/minecraft-patches/features/0282-optimize-FluidState-is-TagKey.patch diff --git a/leaf-server/minecraft-patches/features/0282-counting-chunk-section-fluid.patch b/leaf-server/minecraft-patches/features/0283-counting-chunk-section-fluid.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0282-counting-chunk-section-fluid.patch rename to leaf-server/minecraft-patches/features/0283-counting-chunk-section-fluid.patch diff --git a/leaf-server/minecraft-patches/features/0283-optimize-SpreadingSnowyDirtBlock-randomTick.patch b/leaf-server/minecraft-patches/features/0284-optimize-SpreadingSnowyDirtBlock-randomTick.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0283-optimize-SpreadingSnowyDirtBlock-randomTick.patch rename to leaf-server/minecraft-patches/features/0284-optimize-SpreadingSnowyDirtBlock-randomTick.patch diff --git a/leaf-server/minecraft-patches/features/0284-optimize-onClimbable.patch b/leaf-server/minecraft-patches/features/0285-optimize-onClimbable.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0284-optimize-onClimbable.patch rename to leaf-server/minecraft-patches/features/0285-optimize-onClimbable.patch diff --git a/leaf-server/minecraft-patches/features/0285-optimize-applyMovementEmissionAndPlaySound.patch b/leaf-server/minecraft-patches/features/0286-optimize-applyMovementEmissionAndPlaySound.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0285-optimize-applyMovementEmissionAndPlaySound.patch rename to leaf-server/minecraft-patches/features/0286-optimize-applyMovementEmissionAndPlaySound.patch diff --git a/leaf-server/minecraft-patches/features/0286-optimize-isStateClimbable.patch b/leaf-server/minecraft-patches/features/0287-optimize-isStateClimbable.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0286-optimize-isStateClimbable.patch rename to leaf-server/minecraft-patches/features/0287-optimize-isStateClimbable.patch diff --git a/leaf-server/minecraft-patches/features/0287-optimize-getOnPos.patch b/leaf-server/minecraft-patches/features/0288-optimize-getOnPos.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0287-optimize-getOnPos.patch rename to leaf-server/minecraft-patches/features/0288-optimize-getOnPos.patch diff --git a/leaf-server/minecraft-patches/features/0288-cache-eye-block-position.patch b/leaf-server/minecraft-patches/features/0289-cache-eye-block-position.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0288-cache-eye-block-position.patch rename to leaf-server/minecraft-patches/features/0289-cache-eye-block-position.patch diff --git a/leaf-server/minecraft-patches/features/0289-optimize-entity-in-fluid.patch b/leaf-server/minecraft-patches/features/0290-optimize-entity-in-fluid.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0289-optimize-entity-in-fluid.patch rename to leaf-server/minecraft-patches/features/0290-optimize-entity-in-fluid.patch diff --git a/leaf-server/minecraft-patches/features/0290-optimize-checkInsideBlocks.patch b/leaf-server/minecraft-patches/features/0291-optimize-checkInsideBlocks.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0290-optimize-checkInsideBlocks.patch rename to leaf-server/minecraft-patches/features/0291-optimize-checkInsideBlocks.patch diff --git a/leaf-server/minecraft-patches/features/0291-Replace-entity-fluid-height-map.patch b/leaf-server/minecraft-patches/features/0292-Replace-entity-fluid-height-map.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0291-Replace-entity-fluid-height-map.patch rename to leaf-server/minecraft-patches/features/0292-Replace-entity-fluid-height-map.patch diff --git a/leaf-server/minecraft-patches/features/0292-optimize-collision-shape.patch b/leaf-server/minecraft-patches/features/0293-optimize-collision-shape.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0292-optimize-collision-shape.patch rename to leaf-server/minecraft-patches/features/0293-optimize-collision-shape.patch diff --git a/leaf-server/minecraft-patches/features/0293-cache-collision-list.patch b/leaf-server/minecraft-patches/features/0294-cache-collision-list.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0293-cache-collision-list.patch rename to leaf-server/minecraft-patches/features/0294-cache-collision-list.patch diff --git a/leaf-server/minecraft-patches/features/0294-fast-bit-radix-sort.patch b/leaf-server/minecraft-patches/features/0295-fast-bit-radix-sort.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0294-fast-bit-radix-sort.patch rename to leaf-server/minecraft-patches/features/0295-fast-bit-radix-sort.patch diff --git a/leaf-server/minecraft-patches/features/0295-optimize-tickEffects.patch b/leaf-server/minecraft-patches/features/0296-optimize-tickEffects.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0295-optimize-tickEffects.patch rename to leaf-server/minecraft-patches/features/0296-optimize-tickEffects.patch diff --git a/leaf-server/minecraft-patches/features/0296-Pluto-Expose-Direction-Plane-s-faces.patch b/leaf-server/minecraft-patches/features/0297-Pluto-Expose-Direction-Plane-s-faces.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0296-Pluto-Expose-Direction-Plane-s-faces.patch rename to leaf-server/minecraft-patches/features/0297-Pluto-Expose-Direction-Plane-s-faces.patch diff --git a/leaf-server/minecraft-patches/features/0297-Pluto-reduce-allocation.patch b/leaf-server/minecraft-patches/features/0298-Pluto-reduce-allocation.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0297-Pluto-reduce-allocation.patch rename to leaf-server/minecraft-patches/features/0298-Pluto-reduce-allocation.patch diff --git a/leaf-server/minecraft-patches/features/0298-Only-update-frozen-ticks-if-changed.patch b/leaf-server/minecraft-patches/features/0299-Only-update-frozen-ticks-if-changed.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0298-Only-update-frozen-ticks-if-changed.patch rename to leaf-server/minecraft-patches/features/0299-Only-update-frozen-ticks-if-changed.patch diff --git a/leaf-server/minecraft-patches/features/0299-Prevent-executing-commands-if-server-stopped.patch b/leaf-server/minecraft-patches/features/0300-Prevent-executing-commands-if-server-stopped.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0299-Prevent-executing-commands-if-server-stopped.patch rename to leaf-server/minecraft-patches/features/0300-Prevent-executing-commands-if-server-stopped.patch diff --git a/leaf-server/minecraft-patches/features/0300-optimize-canHoldAnyFluid.patch b/leaf-server/minecraft-patches/features/0301-optimize-canHoldAnyFluid.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0300-optimize-canHoldAnyFluid.patch rename to leaf-server/minecraft-patches/features/0301-optimize-canHoldAnyFluid.patch diff --git a/leaf-server/minecraft-patches/features/0301-Fix-MC-299642.patch b/leaf-server/minecraft-patches/features/0302-Fix-MC-299642.patch similarity index 100% rename from leaf-server/minecraft-patches/features/0301-Fix-MC-299642.patch rename to leaf-server/minecraft-patches/features/0302-Fix-MC-299642.patch