From d813c8b7801a4f074ccb50470f98b4d4a93491ab Mon Sep 17 00:00:00 2001 From: Brianna Date: Sat, 4 Apr 2020 08:43:24 -0400 Subject: [PATCH] Added better use of CompatibleMaterial. --- .../defaultinv/DefaultInventory.java | 8 +++-- .../levelling/rework/IslandLevelManager.java | 31 ++++++------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/songoda/skyblock/challenge/defaultinv/DefaultInventory.java b/src/main/java/com/songoda/skyblock/challenge/defaultinv/DefaultInventory.java index 8adf7340..b53a49ee 100644 --- a/src/main/java/com/songoda/skyblock/challenge/defaultinv/DefaultInventory.java +++ b/src/main/java/com/songoda/skyblock/challenge/defaultinv/DefaultInventory.java @@ -4,6 +4,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import com.songoda.core.compatibility.CompatibleMaterial; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -38,13 +39,14 @@ public class DefaultInventory { String name = ChatColor.translateAlternateColorCodes('&', configLoad.getString(k + ".name")); List lore = toColor(configLoad.getStringList(k + ".lore")); int redirect = configLoad.getInt(k + ".redirect"); - Material item = Material.matchMaterial(strItem); - if (item == null || item == Material.AIR) { + CompatibleMaterial material = CompatibleMaterial.getMaterial(strItem); + if (material == null || material == CompatibleMaterial.AIR) { Bukkit.getLogger().warning("Item " + strItem + " is not a Material"); continue; } - ItemStack is = new ItemStack(item, amount); + ItemStack is = material.getItem(); + is.setAmount(amount); ItemMeta im = is.getItemMeta(); im.setDisplayName(name); im.setLore(lore); diff --git a/src/main/java/com/songoda/skyblock/levelling/rework/IslandLevelManager.java b/src/main/java/com/songoda/skyblock/levelling/rework/IslandLevelManager.java index 4c0640cd..7039b06b 100644 --- a/src/main/java/com/songoda/skyblock/levelling/rework/IslandLevelManager.java +++ b/src/main/java/com/songoda/skyblock/levelling/rework/IslandLevelManager.java @@ -68,11 +68,6 @@ public final class IslandLevelManager { public static boolean isDoubleCheckedBlock(Block block) { return CHECKED_DOUBLE_TYPES.contains(parseType(block)); } - - private static CompatibleMaterial parseType(Block block) { - return CompatibleMaterial.getBlockMaterial(block.getType()); - } - public void startScan(Player attemptScanner, Island island) { if (!Bukkit.isPrimaryThread()) { @@ -185,52 +180,44 @@ public final class IslandLevelManager { if (blockType == CompatibleMaterial.AIR) return EMPTY; - CompatibleMaterial compMaterial = parseType(block); + CompatibleMaterial compMaterial = CompatibleMaterial.getMaterial(block); if (compMaterial == null) return EMPTY; - Material finalType = compMaterial.getMaterial(); - - if (finalType == null) return EMPTY; - final Location blockLocation = block.getLocation(); if (scan.getDoubleBlocks().contains(blockLocation)) return EMPTY; if (CHECKED_DOUBLE_TYPES.contains(finalType)) { - final Block belowBlock = block.getRelative(BlockFace.DOWN); - final CompatibleMaterial belowType = parseType(belowBlock); + final CompatibleMaterial belowMaterial = CompatibleMaterial.getMaterial(belowBlock); if (CHECKED_DOUBLE_TYPES.contains(belowType)) { block = belowBlock; - blockType = belowType; + blockType = belowMaterial; scan.getDoubleBlocks().add(belowBlock.getLocation()); } else { scan.getDoubleBlocks().add(block.getRelative(BlockFace.UP).getLocation()); } - } else if (finalType == CompatibleMaterial.SPAWNER.getBlockMaterial()) { - finalType = CompatibleSpawners.getSpawner(((CreatureSpawner) block.getState()).getSpawnedType()).getMaterial(); } final List calculators = CalculatorRegistry.getCalculators(blockType); final StackableManager stackableManager = SkyBlock.getInstance().getStackableManager(); - final CompatibleMaterial finalCompatMat = CompatibleMaterial.getMaterial(finalType); - final long stackSize = stackableManager == null ? 0 : stackableManager.getStackSizeOf(blockLocation, finalCompatMat); + final long stackSize = stackableManager == null ? 0 : stackableManager.getStackSizeOf(blockLocation, compMaterial); if (calculators == null) { - if (stackSize > 1) return new AmountMaterialPair(finalCompatMat, stackSize); + if (stackSize > 1) return new AmountMaterialPair(compMaterial, stackSize); - AmountMaterialPair cachedPair = cachedPairs.get(finalType); + AmountMaterialPair cachedPair = cachedPairs.get(compMaterial); if (cachedPair != null) return cachedPair; - cachedPair = new AmountMaterialPair(finalCompatMat, 1); - cachedPairs.put(finalCompatMat, cachedPair); + cachedPair = new AmountMaterialPair(compMaterial, 1); + cachedPairs.put(compMaterial, cachedPair); return cachedPair; } @@ -243,7 +230,7 @@ public final class IslandLevelManager { if (amount == 0) amount = 1; - return new AmountMaterialPair(finalCompatMat, amount + stackSize); + return new AmountMaterialPair(compMaterial, amount + stackSize); } }