|
@@ -1,11 +1,13 @@
|
|
package com.gmail.nossr50.skills.repair;
|
|
package com.gmail.nossr50.skills.repair;
|
|
|
|
|
|
|
|
+import org.bukkit.Material;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
|
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
|
import com.gmail.nossr50.config.Config;
|
|
import com.gmail.nossr50.config.Config;
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
+import com.gmail.nossr50.util.ItemUtils;
|
|
|
|
|
|
public class Repair {
|
|
public class Repair {
|
|
// The order of the values is extremely important, a few methods depend on it to work properly
|
|
// 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 arcaneForgingDowngrades = AdvancedConfig.getInstance().getArcaneForgingDowngradeEnabled();
|
|
public static boolean arcaneForgingEnchantLoss = AdvancedConfig.getInstance().getArcaneForgingEnchantLossEnabled();
|
|
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();
|
|
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.
|
|
* Search the inventory for an item and return the index.
|
|
*
|
|
*
|
|
@@ -114,11 +137,11 @@ public class Repair {
|
|
}
|
|
}
|
|
|
|
|
|
protected static String[] getSpoutAnvilMessages(int blockId) {
|
|
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")};
|
|
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!"};
|
|
return new String[] {"[mcMMO] Anvil Placed", "Right click to salvage!"};
|
|
}
|
|
}
|
|
|
|
|
|
@@ -126,14 +149,68 @@ public class Repair {
|
|
}
|
|
}
|
|
|
|
|
|
protected static String getAnvilMessage(int blockId) {
|
|
protected static String getAnvilMessage(int blockId) {
|
|
- if (blockId == Repair.anvilID) {
|
|
|
|
|
|
+ if (blockId == repairAnvilId) {
|
|
return LocaleLoader.getString("Repair.Listener.Anvil");
|
|
return LocaleLoader.getString("Repair.Listener.Anvil");
|
|
}
|
|
}
|
|
|
|
|
|
- if (blockId == Salvage.anvilID) {
|
|
|
|
|
|
+ if (blockId == salvageAnvilId) {
|
|
return LocaleLoader.getString("Repair.Listener.Anvil2");
|
|
return LocaleLoader.getString("Repair.Listener.Anvil2");
|
|
}
|
|
}
|
|
|
|
|
|
return "";
|
|
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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|