2012-05-22 10:22:29 +02:00
|
|
|
package com.gmail.nossr50.skills.repair;
|
|
|
|
|
2013-03-06 17:31:51 +01:00
|
|
|
import org.bukkit.Material;
|
2012-05-22 10:22:29 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2013-03-06 15:37:09 +01:00
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
2012-05-22 10:22:29 +02:00
|
|
|
|
2012-11-21 21:49:54 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2013-01-24 20:19:26 +01:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-03-06 16:47:56 +01:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-03-06 17:31:51 +01:00
|
|
|
import com.gmail.nossr50.util.ItemUtils;
|
2012-05-22 10:22:29 +02:00
|
|
|
|
|
|
|
public class Repair {
|
2013-03-01 06:52:01 +01:00
|
|
|
public static int repairMasteryMaxBonusLevel = AdvancedConfig.getInstance().getRepairMasteryMaxLevel();
|
|
|
|
public static double repairMasteryMaxBonus = AdvancedConfig.getInstance().getRepairMasteryMaxBonus();
|
2012-11-21 21:49:54 +01:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
public static int superRepairMaxBonusLevel = AdvancedConfig.getInstance().getSuperRepairMaxLevel();
|
|
|
|
public static double superRepairMaxChance = AdvancedConfig.getInstance().getSuperRepairChanceMax();
|
2012-11-21 21:49:54 +01:00
|
|
|
|
2013-03-06 17:31:51 +01:00
|
|
|
public static int salvageUnlockLevel = AdvancedConfig.getInstance().getSalvageUnlockLevel();
|
|
|
|
|
|
|
|
public static int salvageAnvilId = Config.getInstance().getSalvageAnvilId();
|
|
|
|
public static int repairAnvilId = Config.getInstance().getRepairAnvilId();
|
2013-03-01 06:52:01 +01:00
|
|
|
public static boolean anvilMessagesEnabled = Config.getInstance().getRepairAnvilMessagesEnabled();
|
2012-05-22 10:22:29 +02:00
|
|
|
|
2013-03-06 17:31:51 +01:00
|
|
|
/**
|
|
|
|
* 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) {
|
2013-05-28 18:53:12 +02:00
|
|
|
if (Config.getInstance().getSalvageTools() && ItemUtils.isMinecraftTool(item)) {
|
2013-03-06 17:31:51 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Config.getInstance().getSalvageArmor() && ItemUtils.isMinecraftArmor(item)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-16 16:51:18 +02:00
|
|
|
public static String getAnvilMessage(int blockId) {
|
|
|
|
if (blockId == repairAnvilId) {
|
|
|
|
return LocaleLoader.getString("Repair.Listener.Anvil");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blockId == salvageAnvilId) {
|
|
|
|
return LocaleLoader.getString("Repair.Listener.Anvil2");
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String[] getSpoutAnvilMessages(int blockId) {
|
|
|
|
if (blockId == repairAnvilId) {
|
|
|
|
return new String[] {LocaleLoader.getString("Repair.AnvilPlaced.Spout1"), LocaleLoader.getString("Repair.AnvilPlaced.Spout2")};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blockId == salvageAnvilId) {
|
|
|
|
return new String[] {"[mcMMO] Anvil Placed", "Right click to salvage!"};
|
|
|
|
}
|
|
|
|
|
|
|
|
return new String[] {"", ""};
|
|
|
|
}
|
|
|
|
|
2012-05-22 10:22:29 +02:00
|
|
|
/**
|
2013-03-06 15:37:09 +01:00
|
|
|
* Search the inventory for an item and return the index.
|
2012-05-22 10:22:29 +02:00
|
|
|
*
|
2013-03-06 15:37:09 +01:00
|
|
|
* @param inventory PlayerInventory to scan
|
|
|
|
* @param itemId Item id to look for
|
|
|
|
* @return index location where the item was found, or -1 if not found
|
2012-05-22 10:22:29 +02:00
|
|
|
*/
|
2013-03-06 15:37:09 +01:00
|
|
|
protected static int findInInventory(PlayerInventory inventory, int itemId) {
|
|
|
|
int location = inventory.first(itemId);
|
2012-05-22 10:22:29 +02:00
|
|
|
|
2013-03-06 15:37:09 +01:00
|
|
|
// VALIDATE
|
|
|
|
if (inventory.getItem(location).getTypeId() == itemId) {
|
|
|
|
return location;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-03-06 15:37:09 +01:00
|
|
|
return -1;
|
2012-05-22 10:22:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-06 15:37:09 +01:00
|
|
|
* Search the inventory for an item and return the index.
|
2012-05-22 10:22:29 +02:00
|
|
|
*
|
2013-03-06 15:37:09 +01:00
|
|
|
* @param inventory PlayerInventory to scan
|
|
|
|
* @param itemId Item id to look for
|
|
|
|
* @param metadata Metadata to look for
|
|
|
|
* @return index location where the item was found, or -1 if not found
|
2012-05-22 10:22:29 +02:00
|
|
|
*/
|
2013-03-06 15:37:09 +01:00
|
|
|
protected static int findInInventory(PlayerInventory inventory, int itemId, byte metadata) {
|
|
|
|
int location = -1;
|
2012-05-22 10:22:29 +02:00
|
|
|
|
2013-03-06 15:43:09 +01:00
|
|
|
ItemStack[] contents = inventory.getContents();
|
|
|
|
|
|
|
|
for (int i = 0; i < contents.length; i++) {
|
|
|
|
ItemStack item = contents[i];
|
|
|
|
|
2013-03-06 15:37:09 +01:00
|
|
|
if (item == null) {
|
|
|
|
continue;
|
2012-05-22 10:22:29 +02:00
|
|
|
}
|
|
|
|
|
2013-03-06 15:37:09 +01:00
|
|
|
if (item.getTypeId() == itemId && item.getData().getData() == metadata) {
|
2013-03-06 15:43:09 +01:00
|
|
|
return i;
|
2013-03-06 15:37:09 +01:00
|
|
|
}
|
2012-05-22 10:22:29 +02:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-06 15:37:09 +01:00
|
|
|
return location;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-06 15:37:09 +01:00
|
|
|
* Decrease the amount of items in this slot by one
|
2013-03-01 06:52:01 +01:00
|
|
|
*
|
2013-03-06 15:37:09 +01:00
|
|
|
* @param inventory PlayerInventory to work in
|
|
|
|
* @param index Item index to decrement
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-03-06 15:37:09 +01:00
|
|
|
protected static void removeOneFrom(PlayerInventory inventory, int index) {
|
|
|
|
ItemStack item = inventory.getItem(index).clone();
|
|
|
|
item.setAmount(1);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-06 15:37:09 +01:00
|
|
|
inventory.removeItem(item);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-06 16:47:56 +01:00
|
|
|
|
2013-03-06 17:31:51 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-05-22 10:22:29 +02:00
|
|
|
}
|