From 4578f40ffadc4c845b4bc62ad1352cee640d04e8 Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Sun, 27 Oct 2019 12:56:25 -0500 Subject: [PATCH] add block method for compatible material lookup --- .../compatibility/CompatibleMaterial.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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