A whole bunch of more work to convert Salvage to a child skill

This commit is contained in:
TfT_02
2013-12-14 14:27:50 +01:00
parent 91bf54019e
commit 4643cf1070
37 changed files with 1008 additions and 376 deletions

View File

@ -1,12 +1,9 @@
package com.gmail.nossr50.skills.salvage;
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;
import com.gmail.nossr50.util.skills.SkillUtils;
public class Salvage {
// The order of the values is extremely important, a few methods depend on it to work properly
@ -53,58 +50,8 @@ public class Salvage {
public static boolean arcaneSalvageDowngrades = AdvancedConfig.getInstance().getArcaneSalvageEnchantDowngradeEnabled();
public static boolean arcaneSalvageEnchantLoss = AdvancedConfig.getInstance().getArcaneSalvageEnchantLossEnabled();
/**
* 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)) {
return true;
}
if (Config.getInstance().getSalvageArmor() && !ItemUtils.isChainmailArmor(item) && ItemUtils.isMinecraftArmor(item)) {
return true;
}
return false;
}
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) {
return SkillUtils.getRepairAndSalvageQuantities(inHand, getSalvagedItem(inHand), (byte) -1);
}
protected static int calculateSalvageableAmount(short currentDurability, short maxDurability, int baseAmount) {
double percentDamaged = (double) (maxDurability - currentDurability) / maxDurability;
double percentDamaged = (maxDurability <= 0) ? 1D : (double) (maxDurability - currentDurability) / maxDurability;
return (int) Math.floor(baseAmount * percentDamaged);
}