diff options
author | md_5 <git@md-5.net> | 2018-08-11 17:43:41 +1000 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-08-11 17:43:41 +1000 |
commit | 96778caabb82eff6c2155d016bea938cebed3953 (patch) | |
tree | b242c4057dcf98d67fa74b8adc09826aab3f2071 | |
parent | 29e75648741b877c06165d82241b6b3a417474f6 (diff) | |
download | craftbukkit-96778caabb82eff6c2155d016bea938cebed3953.tar craftbukkit-96778caabb82eff6c2155d016bea938cebed3953.tar.gz craftbukkit-96778caabb82eff6c2155d016bea938cebed3953.tar.lz craftbukkit-96778caabb82eff6c2155d016bea938cebed3953.tar.xz craftbukkit-96778caabb82eff6c2155d016bea938cebed3953.zip |
SPIGOT-4253: Add way to prioritise item conversion
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java | 16 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java | 5 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java b/src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java index 83ac79f7..15f24e9d 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftLegacy.java @@ -163,6 +163,10 @@ public class CraftLegacy { } public static Material fromLegacy(MaterialData materialData) { + return fromLegacy(materialData, false); + } + + public static Material fromLegacy(MaterialData materialData, boolean itemPriority) { Material material = materialData.getItemType(); if (material == null || !material.isLegacy()) { return material; @@ -170,7 +174,15 @@ public class CraftLegacy { Material mappedData = null; - if (material.isBlock()) { + // Try item first + if (itemPriority) { + Item item = materialToItem.get(materialData); + if (item != null) { + mappedData = CraftMagicNumbers.getMaterial(item); + } + } + + if (mappedData == null && material.isBlock()) { // Try exact match first IBlockData iblock = materialToData.get(materialData); if (iblock != null) { @@ -187,7 +199,7 @@ public class CraftLegacy { } // Fallback to matching item - if (mappedData == null) { + if (!itemPriority && mappedData == null) { Item item = materialToItem.get(materialData); if (item != null) { mappedData = CraftMagicNumbers.getMaterial(item); diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java index 3474536f..21d0062d 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -135,6 +135,11 @@ public final class CraftMagicNumbers implements UnsafeValues { } @Override + public Material fromLegacy(MaterialData material, boolean itemPriority) { + return CraftLegacy.fromLegacy(material, itemPriority); + } + + @Override public BlockData fromLegacy(Material material, byte data) { return CraftBlockData.fromData(getBlock(material, data)); } |