From fdb9d77710379e955c2fbbe0386efdc816f5ccd1 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Tue, 28 Aug 2018 18:45:24 +1000 Subject: [PATCH] Finish the BlockData caching in Bukkit --- .../java/com/sk89q/worldedit/bukkit/BukkitAdapter.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index f7500168a..7b0aa4ff6 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -345,6 +345,8 @@ public class BukkitAdapter { }); } + private static Map blockDataCache = new HashMap<>(); + /** * Create a Bukkit BlockData from a WorldEdit BlockStateHolder * @@ -353,7 +355,13 @@ public class BukkitAdapter { */ public static BlockData adapt(BlockStateHolder block) { checkNotNull(block); - return Bukkit.createBlockData(block.getAsString()); + return blockDataCache.computeIfAbsent(block.getAsString(), new Function() { + @Nullable + @Override + public BlockData apply(@Nullable String input) { + return Bukkit.createBlockData(block.getAsString()); + } + }).clone(); } /**