diff --git a/src/main/java/com/gmail/nossr50/skills/smelting/Smelting.java b/src/main/java/com/gmail/nossr50/skills/smelting/Smelting.java index 115bf5bdd..6222191d3 100644 --- a/src/main/java/com/gmail/nossr50/skills/smelting/Smelting.java +++ b/src/main/java/com/gmail/nossr50/skills/smelting/Smelting.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.skills.smelting; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import org.bukkit.material.MaterialData; import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.experience.ExperienceConfig; @@ -49,14 +50,9 @@ public class Smelting { public static double fluxMiningChance = AdvancedConfig.getInstance().getFluxMiningChance(); protected static int getResourceXp(ItemStack smelting) { + MaterialData data = smelting.getData(); Material resourceType = smelting.getType(); - int xp = ExperienceConfig.getInstance().getXp(SkillType.SMELTING, resourceType != Material.GLOWING_REDSTONE_ORE ? resourceType : Material.REDSTONE_ORE); - - if (xp == 0 && ModUtils.isCustomOreBlock(smelting)) { - xp = ModUtils.getCustomSmeltingBlock(smelting).getSmeltingXpGain(); - } - - return xp; + return ModUtils.isCustomOre(data) ? ModUtils.getCustomBlock(data).getSmeltingXpGain() : ExperienceConfig.getInstance().getXp(SkillType.SMELTING, resourceType != Material.GLOWING_REDSTONE_ORE ? resourceType : Material.REDSTONE_ORE); } } diff --git a/src/main/java/com/gmail/nossr50/util/BlockUtils.java b/src/main/java/com/gmail/nossr50/util/BlockUtils.java index 247322e44..43af44c02 100644 --- a/src/main/java/com/gmail/nossr50/util/BlockUtils.java +++ b/src/main/java/com/gmail/nossr50/util/BlockUtils.java @@ -75,21 +75,7 @@ public final class BlockUtils { * @return true if the block is an ore, false otherwise */ public static boolean isOre(BlockState blockState) { - switch (blockState.getType()) { - case COAL_ORE: - case DIAMOND_ORE: - case GLOWING_REDSTONE_ORE: - case GOLD_ORE: - case IRON_ORE: - case LAPIS_ORE: - case QUARTZ_ORE: - case REDSTONE_ORE: - case EMERALD_ORE: - return true; - - default: - return ModUtils.isCustomOreBlock(blockState); - } + return MaterialUtils.isOre(blockState.getData()); } /** diff --git a/src/main/java/com/gmail/nossr50/util/ItemUtils.java b/src/main/java/com/gmail/nossr50/util/ItemUtils.java index 05171858b..eb6c2fd30 100644 --- a/src/main/java/com/gmail/nossr50/util/ItemUtils.java +++ b/src/main/java/com/gmail/nossr50/util/ItemUtils.java @@ -1,27 +1,23 @@ package com.gmail.nossr50.util; -import java.util.List; - import org.bukkit.ChatColor; -import org.bukkit.CoalType; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.inventory.FurnaceRecipe; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.material.Coal; import org.bukkit.material.Dye; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.mods.CustomArmorConfig; -import com.gmail.nossr50.config.mods.CustomBlockConfig; import com.gmail.nossr50.config.mods.CustomToolConfig; import com.gmail.nossr50.config.party.ItemWeightConfig; import com.gmail.nossr50.locale.LocaleLoader; -public class ItemUtils { +public final class ItemUtils { + private ItemUtils() {} /** * Checks if the item is a bow. @@ -509,21 +505,7 @@ public class ItemUtils { return false; } - switch (item.getType()) { - case COAL_ORE: - case DIAMOND_ORE: - case GLOWING_REDSTONE_ORE: - case GOLD_ORE: - case IRON_ORE: - case LAPIS_ORE: - case REDSTONE_ORE: - case EMERALD_ORE: - case QUARTZ_ORE: - return true; - - default: - return Config.getInstance().getBlockModsEnabled() && CustomBlockConfig.getInstance().isCustomOre(item.getData()); - } + return MaterialUtils.isOre(item.getData()); } public static boolean isSmelted(ItemStack item) { @@ -531,32 +513,13 @@ public class ItemUtils { return false; } - switch (item.getType()) { - case COAL: - return ((Coal) item.getData()).getType() == CoalType.COAL; - - case DIAMOND: - case REDSTONE: - case GOLD_INGOT: - case IRON_INGOT: - case EMERALD: - case QUARTZ: - return true; - - case INK_SACK: - return ((Dye) item.getData()).getColor() == DyeColor.BLUE; - - default: - List recipeList = mcMMO.p.getServer().getRecipesFor(item); - - for (Recipe recipe : recipeList) { - if (recipe instanceof FurnaceRecipe) { - return Config.getInstance().getBlockModsEnabled() && CustomBlockConfig.getInstance().isCustomOre(((FurnaceRecipe) recipe).getInput().getData()); - } - } - - return false; + for (Recipe recipe : mcMMO.p.getServer().getRecipesFor(item)) { + if (recipe instanceof FurnaceRecipe) { + return MaterialUtils.isOre(((FurnaceRecipe) recipe).getInput().getData()); + } } + + return false; } /** diff --git a/src/main/java/com/gmail/nossr50/util/MaterialUtils.java b/src/main/java/com/gmail/nossr50/util/MaterialUtils.java new file mode 100644 index 000000000..a2ecdc120 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/util/MaterialUtils.java @@ -0,0 +1,25 @@ +package com.gmail.nossr50.util; + +import org.bukkit.material.MaterialData; + +public final class MaterialUtils { + private MaterialUtils() {} + + protected static boolean isOre(MaterialData data) { + switch (data.getItemType()) { + case COAL_ORE: + case DIAMOND_ORE: + case GLOWING_REDSTONE_ORE: + case GOLD_ORE: + case IRON_ORE: + case LAPIS_ORE: + case QUARTZ_ORE: + case REDSTONE_ORE: + case EMERALD_ORE: + return true; + + default: + return ModUtils.isCustomOre(data); + } + } +} diff --git a/src/main/java/com/gmail/nossr50/util/ModUtils.java b/src/main/java/com/gmail/nossr50/util/ModUtils.java index bc3cda88a..d9ad50a95 100644 --- a/src/main/java/com/gmail/nossr50/util/ModUtils.java +++ b/src/main/java/com/gmail/nossr50/util/ModUtils.java @@ -7,6 +7,7 @@ import org.bukkit.block.BlockState; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Entity; import org.bukkit.inventory.ItemStack; +import org.bukkit.material.MaterialData; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; @@ -55,8 +56,8 @@ public final class ModUtils { return CustomBlockConfig.getInstance().getCustomBlock(blockState.getData()); } - public static CustomBlock getCustomSmeltingBlock(ItemStack smelting) { - return CustomBlockConfig.getInstance().getCustomBlock(smelting.getData()); + public static CustomBlock getCustomBlock(MaterialData data) { + return CustomBlockConfig.getInstance().getCustomBlock(data); } /** @@ -129,24 +130,8 @@ public final class ModUtils { return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomLog(blockState.getData()); } - /** - * Check if a custom block is an ore block. - * - * @param blockState The BlockState of the block to check - * @return true if the block represents an ore, false otherwise - */ - public static boolean isCustomOreBlock(BlockState blockState) { - return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomOre(blockState.getData()); - } - - /** - * Check if a custom block is an ore block. - * - * @param item The ItemStack of the block to check - * @return true if the block represents an ore, false otherwise - */ - public static boolean isCustomOreBlock(ItemStack item) { - return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomOre(item.getData()); + public static boolean isCustomOre(MaterialData data) { + return customBlocksEnabled && CustomBlockConfig.getInstance().isCustomOre(data); } /**