From f6a18ef777b95f040733f3a02204e14346ab5afc Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 6 Mar 2013 11:31:51 -0500 Subject: [PATCH] Move Salvage functions into Repair --- .../commands/skills/RepairCommand.java | 5 +- .../nossr50/datatypes/player/McMMOPlayer.java | 9 +- .../nossr50/listeners/BlockListener.java | 3 +- .../nossr50/listeners/PlayerListener.java | 5 +- .../gmail/nossr50/skills/repair/Repair.java | 87 +++++++++++++++++-- .../nossr50/skills/repair/RepairManager.java | 4 +- .../gmail/nossr50/skills/repair/Salvage.java | 85 ------------------ 7 files changed, 93 insertions(+), 105 deletions(-) delete mode 100644 src/main/java/com/gmail/nossr50/skills/repair/Salvage.java diff --git a/src/main/java/com/gmail/nossr50/commands/skills/RepairCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/RepairCommand.java index e01fce126..6f6f56a45 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/RepairCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/RepairCommand.java @@ -7,7 +7,6 @@ import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.Repairable; -import com.gmail.nossr50.skills.repair.Salvage; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.player.UserManager; @@ -123,8 +122,8 @@ public class RepairCommand extends SkillCommand { player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.6", diamondLevel), LocaleLoader.getString("Repair.Effect.7"))); } - if (canSalvage && Salvage.salvageUnlockLevel > 0) { - player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.16", Salvage.salvageUnlockLevel), LocaleLoader.getString("Repair.Effect.17"))); + if (canSalvage && Repair.salvageUnlockLevel > 0) { + player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Repair.Effect.16", Repair.salvageUnlockLevel), LocaleLoader.getString("Repair.Effect.17"))); } if (canArcaneForge) { diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 63d1e283c..3d8d6392a 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -30,7 +30,6 @@ import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.RepairManager; -import com.gmail.nossr50.skills.repair.Salvage; import com.gmail.nossr50.skills.smelting.SmeltingManager; import com.gmail.nossr50.skills.swords.SwordsManager; import com.gmail.nossr50.skills.taming.TamingManager; @@ -316,11 +315,11 @@ public class McMMOPlayer { */ public boolean getPlacedAnvil(int anvilId) { - if (anvilId == Repair.anvilID) { + if (anvilId == Repair.repairAnvilId) { return placedRepairAnvil; } - if (anvilId == Salvage.anvilID) { + if (anvilId == Repair.salvageAnvilId) { return placedSalvageAnvil; } @@ -328,11 +327,11 @@ public class McMMOPlayer { } public void togglePlacedAnvil(int anvilId) { - if (anvilId == Repair.anvilID) { + if (anvilId == Repair.repairAnvilId) { placedRepairAnvil = !placedRepairAnvil; } - if (anvilId == Salvage.anvilID) { + if (anvilId == Repair.salvageAnvilId) { placedSalvageAnvil = !placedSalvageAnvil; } } diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 5913bc903..4ce6d067d 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -35,7 +35,6 @@ import com.gmail.nossr50.skills.excavation.ExcavationManager; import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.repair.Repair; -import com.gmail.nossr50.skills.repair.Salvage; import com.gmail.nossr50.skills.smelting.SmeltingManager; import com.gmail.nossr50.skills.unarmed.Unarmed; import com.gmail.nossr50.skills.woodcutting.Woodcutting; @@ -116,7 +115,7 @@ public class BlockListener implements Listener { mcMMO.placeStore.setTrue(blockState); } - if (Repair.anvilMessagesEnabled && (blockId == Repair.anvilID || blockId == Salvage.anvilID)) { + if (Repair.anvilMessagesEnabled && (blockId == Repair.repairAnvilId || blockId == Repair.salvageAnvilId)) { UserManager.getPlayer(player).getRepairManager().placedAnvilCheck(blockId); } } diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index d335c10b8..4358662a9 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -39,7 +39,6 @@ import com.gmail.nossr50.skills.fishing.FishingManager; import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.repair.Repair; -import com.gmail.nossr50.skills.repair.Salvage; import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.util.BlockUtils; import com.gmail.nossr50.util.ChimaeraWing; @@ -285,13 +284,13 @@ public class PlayerListener implements Listener { int blockID = block.getTypeId(); /* REPAIR CHECKS */ - if (blockID == Repair.anvilID && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.repairableManager.isRepairable(heldItem)) { + if (blockID == Repair.repairAnvilId && Permissions.skillEnabled(player, SkillType.REPAIR) && mcMMO.repairableManager.isRepairable(heldItem)) { UserManager.getPlayer(player).getRepairManager().handleRepair(heldItem); event.setCancelled(true); player.updateInventory(); } /* SALVAGE CHECKS */ - else if (blockID == Salvage.anvilID && Permissions.salvage(player) && Salvage.isSalvageable(heldItem)) { + else if (blockID == Repair.salvageAnvilId && Permissions.salvage(player) && Repair.isSalvageable(heldItem)) { UserManager.getPlayer(player).getRepairManager().handleSalvage(block.getLocation(), heldItem); event.setCancelled(true); player.updateInventory(); diff --git a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java index b56b92be4..511a69062 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java @@ -1,11 +1,13 @@ package com.gmail.nossr50.skills.repair; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.util.ItemUtils; public class Repair { // The order of the values is extremely important, a few methods depend on it to work properly @@ -51,9 +53,30 @@ public class Repair { public static boolean arcaneForgingDowngrades = AdvancedConfig.getInstance().getArcaneForgingDowngradeEnabled(); public static boolean arcaneForgingEnchantLoss = AdvancedConfig.getInstance().getArcaneForgingEnchantLossEnabled(); - public static int anvilID = Config.getInstance().getRepairAnvilId(); + public static int salvageUnlockLevel = AdvancedConfig.getInstance().getSalvageUnlockLevel(); + + public static int salvageAnvilId = Config.getInstance().getSalvageAnvilId(); + public static int repairAnvilId = Config.getInstance().getRepairAnvilId(); public static boolean anvilMessagesEnabled = Config.getInstance().getRepairAnvilMessagesEnabled(); + /** + * Checks if the item is salvageable. + * + * @param item Item to check + * @return true if the item is salvageable, false otherwise + */ + public static boolean isSalvageable(ItemStack item) { + if (Config.getInstance().getSalvageTools() && (ItemUtils.isMinecraftTool(item) || ItemUtils.isStringTool(item) || item.getType() == Material.BUCKET)) { + return true; + } + + if (Config.getInstance().getSalvageArmor() && ItemUtils.isMinecraftArmor(item)) { + return true; + } + + return false; + } + /** * Search the inventory for an item and return the index. * @@ -114,11 +137,11 @@ public class Repair { } protected static String[] getSpoutAnvilMessages(int blockId) { - if (blockId == Repair.anvilID) { + if (blockId == repairAnvilId) { return new String[] {LocaleLoader.getString("Repair.AnvilPlaced.Spout1"), LocaleLoader.getString("Repair.AnvilPlaced.Spout2")}; } - if (blockId == Salvage.anvilID) { + if (blockId == salvageAnvilId) { return new String[] {"[mcMMO] Anvil Placed", "Right click to salvage!"}; } @@ -126,14 +149,68 @@ public class Repair { } protected static String getAnvilMessage(int blockId) { - if (blockId == Repair.anvilID) { + if (blockId == repairAnvilId) { return LocaleLoader.getString("Repair.Listener.Anvil"); } - if (blockId == Salvage.anvilID) { + if (blockId == salvageAnvilId) { return LocaleLoader.getString("Repair.Listener.Anvil2"); } return ""; } + + protected static Material getSalvagedItem(ItemStack inHand) { + if (ItemUtils.isDiamondTool(inHand) || ItemUtils.isDiamondArmor(inHand)) { + return Material.DIAMOND; + } + else if (ItemUtils.isGoldTool(inHand) || ItemUtils.isGoldArmor(inHand)) { + return Material.GOLD_INGOT; + } + else if (ItemUtils.isIronTool(inHand) || ItemUtils.isIronArmor(inHand)) { + return Material.IRON_INGOT; + } + else if (ItemUtils.isStoneTool(inHand)) { + return Material.COBBLESTONE; + } + else if (ItemUtils.isWoodTool(inHand)) { + return Material.WOOD; + } + else if (ItemUtils.isLeatherArmor(inHand)) { + return Material.LEATHER; + } + else if (ItemUtils.isStringTool(inHand)) { + return Material.STRING; + } + else { + return null; + } + } + + protected static int getSalvagedAmount(ItemStack inHand) { + if (ItemUtils.isPickaxe(inHand) || ItemUtils.isAxe(inHand) || inHand.getType() == Material.BOW || inHand.getType() == Material.BUCKET) { + return 3; + } + else if (ItemUtils.isShovel(inHand) || inHand.getType() == Material.FLINT_AND_STEEL) { + return 1; + } + else if (ItemUtils.isSword(inHand) || ItemUtils.isHoe(inHand) || inHand.getType() == Material.CARROT_STICK || inHand.getType() == Material.FISHING_ROD || inHand.getType() == Material.SHEARS) { + return 2; + } + else if (ItemUtils.isHelmet(inHand)) { + return 5; + } + else if (ItemUtils.isChestplate(inHand)) { + return 8; + } + else if (ItemUtils.isLeggings(inHand)) { + return 7; + } + else if (ItemUtils.isBoots(inHand)) { + return 4; + } + else { + return 0; + } + } } diff --git a/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java b/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java index 478530de3..a4ac95751 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java @@ -179,7 +179,7 @@ public class RepairManager extends SkillManager { return; } - if (getSkillLevel() < Salvage.salvageUnlockLevel) { + if (getSkillLevel() < Repair.salvageUnlockLevel) { player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptSalvage")); return; } @@ -188,7 +188,7 @@ public class RepairManager extends SkillManager { player.setItemInHand(new ItemStack(Material.AIR)); location.setY(location.getY() + 1); - Misc.dropItems(location, new ItemStack(Salvage.getSalvagedItem(item)), Salvage.getSalvagedAmount(item)); + Misc.dropItems(location, new ItemStack(Repair.getSalvagedItem(item)), Repair.getSalvagedAmount(item)); player.playSound(player.getLocation(), Sound.ANVIL_USE, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH); player.sendMessage(LocaleLoader.getString("Repair.Skills.SalvageSuccess")); diff --git a/src/main/java/com/gmail/nossr50/skills/repair/Salvage.java b/src/main/java/com/gmail/nossr50/skills/repair/Salvage.java deleted file mode 100644 index 42a651b61..000000000 --- a/src/main/java/com/gmail/nossr50/skills/repair/Salvage.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.gmail.nossr50.skills.repair; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -import com.gmail.nossr50.config.AdvancedConfig; -import com.gmail.nossr50.config.Config; -import com.gmail.nossr50.util.ItemUtils; - -public class Salvage { - public static int salvageUnlockLevel = AdvancedConfig.getInstance().getSalvageUnlockLevel(); - public static int anvilID = Config.getInstance().getSalvageAnvilId(); - - /** - * Checks if the item is salvageable. - * - * @param is Item to check - * @return true if the item is salvageable, false otherwise - */ - public static boolean isSalvageable(final ItemStack is) { - if (Config.getInstance().getSalvageTools() && (ItemUtils.isMinecraftTool(is) || ItemUtils.isStringTool(is) || is.getType() == Material.BUCKET)) { - return true; - } - - if (Config.getInstance().getSalvageArmor() && ItemUtils.isMinecraftArmor(is)) { - return true; - } - - return false; - } - - protected static Material getSalvagedItem(final ItemStack inHand) { - if (ItemUtils.isDiamondTool(inHand) || ItemUtils.isDiamondArmor(inHand)) { - return Material.DIAMOND; - } - else if (ItemUtils.isGoldTool(inHand) || ItemUtils.isGoldArmor(inHand)) { - return Material.GOLD_INGOT; - } - else if (ItemUtils.isIronTool(inHand) || ItemUtils.isIronArmor(inHand)) { - return Material.IRON_INGOT; - } - else if (ItemUtils.isStoneTool(inHand)) { - return Material.COBBLESTONE; - } - else if (ItemUtils.isWoodTool(inHand)) { - return Material.WOOD; - } - else if (ItemUtils.isLeatherArmor(inHand)) { - return Material.LEATHER; - } - else if (ItemUtils.isStringTool(inHand)) { - return Material.STRING; - } - else { - return null; - } - } - - protected static int getSalvagedAmount(final ItemStack inHand) { - if (ItemUtils.isPickaxe(inHand) || ItemUtils.isAxe(inHand) || inHand.getType() == Material.BOW || inHand.getType() == Material.BUCKET) { - return 3; - } - else if (ItemUtils.isShovel(inHand) || inHand.getType() == Material.FLINT_AND_STEEL) { - return 1; - } - else if (ItemUtils.isSword(inHand) || ItemUtils.isHoe(inHand) || inHand.getType() == Material.CARROT_STICK || inHand.getType() == Material.FISHING_ROD || inHand.getType() == Material.SHEARS) { - return 2; - } - else if (ItemUtils.isHelmet(inHand)) { - return 5; - } - else if (ItemUtils.isChestplate(inHand)) { - return 8; - } - else if (ItemUtils.isLeggings(inHand)) { - return 7; - } - else if (ItemUtils.isBoots(inHand)) { - return 4; - } - else { - return 0; - } - } -}