diff --git a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java index 4c434c3c..e5e9d73b 100644 --- a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java +++ b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java @@ -6,6 +6,7 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; @@ -1220,6 +1221,27 @@ public enum CompatibleMaterial { return m != null ? m : lookupMap.get(key + item.getDurability()); } + /** + * Lookup a Material by Block, corrected for legacy + * + * @param block block to check + * @return LegacyMaterial or null if none found + */ + public static CompatibleMaterial getMaterial(Block block) { + if (block == null) { + return null; + } + Material mat = block.getType(); + if(mat == null) return null; + else if (useLegacy) { + LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(mat.name()); + if (legacyBlock != null) { + return lookupMap.get(legacyBlock.name()); + } + } + return lookupMap.get(mat.name()); + } + /** * Lookup a Block Material by its modern id name.
* This also can grab materials by their legacy, but only if there is no