From fbf903a1bcbb180194338da188077dba0ab93199 Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 24 Jul 2018 10:08:34 +1000 Subject: SPIGOT-4120: Store BlockData enum mappings per class --- .../craftbukkit/block/data/CraftBlockData.java | 36 +++++++++++++++++----- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java index 94549cee..d68fe947 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java +++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java @@ -89,7 +89,7 @@ public class CraftBlockData implements BlockData { this.state = this.state.set(nms, toNMS(bukkit, nms.b())); } - private static final BiMap, Enum> nmsToBukkit = HashBiMap.create(); + private static final Map, Enum>> classMappings = new HashMap<>(); /** * Convert an NMS Enum (usually a BlockStateEnum) to its appropriate Bukkit @@ -99,9 +99,14 @@ public class CraftBlockData implements BlockData { */ @SuppressWarnings("unchecked") private static > B toBukkit(Enum nms, Class bukkit) { - Enum converted = nmsToBukkit.get(nms); - if (converted != null) { - return (B) converted; + Enum converted; + BiMap, Enum> nmsToBukkit = classMappings.get(nms.getClass()); + + if (nmsToBukkit != null) { + converted = nmsToBukkit.get(nms); + if (converted != null) { + return (B) converted; + } } if (nms instanceof EnumDirection) { @@ -111,6 +116,12 @@ public class CraftBlockData implements BlockData { } Preconditions.checkState(converted != null, "Could not convert enum %s->%s", nms, bukkit); + + if (nmsToBukkit == null) { + nmsToBukkit = HashBiMap.create(); + classMappings.put(nms.getClass(), nmsToBukkit); + } + nmsToBukkit.put(nms, converted); return (B) converted; @@ -126,9 +137,14 @@ public class CraftBlockData implements BlockData { */ @SuppressWarnings("unchecked") private static & INamable> N toNMS(Enum bukkit, Class nms) { - Enum converted = nmsToBukkit.inverse().get(bukkit); - if (converted != null) { - return (N) converted; + Enum converted; + BiMap, Enum> nmsToBukkit = classMappings.get(nms.getClass()); + + if (nmsToBukkit != null) { + converted = nmsToBukkit.inverse().get(bukkit); + if (converted != null) { + return (N) converted; + } } if (bukkit instanceof BlockFace) { @@ -138,6 +154,12 @@ public class CraftBlockData implements BlockData { } Preconditions.checkState(converted != null, "Could not convert enum %s->%s", nms, bukkit); + + if (nmsToBukkit == null) { + nmsToBukkit = HashBiMap.create(); + classMappings.put(nms.getClass(), nmsToBukkit); + } + nmsToBukkit.put(converted, bukkit); return (N) converted; -- cgit v1.2.3