2012-01-09 20:00:13 +01:00
|
|
|
package com.gmail.nossr50.skills;
|
|
|
|
|
2012-03-04 21:44:05 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.ChatColor;
|
2012-02-25 08:49:53 +01:00
|
|
|
import org.bukkit.Material;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.enchantments.Enchantment;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-02-24 00:32:12 +01:00
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
|
|
|
2012-03-07 22:38:48 +01:00
|
|
|
import com.gmail.nossr50.ItemChecks;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.Users;
|
|
|
|
import com.gmail.nossr50.mcPermissions;
|
|
|
|
import com.gmail.nossr50.config.LoadProperties;
|
|
|
|
import com.gmail.nossr50.spout.SpoutStuff;
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
|
|
|
import com.gmail.nossr50.locale.mcLocale;
|
|
|
|
|
|
|
|
public class Repair {
|
2012-01-19 18:46:54 +01:00
|
|
|
|
2012-03-15 08:10:40 +01:00
|
|
|
/**
|
|
|
|
* Handle all the item repair checks.
|
|
|
|
*
|
|
|
|
* @param player Player repairing the item
|
|
|
|
* @param is The item being repaired
|
|
|
|
*/
|
|
|
|
public static void repairCheck(Player player, ItemStack is) {
|
2012-03-13 19:09:32 +01:00
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
|
|
|
short durabilityBefore = is.getDurability();
|
|
|
|
PlayerInventory inventory = player.getInventory();
|
|
|
|
int skillLevel = PP.getSkillLevel(SkillType.REPAIR);
|
2012-01-19 18:46:54 +01:00
|
|
|
|
2012-03-15 08:10:40 +01:00
|
|
|
if (durabilityBefore > 0 && is.getAmount() == 1) {
|
2012-01-19 18:46:54 +01:00
|
|
|
|
2012-03-15 08:10:40 +01:00
|
|
|
/*
|
|
|
|
* REPAIR ARMOR
|
|
|
|
*/
|
|
|
|
if (ItemChecks.isArmor(is) && LoadProperties.repairArmor) {
|
|
|
|
if (ItemChecks.isDiamondArmor(is) && inventory.contains(LoadProperties.rDiamond) && skillLevel >= LoadProperties.repairdiamondlevel) {
|
|
|
|
inventory.removeItem(new ItemStack(LoadProperties.rDiamond, 1));
|
|
|
|
repairItem(player, is);
|
|
|
|
xpHandler(player, PP, is, durabilityBefore, 6, true);
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-03-15 08:10:40 +01:00
|
|
|
else if (ItemChecks.isIronArmor(is) && inventory.contains(LoadProperties.rIron) && skillLevel >= LoadProperties.repairIronLevel) {
|
|
|
|
inventory.removeItem(new ItemStack(LoadProperties.rIron, 1));
|
|
|
|
repairItem(player, is);
|
|
|
|
xpHandler(player, PP, is, durabilityBefore, 2, true);
|
|
|
|
}
|
|
|
|
else if (ItemChecks.isGoldArmor(is) && inventory.contains(LoadProperties.rGold) && skillLevel >= LoadProperties.repairGoldLevel) {
|
|
|
|
inventory.removeItem(new ItemStack(LoadProperties.rGold, 1));
|
|
|
|
repairItem(player, is);
|
|
|
|
xpHandler(player, PP, is, durabilityBefore, 4, true);
|
|
|
|
}
|
|
|
|
else if (ItemChecks.isLeatherArmor(is) && inventory.contains(LoadProperties.rLeather)) {
|
|
|
|
inventory.removeItem(new ItemStack(LoadProperties.rLeather, 1));
|
|
|
|
repairItem(player, is);
|
|
|
|
xpHandler(player, PP, is, durabilityBefore, 1, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
needMoreVespeneGas(is, player); //UNABLE TO REPAIR
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-19 18:46:54 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/*
|
2012-03-15 08:10:40 +01:00
|
|
|
* REPAIR TOOLS
|
2012-03-13 19:09:32 +01:00
|
|
|
*/
|
2012-03-15 08:10:40 +01:00
|
|
|
else if (ItemChecks.isTool(is) && LoadProperties.repairTools) {
|
|
|
|
if (ItemChecks.isStoneTool(is) && inventory.contains(LoadProperties.rStone) && skillLevel >= LoadProperties.repairStoneLevel) {
|
|
|
|
inventory.removeItem(new ItemStack(LoadProperties.rStone, 1));
|
|
|
|
repairItem(player, is);
|
|
|
|
xpHandler(player, PP, is, durabilityBefore, 2, false);
|
|
|
|
}
|
|
|
|
else if (ItemChecks.isWoodTool(is) && inventory.contains(LoadProperties.rWood)) {
|
|
|
|
inventory.removeItem(new ItemStack(LoadProperties.rWood, 1));
|
|
|
|
repairItem(player, is);
|
|
|
|
xpHandler(player, PP, is, durabilityBefore, 2, false);
|
|
|
|
}
|
|
|
|
else if (ItemChecks.isIronTool(is) && inventory.contains(LoadProperties.rIron) && skillLevel >= LoadProperties.repairIronLevel) {
|
|
|
|
inventory.removeItem(new ItemStack(LoadProperties.rIron, 1));
|
|
|
|
repairItem(player, is);
|
|
|
|
xpHandler(player, PP, is, durabilityBefore, 1, true);
|
|
|
|
}
|
|
|
|
else if (ItemChecks.isDiamondTool(is) && inventory.contains(LoadProperties.rDiamond) && skillLevel >= LoadProperties.repairdiamondlevel) {
|
|
|
|
inventory.removeItem(new ItemStack(LoadProperties.rDiamond, 1));
|
|
|
|
repairItem(player, is);
|
|
|
|
xpHandler(player, PP, is, durabilityBefore, 1, true);
|
|
|
|
}
|
|
|
|
else if (ItemChecks.isGoldTool(is) && inventory.contains(LoadProperties.rGold) && skillLevel >= LoadProperties.repairGoldLevel) {
|
|
|
|
inventory.removeItem(new ItemStack(LoadProperties.rGold, 1));
|
|
|
|
repairItem(player, is);
|
|
|
|
xpHandler(player, PP, is, durabilityBefore, 8, true);
|
|
|
|
}
|
|
|
|
else if (is.getType().equals(Material.BOW) && inventory.contains(LoadProperties.rString)){
|
|
|
|
inventory.removeItem(new ItemStack(LoadProperties.rString, 1));
|
|
|
|
repairItem(player, is);
|
|
|
|
xpHandler(player, PP, is, durabilityBefore, 2, false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
needMoreVespeneGas(is, player); //UNABLE TO REPAIR
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage(mcLocale.getString("Skills.FullDurability"));
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-15 08:10:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the XP gain for repair events.
|
|
|
|
*
|
|
|
|
* @param player Player repairing the item
|
|
|
|
* @param PP PlayerProfile of the repairing player
|
|
|
|
* @param is Item being repaired
|
|
|
|
* @param durabilityBefore Durability of the item before repair
|
|
|
|
* @param modify Amount to modify the durability by
|
|
|
|
* @param boost True if the modifier is a boost, false if the modifier is a reduction
|
|
|
|
*/
|
|
|
|
private static void xpHandler(Player player, PlayerProfile PP, ItemStack is, short durabilityBefore, int modify, boolean boost) {
|
2012-03-13 19:09:32 +01:00
|
|
|
short durabilityAfter = is.getDurability();
|
|
|
|
short dif = (short) (durabilityBefore - durabilityAfter);
|
2012-03-15 08:10:40 +01:00
|
|
|
|
|
|
|
if (boost) {
|
2012-03-13 19:09:32 +01:00
|
|
|
dif = (short) (dif * modify);
|
2012-03-15 08:10:40 +01:00
|
|
|
}
|
|
|
|
else{
|
2012-03-13 19:09:32 +01:00
|
|
|
dif = (short) (dif / modify);
|
2012-03-15 08:10:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ItemChecks.isShovel(is)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
dif = (short) (dif / 3);
|
2012-03-15 08:10:40 +01:00
|
|
|
}
|
|
|
|
else if(ItemChecks.isSword(is)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
dif = (short) (dif / 2);
|
2012-03-15 08:10:40 +01:00
|
|
|
}
|
|
|
|
else if(ItemChecks.isHoe(is)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
dif = (short) (dif / 2);
|
2012-03-15 08:10:40 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
PP.addXP(SkillType.REPAIR, dif*10, player);
|
2012-03-15 08:10:40 +01:00
|
|
|
Skills.XpCheckSkill(SkillType.REPAIR, player);
|
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
//CLANG CLANG
|
2012-03-15 08:10:40 +01:00
|
|
|
if (LoadProperties.spoutEnabled) {
|
2012-03-13 19:09:32 +01:00
|
|
|
SpoutStuff.playRepairNoise(player);
|
2012-03-15 08:10:40 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/**
|
|
|
|
* Get current Arcane Forging rank.
|
|
|
|
*
|
|
|
|
* @param skillLevel The skill level of the player whose rank is being checked
|
|
|
|
* @return The player's current Arcane Forging rank
|
|
|
|
*/
|
2012-03-15 08:10:40 +01:00
|
|
|
public static int getArcaneForgingRank(int skillLevel) {
|
|
|
|
if (skillLevel >= LoadProperties.arcaneRank4) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return 4;
|
2012-03-15 08:10:40 +01:00
|
|
|
}
|
|
|
|
else if (skillLevel >= LoadProperties.arcaneRank3) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return 3;
|
2012-03-15 08:10:40 +01:00
|
|
|
}
|
|
|
|
else if (skillLevel >= LoadProperties.arcaneRank2) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return 2;
|
2012-03-15 08:10:40 +01:00
|
|
|
}
|
|
|
|
else if (skillLevel >= LoadProperties.arcaneRank1) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return 1;
|
2012-03-15 08:10:40 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-03-15 08:10:40 +01:00
|
|
|
|
|
|
|
/**
|
2012-03-15 18:11:56 +01:00
|
|
|
* Handles removing & downgrading enchants.
|
|
|
|
*
|
|
|
|
* @param player Player repairing the item
|
|
|
|
* @param is Item being repaired
|
2012-03-15 08:10:40 +01:00
|
|
|
*/
|
2012-03-15 18:11:56 +01:00
|
|
|
private static void addEnchants(Player player, ItemStack is) {
|
2012-03-13 19:09:32 +01:00
|
|
|
Map<Enchantment, Integer> enchants = is.getEnchantments();
|
2012-03-15 18:11:56 +01:00
|
|
|
|
|
|
|
if (enchants.size() == 0) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return;
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
int rank = getArcaneForgingRank(Users.getProfile(player).getSkillLevel(SkillType.REPAIR));
|
2012-03-15 18:11:56 +01:00
|
|
|
|
|
|
|
if (rank == 0) {
|
|
|
|
for (Enchantment x : enchants.keySet()) {
|
2012-03-13 19:09:32 +01:00
|
|
|
is.removeEnchantment(x);
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(mcLocale.getString("Repair.LostEnchants"));
|
|
|
|
return;
|
|
|
|
}
|
2012-03-15 18:11:56 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
boolean downgraded = false;
|
2012-03-15 18:11:56 +01:00
|
|
|
|
|
|
|
for (Entry<Enchantment, Integer> enchant : enchants.entrySet()) {
|
|
|
|
Enchantment enchantment = enchant.getKey();
|
|
|
|
|
|
|
|
if (Math.random() * 100 <= getEnchantChance(rank)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
int enchantLevel = enchant.getValue();
|
2012-03-15 18:11:56 +01:00
|
|
|
|
|
|
|
if (LoadProperties.mayDowngradeEnchants && enchantLevel > 1) {
|
|
|
|
if (Math.random() * 100 <= getDowngradeChance(rank)) {
|
|
|
|
is.addEnchantment(enchantment, enchantLevel--);
|
2012-03-13 19:09:32 +01:00
|
|
|
downgraded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-15 18:11:56 +01:00
|
|
|
else {
|
|
|
|
is.removeEnchantment(enchantment);
|
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-03-15 18:11:56 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
Map<Enchantment, Integer> newEnchants = is.getEnchantments();
|
2012-03-15 18:11:56 +01:00
|
|
|
|
|
|
|
if (newEnchants.isEmpty()) {
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(mcLocale.getString("Repair.ArcaneFailed"));
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else if (downgraded || newEnchants.size() < enchants.size()) {
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(mcLocale.getString("Repair.Downgraded"));
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(mcLocale.getString("Repair.ArcanePerfect"));
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-03-15 18:11:56 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/**
|
|
|
|
* Gets chance of keeping enchantment during repair.
|
2012-03-15 18:11:56 +01:00
|
|
|
*
|
2012-03-13 19:09:32 +01:00
|
|
|
* @param rank Arcane Forging rank
|
2012-03-15 08:10:40 +01:00
|
|
|
* @return The chance of keeping the enchantment
|
2012-03-13 19:09:32 +01:00
|
|
|
*/
|
2012-03-15 08:10:40 +01:00
|
|
|
public static int getEnchantChance(int rank) {
|
|
|
|
switch (rank) {
|
2012-03-13 19:09:32 +01:00
|
|
|
case 4:
|
|
|
|
return LoadProperties.keepEnchantsRank4;
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
case 3:
|
|
|
|
return LoadProperties.keepEnchantsRank3;
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
case 2:
|
|
|
|
return LoadProperties.keepEnchantsRank2;
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
case 1:
|
|
|
|
return LoadProperties.keepEnchantsRank1;
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/**
|
|
|
|
* Gets chance of enchantment being downgraded during repair.
|
2012-03-15 18:11:56 +01:00
|
|
|
*
|
2012-03-13 19:09:32 +01:00
|
|
|
* @param rank Arcane Forging rank
|
|
|
|
* @return The chance of the enchantment being downgraded
|
|
|
|
*/
|
2012-03-15 18:11:56 +01:00
|
|
|
public static int getDowngradeChance(int rank) {
|
2012-03-15 08:10:40 +01:00
|
|
|
switch (rank) {
|
2012-03-13 19:09:32 +01:00
|
|
|
case 4:
|
|
|
|
return LoadProperties.downgradeRank4;
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
case 3:
|
|
|
|
return LoadProperties.downgradeRank3;
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
case 2:
|
|
|
|
return LoadProperties.downgradeRank2;
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
case 1:
|
|
|
|
return LoadProperties.downgradeRank1;
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
default:
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
}
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/**
|
|
|
|
* Computes repair bonuses.
|
2012-03-15 18:11:56 +01:00
|
|
|
*
|
2012-03-13 19:09:32 +01:00
|
|
|
* @param player The player repairing an item
|
|
|
|
* @param durability The durability of the item being repaired
|
|
|
|
* @param ramt The base amount of durability repaired to the item
|
|
|
|
* @return The final amount of durability repaired to the item
|
|
|
|
*/
|
2012-03-15 18:11:56 +01:00
|
|
|
private static short repairCalculate(Player player, short durability, int ramt) {
|
2012-03-13 19:09:32 +01:00
|
|
|
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR);
|
2012-03-15 18:11:56 +01:00
|
|
|
float bonus = (float) skillLevel / 500;
|
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
bonus = (ramt * bonus);
|
2012-03-15 18:11:56 +01:00
|
|
|
ramt += bonus;
|
|
|
|
|
|
|
|
if (checkPlayerProcRepair(player)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
ramt = (short) (ramt * 2);
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
durability -= ramt;
|
|
|
|
|
|
|
|
if (durability < 0) {
|
2012-03-13 19:09:32 +01:00
|
|
|
durability = 0;
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
return durability;
|
|
|
|
}
|
2012-03-15 18:11:56 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/**
|
|
|
|
* Gets the base durability amount to repair an item.
|
2012-03-15 18:11:56 +01:00
|
|
|
*
|
2012-03-13 19:09:32 +01:00
|
|
|
* @param is The item being repaired
|
|
|
|
* @param player The player repairing the item
|
|
|
|
* @return The final amount of durability repaired to the item
|
|
|
|
*/
|
2012-03-15 18:11:56 +01:00
|
|
|
private static short getRepairAmount(ItemStack is, Player player){
|
2012-03-13 19:09:32 +01:00
|
|
|
short maxDurability = is.getType().getMaxDurability();
|
|
|
|
int ramt = 0;
|
|
|
|
|
2012-03-15 18:11:56 +01:00
|
|
|
if (ItemChecks.isShovel(is)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
ramt = maxDurability;
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else if (ItemChecks.isHoe(is) || ItemChecks.isSword(is) || is.getType().equals(Material.SHEARS)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
ramt = maxDurability / 2;
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else if (ItemChecks.isAxe(is) || ItemChecks.isMiningPick(is) || is.getType().equals(Material.BOW)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
ramt = maxDurability / 3;
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else if (ItemChecks.isBoots(is)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
ramt = maxDurability / 4;
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else if (ItemChecks.isHelmet(is)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
ramt = maxDurability / 5;
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else if (ItemChecks.isPants(is)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
ramt = maxDurability / 7;
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else if (ItemChecks.isChestplate(is)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
ramt = maxDurability / 8;
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return repairCalculate(player, is.getDurability(), ramt);
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-03-15 18:11:56 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/**
|
|
|
|
* Informs a player that the repair has failed.
|
2012-03-15 18:11:56 +01:00
|
|
|
*
|
2012-03-13 19:09:32 +01:00
|
|
|
* @param is The item being repaired
|
|
|
|
* @param player The player repairing the item
|
|
|
|
*/
|
2012-03-15 18:11:56 +01:00
|
|
|
private static void needMoreVespeneGas(ItemStack is, Player player) {
|
2012-03-13 19:09:32 +01:00
|
|
|
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR);
|
2012-03-15 18:11:56 +01:00
|
|
|
|
|
|
|
if (is.getAmount() != 1) {
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(mcLocale.getString("Skills.StackedItems"));
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (ItemChecks.isDiamondTool(is) || ItemChecks.isDiamondArmor(is)) {
|
|
|
|
if (skillLevel < LoadProperties.repairdiamondlevel) {
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(mcLocale.getString("Skills.AdeptDiamond"));
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage(mcLocale.getString("Skills.NeedMore") + " " + ChatColor.BLUE + LoadProperties.nDiamond);
|
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-03-15 18:11:56 +01:00
|
|
|
else if (ItemChecks.isIronTool(is) || ItemChecks.isIronArmor(is)) {
|
|
|
|
if (skillLevel < LoadProperties.repairIronLevel) {
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(mcLocale.getString("Skills.AdeptIron"));
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage(mcLocale.getString("Skills.NeedMore")+ " " + ChatColor.GRAY + LoadProperties.nIron);
|
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-03-15 18:11:56 +01:00
|
|
|
else if (ItemChecks.isGoldTool(is) || ItemChecks.isGoldArmor(is)) {
|
|
|
|
if (skillLevel < LoadProperties.repairGoldLevel) {
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(mcLocale.getString("Skills.AdeptGold"));
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage(mcLocale.getString("Skills.NeedMore") + " " + ChatColor.GOLD + LoadProperties.nGold);
|
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-03-15 18:11:56 +01:00
|
|
|
else if (ItemChecks.isStoneTool(is)) {
|
|
|
|
if (skillLevel < LoadProperties.repairStoneLevel) {
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(mcLocale.getString("Skills.AdeptStone"));
|
2012-03-15 18:11:56 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage(mcLocale.getString("Skills.NeedMore") + " " + ChatColor.GRAY + LoadProperties.nStone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ItemChecks.isWoodTool(is)) {
|
|
|
|
player.sendMessage(mcLocale.getString("Skills.NeedMore") + " " + ChatColor.DARK_GREEN + LoadProperties.nWood);
|
|
|
|
}
|
|
|
|
else if (ItemChecks.isLeatherArmor(is)) {
|
|
|
|
player.sendMessage(mcLocale.getString("Skills.NeedMore") + " " + ChatColor.YELLOW + LoadProperties.nLeather);
|
|
|
|
}
|
|
|
|
else if (is.getType().equals(Material.BOW)) {
|
|
|
|
player.sendMessage(mcLocale.getString("Skills.NeedMore") + " " + ChatColor.YELLOW + LoadProperties.nString);
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/**
|
|
|
|
* Checks for Super Repair bonus.
|
2012-03-15 18:11:56 +01:00
|
|
|
*
|
2012-03-15 08:10:40 +01:00
|
|
|
* @param player The player repairing an item
|
2012-03-13 19:09:32 +01:00
|
|
|
* @return true if bonus granted, false otherwise
|
|
|
|
*/
|
2012-03-15 08:10:40 +01:00
|
|
|
public static boolean checkPlayerProcRepair(Player player) {
|
|
|
|
final int MAX_BONUS_LEVEL = 1000;
|
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR);
|
2012-03-15 08:10:40 +01:00
|
|
|
|
|
|
|
if(skillLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= skillLevel)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(mcLocale.getString("Skills.FeltEasy"));
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
return false;
|
|
|
|
}
|
2012-03-15 08:10:40 +01:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/**
|
|
|
|
* Repairs an item.
|
2012-03-15 08:10:40 +01:00
|
|
|
*
|
2012-03-13 19:09:32 +01:00
|
|
|
* @param player The player repairing an item
|
|
|
|
* @param enchants The enchantments on the item
|
|
|
|
* @param enchantsLevel The level of the enchantments on the item
|
|
|
|
*/
|
2012-03-15 08:10:40 +01:00
|
|
|
public static void repairItem(Player player, ItemStack is) {
|
|
|
|
|
|
|
|
/* Handle the enchants */
|
|
|
|
if (LoadProperties.mayLoseEnchants && !mcPermissions.getInstance().repairArcaneBypass(player)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
addEnchants(player, is);
|
2012-03-15 08:10:40 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
is.setDurability(getRepairAmount(is, player));
|
|
|
|
}
|
2012-03-15 08:10:40 +01:00
|
|
|
}
|