diff options
author | md_5 <git@md-5.net> | 2018-07-24 10:08:34 +1000 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-07-24 10:08:34 +1000 |
commit | fbf903a1bcbb180194338da188077dba0ab93199 (patch) | |
tree | dbccedb23665c6cf4da3f1c4b90cea54f2530d99 /src/main/java/org | |
parent | ea7b61290a39f0ab355d7a723907ed312f713b05 (diff) | |
download | craftbukkit-fbf903a1bcbb180194338da188077dba0ab93199.tar craftbukkit-fbf903a1bcbb180194338da188077dba0ab93199.tar.gz craftbukkit-fbf903a1bcbb180194338da188077dba0ab93199.tar.lz craftbukkit-fbf903a1bcbb180194338da188077dba0ab93199.tar.xz craftbukkit-fbf903a1bcbb180194338da188077dba0ab93199.zip |
SPIGOT-4120: Store BlockData enum mappings per class
Diffstat (limited to 'src/main/java/org')
-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; |