diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java | 36 |
1 files changed, 29 insertions, 7 deletions
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<?>, Enum<?>> nmsToBukkit = HashBiMap.create(); + private static final Map<Class, BiMap<Enum<?>, 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 extends Enum<B>> B toBukkit(Enum<?> nms, Class<B> bukkit) { - Enum<?> converted = nmsToBukkit.get(nms); - if (converted != null) { - return (B) converted; + Enum<?> converted; + BiMap<Enum<?>, 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 <N extends Enum<N> & INamable> N toNMS(Enum<?> bukkit, Class<N> nms) { - Enum<?> converted = nmsToBukkit.inverse().get(bukkit); - if (converted != null) { - return (N) converted; + Enum<?> converted; + BiMap<Enum<?>, 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; |