2012-05-22 10:22:29 +02:00
|
|
|
package com.gmail.nossr50.skills.repair;
|
|
|
|
|
|
|
|
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;
|
2012-05-22 10:22:29 +02:00
|
|
|
|
|
|
|
public class Repair {
|
2013-03-06 15:37:09 +01:00
|
|
|
// The order of the values is extremely important, a few methods depend on it to work properly
|
|
|
|
protected enum Tier {
|
|
|
|
FOUR(4) {
|
|
|
|
@Override public int getLevel() { return AdvancedConfig.getInstance().getArcaneForgingRankLevels4(); }
|
|
|
|
@Override public int getKeepEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingKeepEnchantsChanceRank4(); }
|
|
|
|
@Override public int getDowngradeEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingDowngradeChanceRank4(); }},
|
|
|
|
THREE(3) {
|
|
|
|
@Override public int getLevel() { return AdvancedConfig.getInstance().getArcaneForgingRankLevels3(); }
|
|
|
|
@Override public int getKeepEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingKeepEnchantsChanceRank3(); }
|
|
|
|
@Override public int getDowngradeEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingDowngradeChanceRank4(); }},
|
|
|
|
TWO(2) {
|
|
|
|
@Override public int getLevel() { return AdvancedConfig.getInstance().getArcaneForgingRankLevels2(); }
|
|
|
|
@Override public int getKeepEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingKeepEnchantsChanceRank2(); }
|
|
|
|
@Override public int getDowngradeEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingDowngradeChanceRank4(); }},
|
|
|
|
ONE(1) {
|
|
|
|
@Override public int getLevel() { return AdvancedConfig.getInstance().getArcaneForgingRankLevels1(); }
|
|
|
|
@Override public int getKeepEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingKeepEnchantsChanceRank1(); }
|
|
|
|
@Override public int getDowngradeEnchantChance() { return AdvancedConfig.getInstance().getArcaneForgingDowngradeChanceRank4(); }};
|
|
|
|
|
|
|
|
int numerical;
|
|
|
|
|
|
|
|
private Tier(int numerical) {
|
|
|
|
this.numerical = numerical;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int toNumerical() {
|
|
|
|
return numerical;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract protected int getLevel();
|
|
|
|
abstract protected int getKeepEnchantChance();
|
|
|
|
abstract protected int getDowngradeEnchantChance();
|
|
|
|
}
|
|
|
|
|
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-01 06:52:01 +01:00
|
|
|
public static boolean arcaneForgingDowngrades = AdvancedConfig.getInstance().getArcaneForgingDowngradeEnabled();
|
|
|
|
public static boolean arcaneForgingEnchantLoss = AdvancedConfig.getInstance().getArcaneForgingEnchantLossEnabled();
|
2013-01-22 18:26:35 +01:00
|
|
|
|
2013-01-24 20:19:26 +01:00
|
|
|
public static int anvilID = 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 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:37:09 +01:00
|
|
|
for (ItemStack item : inventory.getContents()) {
|
|
|
|
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) {
|
|
|
|
return location;
|
|
|
|
}
|
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
|
|
|
}
|
2012-05-22 10:22:29 +02:00
|
|
|
}
|