From a671db9b968f2feb0c5d10f6c96ca33092e56cb3 Mon Sep 17 00:00:00 2001 From: Pierre Maurice Schwang Date: Sun, 2 Jan 2022 18:29:21 +0100 Subject: [PATCH] Make BlockData creation thread safe again (#6876) --- patches/server/Cache-block-data-strings.patch | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/patches/server/Cache-block-data-strings.patch b/patches/server/Cache-block-data-strings.patch index e3d873f60b..b1ec9712b0 100644 --- a/patches/server/Cache-block-data-strings.patch +++ b/patches/server/Cache-block-data-strings.patch @@ -20,20 +20,12 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java +++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java -@@ -0,0 +0,0 @@ import net.minecraft.commands.arguments.blocks.BlockStateParser; - import net.minecraft.core.Direction; - import net.minecraft.core.Registry; - import net.minecraft.nbt.CompoundTag; -+import net.minecraft.resources.ResourceLocation; - import net.minecraft.util.StringRepresentable; - import net.minecraft.world.level.block.Block; - import net.minecraft.world.level.block.state.BlockState; @@ -0,0 +0,0 @@ public class CraftBlockData implements BlockData { Preconditions.checkState(CraftBlockData.MAP.put(nms, bukkit) == null, "Duplicate mapping %s->%s", nms, bukkit); } + // Paper start - cache block data strings -+ private static Map stringDataCache = new HashMap<>(); ++ private static Map stringDataCache = new java.util.concurrent.ConcurrentHashMap<>(); + + static { + // cache all of the default states at startup, will not cache ones with the custom states inside of the @@ -54,7 +46,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (material != null) { + Block block = CraftMagicNumbers.getBlock(material); + if (block != null) { -+ ResourceLocation key = Registry.BLOCK.getKey(block); ++ net.minecraft.resources.ResourceLocation key = Registry.BLOCK.getKey(block); + data = data == null ? key.toString() : key + data; + } + }