From d381617f112975356cb65a4874de9a5d87ce2a4d Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Wed, 29 Jan 2020 16:03:02 -0500 Subject: [PATCH] Revert "Using an array instead of an EnumMap isn't necessary here" This reverts commit 240a817e --- .../worldedit/bukkit/BukkitBlockRegistry.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java index f728c00fd..d69f66933 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java @@ -27,7 +27,6 @@ import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BundledBlockRegistry; import com.sk89q.worldedit.world.registry.PassthroughBlockMaterial; -import java.util.EnumMap; import org.bukkit.Material; import org.bukkit.block.data.BlockData; @@ -39,7 +38,7 @@ import java.util.OptionalInt; public class BukkitBlockRegistry extends BundledBlockRegistry { - private Map materialMap = new EnumMap<>(Material.class); + private BukkitBlockMaterial[] materialMap; @Nullable @Override @@ -53,17 +52,15 @@ public class BukkitBlockRegistry extends BundledBlockRegistry { if (mat == null) { return new PassthroughBlockMaterial(null); } - return materialMap.computeIfAbsent(mat, material -> new BukkitBlockMaterial(BukkitBlockRegistry.super.getMaterial(blockType), material)); - } - - @Nullable - @Override - public Map> getProperties(BlockType blockType) { - BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); - if (adapter != null) { - return adapter.getProperties(blockType); + if (materialMap == null) { + materialMap = new BukkitBlockMaterial[Material.values().length]; } - return super.getProperties(blockType); + BukkitBlockMaterial result = materialMap[mat.ordinal()]; + if (result == null) { + result = new BukkitBlockMaterial(BukkitBlockRegistry.super.getMaterial(blockType), mat); + materialMap[mat.ordinal()] = result; + } + return result; } @Nullable @@ -76,6 +73,7 @@ public class BukkitBlockRegistry extends BundledBlockRegistry { } return super.getMaterial(state); } + @Override public OptionalInt getInternalBlockStateId(BlockState state) { if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { @@ -83,6 +81,15 @@ public class BukkitBlockRegistry extends BundledBlockRegistry { } return OptionalInt.empty(); } + @Nullable + @Override + public Map> getProperties(BlockType blockType) { + BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); + if (adapter != null) { + return adapter.getProperties(blockType); + } + return super.getProperties(blockType); + } public static class BukkitBlockMaterial extends PassthroughBlockMaterial {