From 240a817e6efd3e2d17502f40c077d2c5c94bea55 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Sun, 26 Jan 2020 16:45:07 -0500 Subject: [PATCH] Using an array instead of an EnumMap isn't necessary here --- .../worldedit/bukkit/BukkitBlockRegistry.java | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 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 d69f66933..f728c00fd 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,6 +27,7 @@ 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; @@ -38,7 +39,7 @@ import java.util.OptionalInt; public class BukkitBlockRegistry extends BundledBlockRegistry { - private BukkitBlockMaterial[] materialMap; + private Map materialMap = new EnumMap<>(Material.class); @Nullable @Override @@ -52,15 +53,17 @@ public class BukkitBlockRegistry extends BundledBlockRegistry { if (mat == null) { return new PassthroughBlockMaterial(null); } - if (materialMap == null) { - materialMap = new BukkitBlockMaterial[Material.values().length]; + 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); } - BukkitBlockMaterial result = materialMap[mat.ordinal()]; - if (result == null) { - result = new BukkitBlockMaterial(BukkitBlockRegistry.super.getMaterial(blockType), mat); - materialMap[mat.ordinal()] = result; - } - return result; + return super.getProperties(blockType); } @Nullable @@ -73,7 +76,6 @@ public class BukkitBlockRegistry extends BundledBlockRegistry { } return super.getMaterial(state); } - @Override public OptionalInt getInternalBlockStateId(BlockState state) { if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { @@ -81,15 +83,6 @@ 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 {