diff --git a/src/main/java/com/gmail/nossr50/Item.java b/src/main/java/com/gmail/nossr50/Item.java index d30c97c10..df8a5c495 100644 --- a/src/main/java/com/gmail/nossr50/Item.java +++ b/src/main/java/com/gmail/nossr50/Item.java @@ -29,18 +29,16 @@ public class Item { PlayerProfile PP = Users.getProfile(player); ItemStack is = player.getItemInHand(); Block block = player.getLocation().getBlock(); - int chimaeraID = LoadProperties.chimaeraId; - int itemsUsed = LoadProperties.feathersConsumedByChimaeraWing; int amount = is.getAmount(); - if (mcPermissions.getInstance().chimaeraWing(player) && is.getTypeId() == chimaeraID) { - if (Skills.cooldownOver(player, PP.getRecentlyHurt(), 60) && amount >= itemsUsed) { - player.setItemInHand(new ItemStack(chimaeraID, amount - itemsUsed)); + if (mcPermissions.getInstance().chimaeraWing(player) && is.getTypeId() == LoadProperties.chimaeraId) { + if (Skills.cooldownOver(PP.getRecentlyHurt(), 60) && amount >= LoadProperties.feathersConsumedByChimaeraWing) { + player.setItemInHand(new ItemStack(LoadProperties.chimaeraId, amount - LoadProperties.feathersConsumedByChimaeraWing)); - for (int blockY = block.getY(); blockY < player.getWorld().getMaxHeight(); blockY++) { - if (player.getLocation().getWorld().getBlockAt(block.getX(), blockY, block.getZ()).getType() != Material.AIR) { + for (int y = 0; block.getY() + y < player.getWorld().getMaxHeight(); y++) { + if (!block.getRelative(0, y, 0).getType().equals(Material.AIR)) { player.sendMessage(mcLocale.getString("Item.ChimaeraWingFail")); - player.teleport(player.getLocation().getWorld().getBlockAt(block.getX(), (blockY - 1), block.getZ()).getLocation()); + player.teleport(block.getRelative(0, y - 1, 0).getLocation()); return; } } @@ -54,10 +52,10 @@ public class Item { player.sendMessage(mcLocale.getString("Item.ChimaeraWingPass")); } - else if (!Skills.cooldownOver(player, PP.getRecentlyHurt(), 60) && is.getAmount() >= itemsUsed) { - player.sendMessage(mcLocale.getString("Item.InjuredWait", new Object[] {Skills.calculateTimeLeft(player, PP.getRecentlyHurt(), 60)})); + else if (!Skills.cooldownOver(PP.getRecentlyHurt(), 60) && is.getAmount() >= LoadProperties.feathersConsumedByChimaeraWing) { + player.sendMessage(mcLocale.getString("Item.InjuredWait", new Object[] {Skills.calculateTimeLeft(PP.getRecentlyHurt(), 60)})); } - else if (is.getTypeId() == LoadProperties.chimaeraId && is.getAmount() <= itemsUsed) { + else if (is.getAmount() <= LoadProperties.feathersConsumedByChimaeraWing) { player.sendMessage(mcLocale.getString("Item.NeedFeathers")); } } diff --git a/src/main/java/com/gmail/nossr50/skills/BlastMining.java b/src/main/java/com/gmail/nossr50/skills/BlastMining.java index 324f24593..d0730500b 100644 --- a/src/main/java/com/gmail/nossr50/skills/BlastMining.java +++ b/src/main/java/com/gmail/nossr50/skills/BlastMining.java @@ -239,6 +239,7 @@ public class BlastMining { final byte SNOW = 78; final byte AIR = 0; final int BLOCKS_AWAY = 100; + final int TIME_CONVERSION_FACTOR = 1000; PlayerProfile PP = Users.getProfile(player); HashSet transparent = new HashSet(); @@ -253,8 +254,8 @@ public class BlastMining { AbilityType ability = AbilityType.BLAST_MINING; /* Check Cooldown */ - if(!Skills.cooldownOver(player, (PP.getSkillDATS(ability) * 1000), ability.getCooldown())) { - player.sendMessage(mcLocale.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + Skills.calculateTimeLeft(player, (PP.getSkillDATS(ability) * 1000), ability.getCooldown()) + "s)"); + if(!Skills.cooldownOver(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown())) { + player.sendMessage(mcLocale.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + Skills.calculateTimeLeft(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)"); return; } diff --git a/src/main/java/com/gmail/nossr50/skills/Repair.java b/src/main/java/com/gmail/nossr50/skills/Repair.java index b7ae54462..7a855554b 100644 --- a/src/main/java/com/gmail/nossr50/skills/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/Repair.java @@ -20,519 +20,518 @@ import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.mcLocale; - public class Repair { - private static int rGold = LoadProperties.rGold; - private static String nGold = LoadProperties.nGold; - private static int rStone = LoadProperties.rStone; - private static String nStone = LoadProperties.nStone; - private static int rWood = LoadProperties.rWood; - private static String nWood = LoadProperties.nWood; - private static int rDiamond = LoadProperties.rDiamond; - private static String nDiamond = LoadProperties.nDiamond; - private static int rIron = LoadProperties.rIron; - private static String nIron = LoadProperties.nIron; - private static int rString = LoadProperties.rString; - private static String nString = LoadProperties.nString; - private static int rLeather = LoadProperties.rLeather; - private static String nLeather = LoadProperties.nLeather; - - private static int dLevel = LoadProperties.repairdiamondlevel; - private static int iLevel = LoadProperties.repairIronLevel; - private static int gLevel = LoadProperties.repairGoldLevel; - private static int sLevel = LoadProperties.repairStoneLevel; - private static boolean spout = LoadProperties.spoutEnabled; - - public static void repairCheck(Player player, ItemStack is, Block block){ - PlayerProfile PP = Users.getProfile(player); - short durabilityBefore = is.getDurability(); - PlayerInventory inventory = player.getInventory(); - int skillLevel = PP.getSkillLevel(SkillType.REPAIR); + private static int rGold = LoadProperties.rGold; + private static String nGold = LoadProperties.nGold; + private static int rStone = LoadProperties.rStone; + private static String nStone = LoadProperties.nStone; + private static int rWood = LoadProperties.rWood; + private static String nWood = LoadProperties.nWood; + private static int rDiamond = LoadProperties.rDiamond; + private static String nDiamond = LoadProperties.nDiamond; + private static int rIron = LoadProperties.rIron; + private static String nIron = LoadProperties.nIron; + private static int rString = LoadProperties.rString; + private static String nString = LoadProperties.nString; + private static int rLeather = LoadProperties.rLeather; + private static String nLeather = LoadProperties.nLeather; - if(block != null && mcPermissions.getInstance().repair(player)){ - if(durabilityBefore > 0 && is.getAmount() < 2){ + private static int dLevel = LoadProperties.repairdiamondlevel; + private static int iLevel = LoadProperties.repairIronLevel; + private static int gLevel = LoadProperties.repairGoldLevel; + private static int sLevel = LoadProperties.repairStoneLevel; + private static boolean spout = LoadProperties.spoutEnabled; - /* - * REPAIR ARMOR - */ - if(isArmor(is) && LoadProperties.repairArmor){ + public static void repairCheck(Player player, ItemStack is, Block block){ + PlayerProfile PP = Users.getProfile(player); + short durabilityBefore = is.getDurability(); + PlayerInventory inventory = player.getInventory(); + int skillLevel = PP.getSkillLevel(SkillType.REPAIR); - //DIAMOND ARMOR - if(isDiamondArmor(is) && inventory.contains(rDiamond) && skillLevel >= dLevel){ - inventory.removeItem(new ItemStack(rDiamond, 1)); - repairItem(player, is); - xpHandler(player, PP, is, durabilityBefore, 6, true); - } + if(block != null && mcPermissions.getInstance().repair(player)){ + if(durabilityBefore > 0 && is.getAmount() < 2){ - //IRON ARMOR - else if (isIronArmor(is) && inventory.contains(rIron) && skillLevel >= iLevel){ - inventory.removeItem(new ItemStack(rIron, 1)); - repairItem(player, is); - xpHandler(player, PP, is, durabilityBefore, 2, true); - } + /* + * REPAIR ARMOR + */ + if(isArmor(is) && LoadProperties.repairArmor){ - //GOLD ARMOR - else if (isGoldArmor(is) && inventory.contains(rGold) && skillLevel >= gLevel){ - inventory.removeItem(new ItemStack(rGold, 1)); - repairItem(player, is); - xpHandler(player, PP, is, durabilityBefore, 4, true); - } + //DIAMOND ARMOR + if(isDiamondArmor(is) && inventory.contains(rDiamond) && skillLevel >= dLevel){ + inventory.removeItem(new ItemStack(rDiamond, 1)); + repairItem(player, is); + xpHandler(player, PP, is, durabilityBefore, 6, true); + } - //LEATHER ARMOR - else if (isLeatherArmor(is) && inventory.contains(rLeather)){ - inventory.removeItem(new ItemStack(rLeather, 1)); - repairItem(player, is); - xpHandler(player, PP, is, durabilityBefore, 1, true); - } + //IRON ARMOR + else if (isIronArmor(is) && inventory.contains(rIron) && skillLevel >= iLevel){ + inventory.removeItem(new ItemStack(rIron, 1)); + repairItem(player, is); + xpHandler(player, PP, is, durabilityBefore, 2, true); + } - //UNABLE TO REPAIR - else { - needMoreVespeneGas(is, player); - } - } + //GOLD ARMOR + else if (isGoldArmor(is) && inventory.contains(rGold) && skillLevel >= gLevel){ + inventory.removeItem(new ItemStack(rGold, 1)); + repairItem(player, is); + xpHandler(player, PP, is, durabilityBefore, 4, true); + } - /* - * REPAIR TOOLS - */ - if(isTools(is) && LoadProperties.repairTools){ + //LEATHER ARMOR + else if (isLeatherArmor(is) && inventory.contains(rLeather)){ + inventory.removeItem(new ItemStack(rLeather, 1)); + repairItem(player, is); + xpHandler(player, PP, is, durabilityBefore, 1, true); + } - //STONE TOOLS - if(isStoneTools(is) && inventory.contains(rStone) && skillLevel >= sLevel){ - inventory.removeItem(new ItemStack(rStone, 1)); - repairItem(player, is); - xpHandler(player, PP, is, durabilityBefore, 2, false); - } + //UNABLE TO REPAIR + else { + needMoreVespeneGas(is, player); + } + } - //WOOD TOOLS - else if(isWoodTools(is) && inventory.contains(rWood)){ - inventory.removeItem(new ItemStack(rWood, 1)); - repairItem(player, is); - xpHandler(player, PP, is, durabilityBefore, 2, false); - } + /* + * REPAIR TOOLS + */ + if(isTools(is) && LoadProperties.repairTools){ - //IRON TOOLS - else if(isIronTools(is) && inventory.contains(rIron) && skillLevel >= iLevel){ - inventory.removeItem(new ItemStack(rIron, 1)); - repairItem(player, is); - xpHandler(player, PP, is, durabilityBefore, 1, true); - } + //STONE TOOLS + if(isStoneTools(is) && inventory.contains(rStone) && skillLevel >= sLevel){ + inventory.removeItem(new ItemStack(rStone, 1)); + repairItem(player, is); + xpHandler(player, PP, is, durabilityBefore, 2, false); + } - //DIAMOND TOOLS - else if (isDiamondTools(is) && inventory.contains(rDiamond) && skillLevel >= dLevel){ - inventory.removeItem(new ItemStack(rDiamond, 1)); - repairItem(player, is); - xpHandler(player, PP, is, durabilityBefore, 1, true); - } - - //GOLD TOOLS - else if(isGoldTools(is) && inventory.contains(rGold) && skillLevel >= gLevel){ - inventory.removeItem(new ItemStack(rGold, 1)); - repairItem(player, is); - xpHandler(player, PP, is, durabilityBefore, 8, true); - } - - //BOW - else if(isBow(is) && inventory.contains(rString)){ - inventory.removeItem(new ItemStack(rString, 1)); - repairItem(player, is); - xpHandler(player, PP, is, durabilityBefore, 2, false); - } + //WOOD TOOLS + else if(isWoodTools(is) && inventory.contains(rWood)){ + inventory.removeItem(new ItemStack(rWood, 1)); + repairItem(player, is); + xpHandler(player, PP, is, durabilityBefore, 2, false); + } - //UNABLE TO REPAIR - else { - needMoreVespeneGas(is, player); - } - } - } + //IRON TOOLS + else if(isIronTools(is) && inventory.contains(rIron) && skillLevel >= iLevel){ + inventory.removeItem(new ItemStack(rIron, 1)); + repairItem(player, is); + xpHandler(player, PP, is, durabilityBefore, 1, true); + } - else { - player.sendMessage(mcLocale.getString("Skills.FullDurability")); - } + //DIAMOND TOOLS + else if (isDiamondTools(is) && inventory.contains(rDiamond) && skillLevel >= dLevel){ + inventory.removeItem(new ItemStack(rDiamond, 1)); + repairItem(player, is); + xpHandler(player, PP, is, durabilityBefore, 1, true); + } + + //GOLD TOOLS + else if(isGoldTools(is) && inventory.contains(rGold) && skillLevel >= gLevel){ + inventory.removeItem(new ItemStack(rGold, 1)); + repairItem(player, is); + xpHandler(player, PP, is, durabilityBefore, 8, true); + } + + //BOW + else if(isBow(is) && inventory.contains(rString)){ + inventory.removeItem(new ItemStack(rString, 1)); + repairItem(player, is); + xpHandler(player, PP, is, durabilityBefore, 2, false); + } - /* - * GIVE SKILL IF THERE IS ENOUGH XP - */ - Skills.XpCheckSkill(SkillType.REPAIR, player); - } - } - - public static void xpHandler(Player player, PlayerProfile PP, ItemStack is, short durabilityBefore, int modify, boolean boost) - { - short durabilityAfter = is.getDurability(); - short dif = (short) (durabilityBefore - durabilityAfter); - if(boost) - dif = (short) (dif * modify); - if(!boost) - dif = (short) (dif / modify); - if(ItemChecks.isShovel(is)) - dif = (short) (dif / 3); - if(ItemChecks.isSword(is)) - dif = (short) (dif / 2); - if(ItemChecks.isHoe(is)) - dif = (short) (dif / 2); - - PP.addXP(SkillType.REPAIR, dif*10, player); - - //CLANG CLANG - if(spout) - SpoutStuff.playRepairNoise(player); - } - - /** - * 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 - */ - public static int getArcaneForgingRank(int skillLevel) - { - if(skillLevel >= LoadProperties.arcaneRank4) - return 4; - if (skillLevel >= LoadProperties.arcaneRank3) - return 3; - if(skillLevel >= LoadProperties.arcaneRank2) - return 2; - if (skillLevel >= LoadProperties.arcaneRank1) - return 1; - - return 0; - } - - public static void addEnchants(Player player, ItemStack is) - { - Map enchants = is.getEnchantments(); - if(enchants.size() == 0) - return; - - int rank = getArcaneForgingRank(Users.getProfile(player).getSkillLevel(SkillType.REPAIR)); - if(rank == 0) - { - for(Enchantment x : enchants.keySet()) - is.removeEnchantment(x); - player.sendMessage(mcLocale.getString("Repair.LostEnchants")); - return; - } - - boolean downgraded = false; - for(Entry enchant : enchants.entrySet()) - { - if(Math.random() * 100 <= getEnchantChance(rank)) - { - int enchantLevel = enchant.getValue(); - if(LoadProperties.mayDowngradeEnchants && enchantLevel > 1) - { - if(Math.random() * 100 <= getDowngradeChance(rank)) - { - is.addEnchantment(enchant.getKey(), enchantLevel--); - downgraded = true; - } - } - } - else - is.removeEnchantment(enchant.getKey()); - } - - Map newEnchants = is.getEnchantments(); - if(newEnchants.isEmpty()) - player.sendMessage(mcLocale.getString("Repair.ArcaneFailed")); - else if(downgraded || newEnchants.size() < enchants.size()) - player.sendMessage(mcLocale.getString("Repair.Downgraded")); - else - player.sendMessage(mcLocale.getString("Repair.ArcanePerfect")); - } - - /** - * Gets chance of keeping enchantment during repair. - * - * @param rank Arcane Forging rank - * @return The chance of keeping the enchantment - */ - public static int getEnchantChance(int rank) - { - switch(rank) - { - case 4: - return LoadProperties.keepEnchantsRank4; - case 3: - return LoadProperties.keepEnchantsRank3; - case 2: - return LoadProperties.keepEnchantsRank2; - case 1: - return LoadProperties.keepEnchantsRank1; - default: - return 0; - } - } - - /** - * Gets chance of enchantment being downgraded during repair. - * - * @param rank Arcane Forging rank - * @return The chance of the enchantment being downgraded - */ - public static int getDowngradeChance(int rank) - { - switch(rank) - { - case 4: - return LoadProperties.downgradeRank4; - case 3: - return LoadProperties.downgradeRank3; - case 2: - return LoadProperties.downgradeRank2; - case 1: - return LoadProperties.downgradeRank1; - default: - return 100; - } - } - - public static boolean isArmor(ItemStack is){ - return isLeatherArmor(is) || isGoldArmor(is) || isIronArmor(is) || isDiamondArmor(is); - } - - public static boolean isLeatherArmor(ItemStack is){ - switch(is.getType()){ - case LEATHER_BOOTS: - case LEATHER_CHESTPLATE: - case LEATHER_HELMET: - case LEATHER_LEGGINGS: - return true; - } - return false; - } - - public static boolean isGoldArmor(ItemStack is){ - switch(is.getType()){ - case GOLD_BOOTS: - case GOLD_CHESTPLATE: - case GOLD_HELMET: - case GOLD_LEGGINGS: - return true; - } - return false; - } - - public static boolean isIronArmor(ItemStack is){ - switch(is.getType()){ - case IRON_BOOTS: - case IRON_CHESTPLATE: - case IRON_HELMET: - case IRON_LEGGINGS: - return true; - } - return false; - } - - public static boolean isDiamondArmor(ItemStack is){ - switch(is.getType()){ - case DIAMOND_BOOTS: - case DIAMOND_CHESTPLATE: - case DIAMOND_HELMET: - case DIAMOND_LEGGINGS: - return true; - } - return false; - } - - public static boolean isTools(ItemStack is) - { - return isStoneTools(is) || isWoodTools(is) || isGoldTools(is) || isIronTools(is) || isDiamondTools(is) || isBow(is); - } - - public static boolean isStoneTools(ItemStack is){ - switch(is.getType()){ - case STONE_AXE: - case STONE_HOE: - case STONE_PICKAXE: - case STONE_SPADE: - case STONE_SWORD: - return true; - } - return false; - } - public static boolean isWoodTools(ItemStack is){ - switch(is.getType()){ - case WOOD_AXE: - case WOOD_HOE: - case WOOD_PICKAXE: - case WOOD_SPADE: - case WOOD_SWORD: - return true; - } - return false; - } - public static boolean isGoldTools(ItemStack is){ - switch(is.getType()){ - case GOLD_AXE: - case GOLD_HOE: - case GOLD_PICKAXE: - case GOLD_SPADE: - case GOLD_SWORD: - return true; - } - return false; - } - public static boolean isIronTools(ItemStack is){ - switch(is.getType()){ - case IRON_AXE: - case IRON_HOE: - case IRON_PICKAXE: - case IRON_SPADE: - case IRON_SWORD: - case SHEARS: - return true; - } - return false; - } - public static boolean isDiamondTools(ItemStack is){ - switch(is.getType()){ - case DIAMOND_AXE: - case DIAMOND_HOE: - case DIAMOND_PICKAXE: - case DIAMOND_SPADE: - case DIAMOND_SWORD: - return true; - } - return false; - } - - public static boolean isBow(ItemStack is){ - return is.getType() == Material.BOW; - } - - /** - * Computes repair bonuses. - * - * @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 - */ - public static short repairCalculate(Player player, short durability, int ramt){ - int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR); - float bonus = (float)(skillLevel/500); - bonus = (ramt * bonus); - ramt+=bonus; - if(checkPlayerProcRepair(player)) - ramt = (short) (ramt * 2); - durability-=ramt; - if(durability < 0) - durability = 0; - return durability; - } - - /** - * Gets the base durability amount to repair an item. - * - * @param is The item being repaired - * @param player The player repairing the item - * @return The final amount of durability repaired to the item - */ - public static short getRepairAmount(ItemStack is, Player player){ - short durability = is.getDurability(); - short maxDurability = is.getType().getMaxDurability(); - int ramt = 0; - - if(ItemChecks.isShovel(is)) - ramt = maxDurability; - else if(ItemChecks.isHoe(is) || ItemChecks.isSword(is) || is.getTypeId() == 359) - ramt = maxDurability / 2; - else if(ItemChecks.isAxe(is) || ItemChecks.isMiningPick(is) || isBow(is)) - ramt = maxDurability / 3; - else if(ItemChecks.isBoots(is)) - ramt = maxDurability / 4; - else if(ItemChecks.isHelmet(is)) - ramt = maxDurability / 5; - else if(ItemChecks.isPants(is)) - ramt = maxDurability / 7; - else if(ItemChecks.isChestplate(is)) - ramt = maxDurability / 8; - - return repairCalculate(player, durability, ramt); - } - - /** - * Informs a player that the repair has failed. - * - * @param is The item being repaired - * @param player The player repairing the item - */ - public static void needMoreVespeneGas(ItemStack is, Player player) - { - int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR); - - if(is.getAmount() > 1) - player.sendMessage(mcLocale.getString("Skills.StackedItems")); - else - { - if(isDiamondTools(is) || isDiamondArmor(is)) - { - if(skillLevel < LoadProperties.repairdiamondlevel) - player.sendMessage(mcLocale.getString("Skills.AdeptDiamond")); - else - player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.BLUE+ nDiamond); - } - else if(isIronTools(is) || isIronArmor(is)) - { - if(skillLevel < LoadProperties.repairIronLevel) - player.sendMessage(mcLocale.getString("Skills.AdeptIron")); - else - player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.GRAY+ nIron); - } - else if(isGoldTools(is) || isGoldArmor(is)) - { - if(skillLevel < LoadProperties.repairGoldLevel) - player.sendMessage(mcLocale.getString("Skills.AdeptGold")); - else - player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.GOLD+nGold); - } - else if(isStoneTools(is)) - { - if(skillLevel < LoadProperties.repairStoneLevel) - player.sendMessage(mcLocale.getString("Skills.AdeptStone")); - else - player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.GRAY+nStone); - } - else if(isWoodTools(is)) - player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.DARK_GREEN+ nWood); - else if (isLeatherArmor(is)) - player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.YELLOW+ nLeather); - else if (isBow(is)) - player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.YELLOW+ nString); - } - } - - /** - * Checks for Super Repair bonus. - * - * @param player The player repairing an item. - * @return true if bonus granted, false otherwise - */ - public static boolean checkPlayerProcRepair(Player player) - { - int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR); - if(skillLevel > 1000 || (Math.random() * 1000 <= skillLevel)) - { - player.sendMessage(mcLocale.getString("Skills.FeltEasy")); - return true; - } - return false; - } - - /** - * Repairs an item. - * - * @param player The player repairing an item - * @param enchants The enchantments on the item - * @param enchantsLevel The level of the enchantments on the item - */ - public static void repairItem(Player player, ItemStack is) - { - //Handle the enchantments - if(LoadProperties.mayLoseEnchants && !mcPermissions.getInstance().repairArcaneBypass(player)) - addEnchants(player, is); - is.setDurability(getRepairAmount(is, player)); - } + //UNABLE TO REPAIR + else { + needMoreVespeneGas(is, player); + } + } + } + + else { + player.sendMessage(mcLocale.getString("Skills.FullDurability")); + } + + /* + * GIVE SKILL IF THERE IS ENOUGH XP + */ + Skills.XpCheckSkill(SkillType.REPAIR, player); + } + } + + private static void xpHandler(Player player, PlayerProfile PP, ItemStack is, short durabilityBefore, int modify, boolean boost) + { + short durabilityAfter = is.getDurability(); + short dif = (short) (durabilityBefore - durabilityAfter); + if(boost) + dif = (short) (dif * modify); + if(!boost) + dif = (short) (dif / modify); + if(ItemChecks.isShovel(is)) + dif = (short) (dif / 3); + if(ItemChecks.isSword(is)) + dif = (short) (dif / 2); + if(ItemChecks.isHoe(is)) + dif = (short) (dif / 2); + + PP.addXP(SkillType.REPAIR, dif*10, player); + + //CLANG CLANG + if(spout) + SpoutStuff.playRepairNoise(player); + } + + /** + * 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 + */ + public static int getArcaneForgingRank(int skillLevel) + { + if(skillLevel >= LoadProperties.arcaneRank4) + return 4; + if (skillLevel >= LoadProperties.arcaneRank3) + return 3; + if(skillLevel >= LoadProperties.arcaneRank2) + return 2; + if (skillLevel >= LoadProperties.arcaneRank1) + return 1; + + return 0; + } + + public static void addEnchants(Player player, ItemStack is) + { + Map enchants = is.getEnchantments(); + if(enchants.size() == 0) + return; + + int rank = getArcaneForgingRank(Users.getProfile(player).getSkillLevel(SkillType.REPAIR)); + if(rank == 0) + { + for(Enchantment x : enchants.keySet()) + is.removeEnchantment(x); + player.sendMessage(mcLocale.getString("Repair.LostEnchants")); + return; + } + + boolean downgraded = false; + for(Entry enchant : enchants.entrySet()) + { + if(Math.random() * 100 <= getEnchantChance(rank)) + { + int enchantLevel = enchant.getValue(); + if(LoadProperties.mayDowngradeEnchants && enchantLevel > 1) + { + if(Math.random() * 100 <= getDowngradeChance(rank)) + { + is.addEnchantment(enchant.getKey(), enchantLevel--); + downgraded = true; + } + } + } + else + is.removeEnchantment(enchant.getKey()); + } + + Map newEnchants = is.getEnchantments(); + if(newEnchants.isEmpty()) + player.sendMessage(mcLocale.getString("Repair.ArcaneFailed")); + else if(downgraded || newEnchants.size() < enchants.size()) + player.sendMessage(mcLocale.getString("Repair.Downgraded")); + else + player.sendMessage(mcLocale.getString("Repair.ArcanePerfect")); + } + + /** + * Gets chance of keeping enchantment during repair. + * + * @param rank Arcane Forging rank + * @return The chance of keeping the enchantment + */ + public static int getEnchantChance(int rank) + { + switch(rank) + { + case 4: + return LoadProperties.keepEnchantsRank4; + case 3: + return LoadProperties.keepEnchantsRank3; + case 2: + return LoadProperties.keepEnchantsRank2; + case 1: + return LoadProperties.keepEnchantsRank1; + default: + return 0; + } + } + + /** + * Gets chance of enchantment being downgraded during repair. + * + * @param rank Arcane Forging rank + * @return The chance of the enchantment being downgraded + */ + public static int getDowngradeChance(int rank) + { + switch(rank) + { + case 4: + return LoadProperties.downgradeRank4; + case 3: + return LoadProperties.downgradeRank3; + case 2: + return LoadProperties.downgradeRank2; + case 1: + return LoadProperties.downgradeRank1; + default: + return 100; + } + } + + public static boolean isArmor(ItemStack is){ + return isLeatherArmor(is) || isGoldArmor(is) || isIronArmor(is) || isDiamondArmor(is); + } + + public static boolean isLeatherArmor(ItemStack is){ + switch(is.getType()){ + case LEATHER_BOOTS: + case LEATHER_CHESTPLATE: + case LEATHER_HELMET: + case LEATHER_LEGGINGS: + return true; + } + return false; + } + + public static boolean isGoldArmor(ItemStack is){ + switch(is.getType()){ + case GOLD_BOOTS: + case GOLD_CHESTPLATE: + case GOLD_HELMET: + case GOLD_LEGGINGS: + return true; + } + return false; + } + + public static boolean isIronArmor(ItemStack is){ + switch(is.getType()){ + case IRON_BOOTS: + case IRON_CHESTPLATE: + case IRON_HELMET: + case IRON_LEGGINGS: + return true; + } + return false; + } + + public static boolean isDiamondArmor(ItemStack is){ + switch(is.getType()){ + case DIAMOND_BOOTS: + case DIAMOND_CHESTPLATE: + case DIAMOND_HELMET: + case DIAMOND_LEGGINGS: + return true; + } + return false; + } + + public static boolean isTools(ItemStack is) + { + return isStoneTools(is) || isWoodTools(is) || isGoldTools(is) || isIronTools(is) || isDiamondTools(is) || isBow(is); + } + + public static boolean isStoneTools(ItemStack is){ + switch(is.getType()){ + case STONE_AXE: + case STONE_HOE: + case STONE_PICKAXE: + case STONE_SPADE: + case STONE_SWORD: + return true; + } + return false; + } + public static boolean isWoodTools(ItemStack is){ + switch(is.getType()){ + case WOOD_AXE: + case WOOD_HOE: + case WOOD_PICKAXE: + case WOOD_SPADE: + case WOOD_SWORD: + return true; + } + return false; + } + public static boolean isGoldTools(ItemStack is){ + switch(is.getType()){ + case GOLD_AXE: + case GOLD_HOE: + case GOLD_PICKAXE: + case GOLD_SPADE: + case GOLD_SWORD: + return true; + } + return false; + } + public static boolean isIronTools(ItemStack is){ + switch(is.getType()){ + case IRON_AXE: + case IRON_HOE: + case IRON_PICKAXE: + case IRON_SPADE: + case IRON_SWORD: + case SHEARS: + return true; + } + return false; + } + public static boolean isDiamondTools(ItemStack is){ + switch(is.getType()){ + case DIAMOND_AXE: + case DIAMOND_HOE: + case DIAMOND_PICKAXE: + case DIAMOND_SPADE: + case DIAMOND_SWORD: + return true; + } + return false; + } + + public static boolean isBow(ItemStack is){ + return is.getType() == Material.BOW; + } + + /** + * Computes repair bonuses. + * + * @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 + */ + public static short repairCalculate(Player player, short durability, int ramt){ + int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR); + float bonus = (float)(skillLevel/500); + bonus = (ramt * bonus); + ramt+=bonus; + if(checkPlayerProcRepair(player)) + ramt = (short) (ramt * 2); + durability-=ramt; + if(durability < 0) + durability = 0; + return durability; + } + + /** + * Gets the base durability amount to repair an item. + * + * @param is The item being repaired + * @param player The player repairing the item + * @return The final amount of durability repaired to the item + */ + public static short getRepairAmount(ItemStack is, Player player){ + short durability = is.getDurability(); + short maxDurability = is.getType().getMaxDurability(); + int ramt = 0; + + if(ItemChecks.isShovel(is)) + ramt = maxDurability; + else if(ItemChecks.isHoe(is) || ItemChecks.isSword(is) || is.getTypeId() == 359) + ramt = maxDurability / 2; + else if(ItemChecks.isAxe(is) || ItemChecks.isMiningPick(is) || isBow(is)) + ramt = maxDurability / 3; + else if(ItemChecks.isBoots(is)) + ramt = maxDurability / 4; + else if(ItemChecks.isHelmet(is)) + ramt = maxDurability / 5; + else if(ItemChecks.isPants(is)) + ramt = maxDurability / 7; + else if(ItemChecks.isChestplate(is)) + ramt = maxDurability / 8; + + return repairCalculate(player, durability, ramt); + } + + /** + * Informs a player that the repair has failed. + * + * @param is The item being repaired + * @param player The player repairing the item + */ + public static void needMoreVespeneGas(ItemStack is, Player player) + { + int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR); + + if(is.getAmount() > 1) + player.sendMessage(mcLocale.getString("Skills.StackedItems")); + else + { + if(isDiamondTools(is) || isDiamondArmor(is)) + { + if(skillLevel < LoadProperties.repairdiamondlevel) + player.sendMessage(mcLocale.getString("Skills.AdeptDiamond")); + else + player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.BLUE+ nDiamond); + } + else if(isIronTools(is) || isIronArmor(is)) + { + if(skillLevel < LoadProperties.repairIronLevel) + player.sendMessage(mcLocale.getString("Skills.AdeptIron")); + else + player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.GRAY+ nIron); + } + else if(isGoldTools(is) || isGoldArmor(is)) + { + if(skillLevel < LoadProperties.repairGoldLevel) + player.sendMessage(mcLocale.getString("Skills.AdeptGold")); + else + player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.GOLD+nGold); + } + else if(isStoneTools(is)) + { + if(skillLevel < LoadProperties.repairStoneLevel) + player.sendMessage(mcLocale.getString("Skills.AdeptStone")); + else + player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.GRAY+nStone); + } + else if(isWoodTools(is)) + player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.DARK_GREEN+ nWood); + else if (isLeatherArmor(is)) + player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.YELLOW+ nLeather); + else if (isBow(is)) + player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.YELLOW+ nString); + } + } + + /** + * Checks for Super Repair bonus. + * + * @param player The player repairing an item. + * @return true if bonus granted, false otherwise + */ + public static boolean checkPlayerProcRepair(Player player) + { + int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR); + if(skillLevel > 1000 || (Math.random() * 1000 <= skillLevel)) + { + player.sendMessage(mcLocale.getString("Skills.FeltEasy")); + return true; + } + return false; + } + + /** + * Repairs an item. + * + * @param player The player repairing an item + * @param enchants The enchantments on the item + * @param enchantsLevel The level of the enchantments on the item + */ + public static void repairItem(Player player, ItemStack is) + { + //Handle the enchantments + if(LoadProperties.mayLoseEnchants && !mcPermissions.getInstance().repairArcaneBypass(player)) + addEnchants(player, is); + is.setDurability(getRepairAmount(is, player)); + } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/skills/Skills.java b/src/main/java/com/gmail/nossr50/skills/Skills.java index f34e6f6bf..193ec9437 100644 --- a/src/main/java/com/gmail/nossr50/skills/Skills.java +++ b/src/main/java/com/gmail/nossr50/skills/Skills.java @@ -23,315 +23,423 @@ import com.gmail.nossr50.datatypes.ToolType; import com.gmail.nossr50.events.McMMOPlayerLevelUpEvent; import com.gmail.nossr50.locale.mcLocale; -public class Skills -{ - public static boolean cooldownOver(Player player, long oldTime, int cooldown){ - long currentTime = System.currentTimeMillis(); - if(currentTime - oldTime >= (cooldown * 1000)) - return true; - else - return false; - } - - public static int calculateTimeLeft(Player player, long deactivatedTimeStamp, int cooldown) - { - return (int) (((deactivatedTimeStamp + (cooldown * 1000)) - System.currentTimeMillis())/1000); +public class Skills { + + private final static int TIME_CONVERSION_FACTOR = 1000; + private final static int MAX_DISTANCE_AWAY = 10; + + /** + * Checks to see if the cooldown for an item or ability is expired. + * + * @param oldTime The time the ability or item was last used + * @param cooldown The amount of time that must pass between uses + * @return true if the cooldown is over, false otherwise + */ + public static boolean cooldownOver(long oldTime, int cooldown){ + long currentTime = System.currentTimeMillis(); + + if (currentTime - oldTime >= (cooldown * TIME_CONVERSION_FACTOR)) { + return true; + } + else { + return false; + } } - - public static void watchCooldown(Player player, PlayerProfile PP, long curTime, AbilityType ability) - { - if(!ability.getInformed(PP) && curTime - (PP.getSkillDATS(ability) * 1000) >= (ability.getCooldown() * 1000)) - { - ability.setInformed(PP, true); - player.sendMessage(ability.getAbilityRefresh()); - } + + /** + * Calculate the time remaining until the cooldown expires. + * + * @param deactivatedTimeStamp Time of deactivation + * @param cooldown The length of the cooldown + * @return the number of seconds remaining before the cooldown expires + */ + public static int calculateTimeLeft(long deactivatedTimeStamp, int cooldown) { + return (int) (((deactivatedTimeStamp + (cooldown * TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / TIME_CONVERSION_FACTOR); } - - public static void activationCheck(Player player, SkillType skill) - { - if(LoadProperties.enableOnlyActivateWhenSneaking && !player.isSneaking()) - return; - - PlayerProfile PP = Users.getProfile(player); - AbilityType ability = skill.getAbility(); - ToolType tool = skill.getTool(); - - if(!PP.getAbilityUse() || PP.getSuperBreakerMode() || PP.getSerratedStrikesMode() || PP.getTreeFellerMode() || PP.getGreenTerraMode() || PP.getBerserkMode() || PP.getGigaDrillBreakerMode()) - return; - - //Woodcutting & Axes need to be treated differently - //Basically the tool always needs to ready and we check to see if the cooldown is over when the user takes action - if(skill == SkillType.WOODCUTTING || skill == SkillType.AXES) - { - if(tool.inHand(player.getItemInHand()) && !tool.getToolMode(PP)) - { - if(LoadProperties.enableAbilityMessages) + + /** + * Sends a message to the player when the cooldown expires. + * + * @param player The player to send a message to + * @param PP The profile of the player + * @param curTime The current system time + * @param ability The ability to watch cooldowns for + */ + public static void watchCooldown(Player player, PlayerProfile PP, long curTime, AbilityType ability) { + if (!ability.getInformed(PP) && curTime - (PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR) >= (ability.getCooldown() * TIME_CONVERSION_FACTOR)) { + ability.setInformed(PP, true); + player.sendMessage(ability.getAbilityRefresh()); + } + } + + /** + * Process activating abilities & readying the tool. + * + * @param player The player using the ability + * @param skill The skill the ability is tied to + */ + public static void activationCheck(Player player, SkillType skill) { + if (LoadProperties.enableOnlyActivateWhenSneaking && !player.isSneaking()) { + return; + } + + PlayerProfile PP = Users.getProfile(player); + AbilityType ability = skill.getAbility(); + ToolType tool = skill.getTool(); + ItemStack inHand = player.getItemInHand(); + + /* Check if any abilities are active */ + if (!PP.getAbilityUse() || PP.getSuperBreakerMode() || PP.getSerratedStrikesMode() || PP.getTreeFellerMode() || PP.getGreenTerraMode() || PP.getBerserkMode() || PP.getGigaDrillBreakerMode()) { + return; + } + + /* Woodcutting & Axes need to be treated differently. + * Basically the tool always needs to ready and we check to see if the cooldown is over when the user takes action + */ + if (skill == SkillType.WOODCUTTING || skill == SkillType.AXES) { + if (tool.inHand(inHand) && !tool.getToolMode(PP)) { + if (LoadProperties.enableAbilityMessages) { player.sendMessage(tool.getRaiseTool()); - + } + tool.setToolATS(PP, System.currentTimeMillis()); tool.setToolMode(PP, true); - } - } else if(ability.getPermissions(player) && tool.inHand(player.getItemInHand()) && !tool.getToolMode(PP)) - { - if(!ability.getMode(PP) && !cooldownOver(player, (PP.getSkillDATS(ability) * 1000), ability.getCooldown())) - { - player.sendMessage(mcLocale.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + calculateTimeLeft(player, (PP.getSkillDATS(ability) * 1000), ability.getCooldown()) + "s)"); - return; - } - - if(LoadProperties.enableAbilityMessages) - player.sendMessage(tool.getRaiseTool()); - - tool.setToolATS(PP, System.currentTimeMillis()); - tool.setToolMode(PP, true); - } - } - - public static void monitorSkill(Player player, PlayerProfile PP, long curTime, SkillType skill) - { - ToolType tool = skill.getTool(); - AbilityType ability = skill.getAbility(); - if(tool.getToolMode(PP) && curTime - (tool.getToolATS(PP) * 1000) >= 4000) - { - tool.setToolMode(PP, false); - player.sendMessage(tool.getLowerTool()); - } - - if(ability.getPermissions(player)) - { - if(ability.getMode(PP) && (PP.getSkillDATS(ability) * 1000) <= curTime) - { - ability.setMode(PP, false); - ability.setInformed(PP, false); - player.sendMessage(ability.getAbilityOff()); - - for(Player y : player.getWorld().getPlayers()) - { - if(y != player && m.isNear(player.getLocation(), y.getLocation(), 10)) - y.sendMessage(ability.getAbilityPlayerOff(player)); - } - } - } - } - - public static void ProcessLeaderboardUpdate(SkillType skillType, Player player) - { - PlayerProfile PP = Users.getProfile(player); - - PlayerStat ps = new PlayerStat(); - if(skillType != SkillType.ALL) - ps.statVal = PP.getSkillLevel(skillType); - else - ps.statVal = m.getPowerLevel(player, PP); - ps.name = player.getName(); - Leaderboard.updateLeaderboard(ps, skillType); - } - - public static void XpCheckSkill(SkillType skillType, Player player) - { - PlayerProfile PP = Users.getProfile(player); - - if(PP.getSkillXpLevel(skillType) >= PP.getXpToLevel(skillType)) - { - int skillups = 0; - - while(PP.getSkillXpLevel(skillType) >= PP.getXpToLevel(skillType)) - { - if(skillType.getMaxLevel() >= PP.getSkillLevel(skillType) + 1) - { - skillups++; - PP.removeXP(skillType, PP.getXpToLevel(skillType)); - PP.skillUp(skillType, 1); - - McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType); - Bukkit.getPluginManager().callEvent(eventToFire); - } else - { - PP.removeXP(skillType, PP.getXpToLevel(skillType)); - } - } - - if(!LoadProperties.useMySQL) - { - ProcessLeaderboardUpdate(skillType, player); - ProcessLeaderboardUpdate(SkillType.ALL, player); - } - - String capitalized = m.getCapitalized(skillType.toString()); - - //Contrib stuff - - if(LoadProperties.spoutEnabled && player instanceof SpoutPlayer) - { - SpoutPlayer sPlayer = SpoutManager.getPlayer(player); - if(sPlayer.isSpoutCraftEnabled()) - { - SpoutStuff.levelUpNotification(skillType, sPlayer); - } else - { - player.sendMessage(mcLocale.getString("Skills."+capitalized+"Up", new Object[] {String.valueOf(skillups), PP.getSkillLevel(skillType)})); - } - } - else - player.sendMessage(mcLocale.getString("Skills."+capitalized+"Up", new Object[] {String.valueOf(skillups), PP.getSkillLevel(skillType)})); - } - if(LoadProperties.xpbar && LoadProperties.spoutEnabled) - { - SpoutPlayer sPlayer = SpoutManager.getPlayer(player); - if(sPlayer.isSpoutCraftEnabled()) - { - SpoutStuff.updateXpBar(sPlayer); - } - } - } - - public static void XpCheckAll(Player player) - { - for(SkillType x : SkillType.values()) - { - //Don't want to do anything with this one - if(x == SkillType.ALL) - continue; - - XpCheckSkill(x, player); - } - } - - public static SkillType getSkillType(String skillName) - { - for(SkillType x : SkillType.values()) - { - if(x.toString().equals(skillName.toUpperCase())) - return x; - } - return null; - } - - public static boolean isSkill(String skillname){ - skillname = skillname.toUpperCase(); - for(SkillType x : SkillType.values()) - { - if(x.toString().equals(skillname)) - return true; - } - return false; - } - - //We should probably rework this - it's a fairly ugly way to do this, compared to our other command formatting. - public static String getSkillStats(String skillname, Integer level, Integer XP, Integer XPToLevel) - { - ChatColor parColor = ChatColor.DARK_AQUA; - ChatColor xpColor = ChatColor.GRAY; - ChatColor LvlColor = ChatColor.GREEN; - ChatColor skillColor = ChatColor.YELLOW; - - return skillColor+skillname+LvlColor+level+parColor+" XP"+"("+xpColor+XP+parColor+"/"+xpColor+XPToLevel+parColor+")"; - } - - public static boolean hasCombatSkills(Player player) - { - if(mcPermissions.getInstance().axes(player) || mcPermissions.getInstance().archery(player) || mcPermissions.getInstance().swords(player) || mcPermissions.getInstance().taming(player) || mcPermissions.getInstance().unarmed(player)) - return true; - else - return false; - } - - public static boolean hasGatheringSkills(Player player) - { - if(mcPermissions.getInstance().excavation(player) || mcPermissions.getInstance().fishing(player) || mcPermissions.getInstance().herbalism(player) || mcPermissions.getInstance().mining(player) || mcPermissions.getInstance().woodcutting(player)) - return true; - else - return false; - } - - public static boolean hasMiscSkills(Player player) - { - if(mcPermissions.getInstance().acrobatics(player) || mcPermissions.getInstance().repair(player)) - return true; - else - return false; - } - - public static void abilityDurabilityLoss(ItemStack inhand, int durabilityLoss) - { - if(LoadProperties.toolsLoseDurabilityFromAbilities) - { - if(!inhand.containsEnchantment(Enchantment.DURABILITY)) - { - inhand.setDurability((short)(inhand.getDurability()+durabilityLoss)); } } + else if (ability.getPermissions(player) && tool.inHand(inHand) && !tool.getToolMode(PP)) { + if (!ability.getMode(PP) && !cooldownOver(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown())) { + player.sendMessage(mcLocale.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + calculateTimeLeft(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)"); + return; + } + + if (LoadProperties.enableAbilityMessages) { + player.sendMessage(tool.getRaiseTool()); + } + + tool.setToolATS(PP, System.currentTimeMillis()); + tool.setToolMode(PP, true); + } + } + + /** + * Monitors various things relating to skill abilities. + * + * @param player The player using the skill + * @param PP The profile of the player + * @param curTime The current system time + * @param skill The skill being monitored + */ + public static void monitorSkill(Player player, PlayerProfile PP, long curTime, SkillType skill) { + final int FOUR_SECONDS = 4000; + + ToolType tool = skill.getTool(); + AbilityType ability = skill.getAbility(); + + if (tool.getToolMode(PP) && curTime - (tool.getToolATS(PP) * TIME_CONVERSION_FACTOR) >= FOUR_SECONDS) { + tool.setToolMode(PP, false); + player.sendMessage(tool.getLowerTool()); + } + + if (ability.getPermissions(player)) { + if (ability.getMode(PP) && (PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR) <= curTime) { + ability.setMode(PP, false); + ability.setInformed(PP, false); + player.sendMessage(ability.getAbilityOff()); + + for (Player y : player.getWorld().getPlayers()) { + if (y != player && m.isNear(player.getLocation(), y.getLocation(), MAX_DISTANCE_AWAY)) { + y.sendMessage(ability.getAbilityPlayerOff(player)); + } + } + } + } + } + + /** + * Update the leaderboards. + * + * @param skillType The skill to update the leaderboards for + * @param player The player whose skill to update + */ + public static void ProcessLeaderboardUpdate(SkillType skillType, Player player) { + PlayerProfile PP = Users.getProfile(player); + PlayerStat ps = new PlayerStat(); + + if (skillType != SkillType.ALL) { + ps.statVal = PP.getSkillLevel(skillType); + } + else { + ps.statVal = m.getPowerLevel(player, PP); + } + + ps.name = player.getName(); + Leaderboard.updateLeaderboard(ps, skillType); + } + + /** + * Check the XP of a skill. + * + * @param skillType The skill to check + * @param player The player whose skill to check + */ + public static void XpCheckSkill(SkillType skillType, Player player) { + PlayerProfile PP = Users.getProfile(player); + + if (PP.getSkillXpLevel(skillType) >= PP.getXpToLevel(skillType)) { + int skillups = 0; + + while (PP.getSkillXpLevel(skillType) >= PP.getXpToLevel(skillType)) { + if (skillType.getMaxLevel() >= PP.getSkillLevel(skillType) + 1) { + skillups++; + PP.removeXP(skillType, PP.getXpToLevel(skillType)); + PP.skillUp(skillType, 1); + + McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType); + Bukkit.getPluginManager().callEvent(eventToFire); + } + else { + PP.removeXP(skillType, PP.getXpToLevel(skillType)); + } + } + + if (!LoadProperties.useMySQL) { + ProcessLeaderboardUpdate(skillType, player); + ProcessLeaderboardUpdate(SkillType.ALL, player); + } + + String capitalized = m.getCapitalized(skillType.toString()); + + /* Spout Stuff */ + if (LoadProperties.spoutEnabled && player instanceof SpoutPlayer) { + SpoutPlayer sPlayer = SpoutManager.getPlayer(player); + + if (sPlayer.isSpoutCraftEnabled()) { + if (LoadProperties.xpbar) { + SpoutStuff.updateXpBar(sPlayer); + } + + SpoutStuff.levelUpNotification(skillType, sPlayer); + } + else { + player.sendMessage(mcLocale.getString("Skills."+capitalized+"Up", new Object[] {String.valueOf(skillups), PP.getSkillLevel(skillType)})); + } + } + else { + player.sendMessage(mcLocale.getString("Skills."+capitalized+"Up", new Object[] {String.valueOf(skillups), PP.getSkillLevel(skillType)})); + } + } + } + + /** + * Check XP of all skills. + * + * @param player The player to check XP for. + */ + public static void XpCheckAll(Player player) { + for (SkillType x : SkillType.values()) { + //Don't want to do anything with this one + if (x == SkillType.ALL) { + continue; + } + + XpCheckSkill(x, player); + } + } + + /** + * Get the skill represented by the given string + * + * @param skillName The name of the skill + * @return the SkillType if it exists, null otherwise + */ + public static SkillType getSkillType(String skillName) { + for (SkillType x : SkillType.values()) { + if (x.toString().equals(skillName.toUpperCase())) + return x; + } + return null; + } + + /** + * Checks if the given string represents a valid skill + * + * @param skillname The name of the skill to check + * @return true if this is a valid skill, false otherwise + */ + public static boolean isSkill(String skillName) { + if (getSkillType(skillName) != null) { + return true; + } + else { + return false; + } } + /** + * Get the format string for + * @param skillname + * @param level + * @param XP + * @param XPToLevel + * @return + */ + public static String getSkillStats(String skillname, Integer level, Integer XP, Integer XPToLevel) { + //TODO: Ditch this function in favor of better locale setup. + + ChatColor parColor = ChatColor.DARK_AQUA; + ChatColor xpColor = ChatColor.GRAY; + ChatColor LvlColor = ChatColor.GREEN; + ChatColor skillColor = ChatColor.YELLOW; + + return skillColor + skillname + LvlColor + level + parColor +" XP" + "(" + xpColor + XP + parColor + "/" + xpColor + XPToLevel + parColor + ")"; + } + + /** + * Check if the player has any combat skill permissions. + * + * @param player The player to check permissions for + * @return true if the player has combat skills, false otherwise + */ + public static boolean hasCombatSkills(Player player) { + if (mcPermissions.getInstance().axes(player) + || mcPermissions.getInstance().archery(player) + || mcPermissions.getInstance().swords(player) + || mcPermissions.getInstance().taming(player) + || mcPermissions.getInstance().unarmed(player)) { + return true; + } + else { + return false; + } + } + + /** + * Check if the player has any gathering skill permissions. + * + * @param player The player to check permissions for + * @return true if the player has gathering skills, false otherwise + */ + public static boolean hasGatheringSkills(Player player) { + if (mcPermissions.getInstance().excavation(player) + || mcPermissions.getInstance().fishing(player) + || mcPermissions.getInstance().herbalism(player) + || mcPermissions.getInstance().mining(player) + || mcPermissions.getInstance().woodcutting(player)) { + return true; + } + else { + return false; + } + } + + /** + * Check if the player has any misc skill permissions. + * + * @param player The player to check permissions for + * @return true if the player has misc skills, false otherwise + */ + public static boolean hasMiscSkills(Player player) { + if (mcPermissions.getInstance().acrobatics(player) || mcPermissions.getInstance().repair(player)) { + return true; + } + else { + return false; + } + } + + /** + * Handle tool durability loss from abilities. + * + * @param inhand The item to damage + * @param durabilityLoss The durability to remove from the item + */ + public static void abilityDurabilityLoss(ItemStack inhand, int durabilityLoss) { + if (LoadProperties.toolsLoseDurabilityFromAbilities) { + if (!inhand.containsEnchantment(Enchantment.DURABILITY)) { + inhand.setDurability((short) (inhand.getDurability() + durabilityLoss)); + } + } + } + /** * Check to see if an ability can be activated. - * + * * @param player The player activating the ability * @param type The skill the ability is based on */ - public static void abilityCheck(Player player, SkillType type) - { - PlayerProfile PP = Users.getProfile(player); - AbilityType ability = type.getAbility(); - if(type.getTool().inHand(player.getItemInHand())) - { - if(type.getTool().getToolMode(PP)) - type.getTool().setToolMode(PP, false); - - //Axes and Woodcutting are odd because they share the same tool so we show them the too tired message when they take action - if(type == SkillType.WOODCUTTING || type == SkillType.AXES) - { - if(!ability.getMode(PP) && !cooldownOver(player, (PP.getSkillDATS(ability) * 1000), ability.getCooldown())) - { - player.sendMessage(mcLocale.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + calculateTimeLeft(player, (PP.getSkillDATS(ability) * 1000), ability.getCooldown()) + "s)"); + public static void abilityCheck(Player player, SkillType type) { + PlayerProfile PP = Users.getProfile(player); + AbilityType ability = type.getAbility(); + + if (type.getTool().inHand(player.getItemInHand())) { + if (type.getTool().getToolMode(PP)) { + type.getTool().setToolMode(PP, false); + } + + /* Axes and Woodcutting are odd because they share the same tool. + * We show them the too tired message when they take action. + */ + if (type == SkillType.WOODCUTTING || type == SkillType.AXES) { + if (!ability.getMode(PP) && !cooldownOver(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown())) { + player.sendMessage(mcLocale.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + calculateTimeLeft(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)"); return; } - } - - int ticks = 2 + (PP.getSkillLevel(type) / 50); - if(!ability.getMode(PP) && cooldownOver(player, PP.getSkillDATS(ability), ability.getCooldown())) - { - player.sendMessage(ability.getAbilityOn()); - for(Player y : player.getWorld().getPlayers()) - { - if(y != player && m.isNear(player.getLocation(), y.getLocation(), 10)) - y.sendMessage(ability.getAbilityPlayer(player)); - } - PP.setSkillDATS(ability, System.currentTimeMillis()+(ticks*1000)); - ability.setMode(PP, true); - } - } - } - - public static boolean triggerCheck(Player player, Block block, AbilityType ability) { - boolean activate = true; - - if (!ability.getPermissions(player)) { - activate = false; - return activate; - } - - switch (ability) { - case BERSERK: - case GIGA_DRILL_BREAKER: - case SUPER_BREAKER: - case LEAF_BLOWER: - if (!m.blockBreakSimulate(block, player, true)) { - activate = false; - break; - } + } - case GREEN_TERRA: - if (!ability.blockCheck(block.getType())) { - activate = false; - break; - } - break; - - default: - activate = false; - break; - } - return activate; + int ticks = 2 + (PP.getSkillLevel(type) / 50); + + if (!ability.getMode(PP) && cooldownOver(PP.getSkillDATS(ability), ability.getCooldown())) { + player.sendMessage(ability.getAbilityOn()); + + for (Player y : player.getWorld().getPlayers()) { + if (y != player && m.isNear(player.getLocation(), y.getLocation(), MAX_DISTANCE_AWAY)) { + y.sendMessage(ability.getAbilityPlayer(player)); + } + } + + PP.setSkillDATS(ability, System.currentTimeMillis()+(ticks * TIME_CONVERSION_FACTOR)); + ability.setMode(PP, true); + } + } + } + + /** + * Check to see if ability should be triggered. + * + * @param player The player using the ability + * @param block The block modified by the ability + * @param ability The ability to check + * @return true if the ability should activate, false otherwise + */ + public static boolean triggerCheck(Player player, Block block, AbilityType ability) { + boolean activate = true; + + if (!ability.getPermissions(player)) { + activate = false; + return activate; + } + + switch (ability) { + case BERSERK: + case GIGA_DRILL_BREAKER: + case SUPER_BREAKER: + case LEAF_BLOWER: + if (!m.blockBreakSimulate(block, player, true)) { + activate = false; + break; + } + + case GREEN_TERRA: + if (!ability.blockCheck(block.getType())) { + activate = false; + break; + } + + default: + activate = false; + break; + } + + return activate; } } diff --git a/src/main/resources/locale/locale_de.properties b/src/main/resources/locale/locale_de.properties index 3d85eaf8c..8fed8c169 100644 --- a/src/main/resources/locale/locale_de.properties +++ b/src/main/resources/locale/locale_de.properties @@ -215,10 +215,6 @@ mcPlayerListener.GreenThumb=[[YELLOW]]**GRUENER DAUMEN** mcPlayerListener.GreenThumbFail=[[DARK_RED]]**YELLOW THUMB FEHLGESCHLAGEN** mcPlayerListener.HerbalismSkill=[[YELLOW]]Kraeuterkunde Skill [[DARK_AQUA]](Herbalism): mcPlayerListener.MiningSkill=[[YELLOW]]Bergbau Skill [[DARK_AQUA]](Mining): -mcPlayerListener.MyspawnCleared=[[DARK_AQUA]]Myspawn ist freigegeben -mcPlayerListener.MyspawnNotExist=[[RED]]Lege deinen myspawn erst mit einem Bett fest -mcPlayerListener.MyspawnSet=[[DARK_AQUA]]Myspawn wurde an deine aktuelle Position gesetzt -mcPlayerListener.MyspawnTimeNotice=Du musst {0}m {1}s warten um myspawn zu nutzen mcPlayerListener.NoPermission=unzureichende mcPermissions. mcPlayerListener.NoSkillNote=[[DARK_AQUA]]Skills ohne Zugriff sind ausgeblendet mcPlayerListener.NotInParty=[[RED]]Du bist in keiner Gruppe. diff --git a/src/main/resources/locale/locale_en_us.properties b/src/main/resources/locale/locale_en_us.properties index 78e796b37..044c219cb 100644 --- a/src/main/resources/locale/locale_en_us.properties +++ b/src/main/resources/locale/locale_en_us.properties @@ -217,10 +217,6 @@ mcPlayerListener.GreenThumb=[[GREEN]]**GREEN THUMB** mcPlayerListener.GreenThumbFail=[[RED]]**GREEN THUMB FAIL** mcPlayerListener.HerbalismSkill=Herbalism: mcPlayerListener.MiningSkill=Mining: -mcPlayerListener.MyspawnCleared=[[DARK_AQUA]]Myspawn is now cleared. -mcPlayerListener.MyspawnNotExist=[[RED]]Configure your myspawn first with a bed. -mcPlayerListener.MyspawnSet=[[DARK_AQUA]]Myspawn has been set to your current location. -mcPlayerListener.MyspawnTimeNotice=You must wait {0}m {1}s to use myspawn mcPlayerListener.NoPermission=Insufficient mcPermissions. mcPlayerListener.NoSkillNote=[[DARK_GRAY]]If you don't have access to a skill it will not be shown here. mcPlayerListener.NotInParty=[[RED]]You are not in a party. diff --git a/src/main/resources/locale/locale_es_es.properties b/src/main/resources/locale/locale_es_es.properties index a72d571ff..ad8c31d34 100644 --- a/src/main/resources/locale/locale_es_es.properties +++ b/src/main/resources/locale/locale_es_es.properties @@ -215,10 +215,6 @@ mcPlayerListener.GreenThumb=[[GREEN]]**DEDOS VERDES** mcPlayerListener.GreenThumbFail=[[RED]]**DEDOS VERDES FALLIDO** mcPlayerListener.HerbalismSkill=Herboristeria: mcPlayerListener.MiningSkill=Minar: -mcPlayerListener.MyspawnCleared=[[DARK_AQUA]]Myspawn esta ahora limpio. -mcPlayerListener.MyspawnNotExist=[[RED]]Configura tu myspawn primero con una cama. -mcPlayerListener.MyspawnSet=[[DARK_AQUA]]Myspawn ha sido establecido hacia tu localizacion actual. -mcPlayerListener.MyspawnTimeNotice=Tienes que esperar {0}min {1}seg para usar myspawn mcPlayerListener.NoPermission=mcPermisos insuficientes mcPlayerListener.NoSkillNote=[[DARK_GRAY]]Si no tienes acceso a una habilidad no seras mostrado aqui. mcPlayerListener.NotInParty=[[RED]]No estas en una fiesta. diff --git a/src/main/resources/locale/locale_fi.properties b/src/main/resources/locale/locale_fi.properties index cd430819a..8d468a056 100644 --- a/src/main/resources/locale/locale_fi.properties +++ b/src/main/resources/locale/locale_fi.properties @@ -215,10 +215,6 @@ mcPlayerListener.GreenThumb=[[GREEN]]**VIHERPEUKALO** mcPlayerListener.GreenThumbFail=[[RED]]**VIHERPEUKALO EPÄONNISTUI** mcPlayerListener.HerbalismSkill=[[YELLOW]]Yrttihoito: mcPlayerListener.MiningSkill=[[YELLOW]]Kaivanto: -mcPlayerListener.MyspawnCleared=[[DARK_AQUA]]Myspawn on tyhjätty. -mcPlayerListener.MyspawnNotExist=[[RED]]Määrää myspawnisi ensin laittamalla sänky maahan. -mcPlayerListener.MyspawnSet=[[DARK_AQUA]]Myspawn on asetettu tämänhetkiseen sijaintiisi. -mcPlayerListener.MyspawnTimeNotice=Sinun pitää odottaa {0}m {1}s käyttääksesi myspawnia mcPlayerListener.NoPermission=Puutteelliset oikeudet (mcPermissions) mcPlayerListener.NoSkillNote=[[DARK_GRAY]]Jos sinulla ei ole käyttöoikeutta johonkin taitoon, sitä ei näytetä täällä. mcPlayerListener.NotInParty=[[RED]]Et ole ryhmässä. diff --git a/src/main/resources/locale/locale_fr.properties b/src/main/resources/locale/locale_fr.properties index 72a86e900..c10bf9f91 100644 --- a/src/main/resources/locale/locale_fr.properties +++ b/src/main/resources/locale/locale_fr.properties @@ -215,10 +215,6 @@ mcPlayerListener.GreenThumb=[[GREEN]]**MAIN VERTE** mcPlayerListener.GreenThumbFail=[[RED]]**MAIN VERTE A ECHOUÉ** mcPlayerListener.HerbalismSkill=[[YELLOW]]Herboriste (/Herbalism) : mcPlayerListener.MiningSkill=[[YELLOW]]Minage (/Mining): -mcPlayerListener.MyspawnCleared=[[DARK_AQUA]]Votre point de spawn a été éffacé. -mcPlayerListener.MyspawnNotExist=[[RED]]Dormez dans un lit pour définir votre point de spawn. -mcPlayerListener.MyspawnSet=[[DARK_AQUA]]Votre point de spawn a été enregistré ici. -mcPlayerListener.MyspawnTimeNotice=Vous devez attendre {0}m {1}s avant d'utiliser votre spawn mcPlayerListener.NoPermission=Vous n'avez pas les permissions nécessaires. mcPlayerListener.NoSkillNote=[[DARK_GRAY]]Si vous n'avez pas accès à une compé, elle ne sera pas affichée ici. mcPlayerListener.NotInParty=[[RED]]Vous n'êtes pas dans un groupe. diff --git a/src/main/resources/locale/locale_nl.properties b/src/main/resources/locale/locale_nl.properties index 66ae16f16..07fcc4663 100644 --- a/src/main/resources/locale/locale_nl.properties +++ b/src/main/resources/locale/locale_nl.properties @@ -221,10 +221,6 @@ mcPlayerListener.GreenThumb=[[GREEN]]**GROENE VINGERS** mcPlayerListener.GreenThumbFail=[[RED]]**GROENE VINNGERS MISLUKT** mcPlayerListener.HerbalismSkill=Landbouw: mcPlayerListener.MiningSkill=Mijnbouw: -mcPlayerListener.MyspawnCleared=[[DARK_AQUA]]Myspawn is verwijderd. -mcPlayerListener.MyspawnNotExist=[[RED]]Plaats Myspawn eerst door op een bed te drukken. -mcPlayerListener.MyspawnSet=[[DARK_AQUA]]Myspawn is geplaatst op je huidige locatie. -mcPlayerListener.MyspawnTimeNotice=Je moet {0}m {1}s wachten voordat je myspawn kan gebruiken. mcPlayerListener.NoPermission=Je hebt geen permissie. mcPlayerListener.NoSkillNote=[[DARK_GRAY]]Als je geen toegang hebt tot een skill wordt hij hier niet weergegeven. mcPlayerListener.NotInParty=[[RED]]Je zit niet in een party. diff --git a/src/main/resources/locale/locale_pl.properties b/src/main/resources/locale/locale_pl.properties index f29adbb8b..d45134279 100644 --- a/src/main/resources/locale/locale_pl.properties +++ b/src/main/resources/locale/locale_pl.properties @@ -215,10 +215,6 @@ mcPlayerListener.GreenThumb=[[GREEN]]**UZYLES ZIELONEJ ZIEMI** mcPlayerListener.GreenThumbFail=[[RED]]**UZYWANIE ZIELONEJ ZIEMI NIE POWIODLO SIE** mcPlayerListener.HerbalismSkill=Zielarstwo: mcPlayerListener.MiningSkill=Gornictwo: -mcPlayerListener.MyspawnCleared=[[DARK_AQUA]]Twoj spawn zostal usuniety. -mcPlayerListener.MyspawnNotExist=[[RED]]Musisz ustawic swoj spawn za pomoca lozka. -mcPlayerListener.MyspawnSet=[[DARK_AQUA]]Twoj spawn zostal ustawiony na twoje aktualne polozenie. -mcPlayerListener.MyspawnTimeNotice=Musisz zaczekac {0} minut i {1} sekund aby przeteleportowac sie na spawn. mcPlayerListener.NoPermission=Brak mcPermissions. mcPlayerListener.NoSkillNote=[[DARK_GRAY]]Umiejetnosci, ktorych nie mozesz uzyc nie sa wyswietlane. mcPlayerListener.NotInParty=[[RED]]Nie jestes w grupie. diff --git a/src/main/resources/locale/locale_pt_br.properties b/src/main/resources/locale/locale_pt_br.properties index 33dca845f..56805d5a8 100644 --- a/src/main/resources/locale/locale_pt_br.properties +++ b/src/main/resources/locale/locale_pt_br.properties @@ -221,10 +221,6 @@ mcPlayerListener.GreenThumb=[[GREEN]]*DEDOS VERDES* mcPlayerListener.GreenThumbFail=[[RED]]*DEDOS VERDES FALHOU* mcPlayerListener.HerbalismSkill=Herbalismo (Herbalism): mcPlayerListener.MiningSkill=Mineraçao (Mining): -mcPlayerListener.MyspawnCleared=[[DARK_AQUA]]Ponto de Spawn foi apagado. -mcPlayerListener.MyspawnNotExist=[[RED]]Primeiro crie um spawn durmindo na cama. -mcPlayerListener.MyspawnSet=[[DARK_AQUA]]Spawn foi gravado neste local. -mcPlayerListener.MyspawnTimeNotice=Você precisa esperar {0}m {1}s para usar "myspawn" mcPlayerListener.NoPermission=Nao tem permissao para realizar esta açao. mcPlayerListener.NoSkillNote=[[DARK_GRAY]]Se você nao tem acesso a uma habilidade, ela nao será exibida aqui. mcPlayerListener.NotInParty=[[RED]]Você nao está em nenhuma equipe. diff --git a/src/main/resources/locale/locale_ru.properties b/src/main/resources/locale/locale_ru.properties index 6e911fa88..f639a0b8d 100644 --- a/src/main/resources/locale/locale_ru.properties +++ b/src/main/resources/locale/locale_ru.properties @@ -216,10 +216,6 @@ mcPlayerListener.GreenThumb=[[GREEN]]**" mcPlayerListener.GreenThumbFail=[[RED]]**"Çåëåíûé ôåðìåð" íåóäàëñÿ** mcPlayerListener.HerbalismSkill=Òðàâîâåäåíèå: mcPlayerListener.MiningSkill=Øàõò¸ðñòâî: -mcPlayerListener.MyspawnCleared=[[DARK_AQUA]]Âàøà êðîâàòü óáðàíà. -mcPlayerListener.MyspawnNotExist=[[RED]]Ñäåëàéòå âàøó òî÷êó ïîÿâëåíèÿ âîçëå êðîâàòè, ïîñïàâ íà êðîâàòè. -mcPlayerListener.MyspawnSet=[[DARK_AQUA]]Ìîÿ òî÷êà ïîÿâëåíèÿ ñîõðàíåíà â ýòîé ëîêàöèè. -mcPlayerListener.MyspawnTimeNotice=Âû äîëæíû ïîäîæäàòü {0}m {1}s ÷òîáû èñïîëüçîâàòü ïîÿâëåíèå îêîëî êðîâàòè mcPlayerListener.NoPermission=Íåäîñòàòî÷íûå ïðàâà. mcPlayerListener.NoSkillNote=[[DARK_GRAY]]Åñëè ó âàñ íåò äîñòóïà ê óìåíèþ, òî îíî çäåñü íå îòîáðàçèòñÿ. mcPlayerListener.NotInParty=[[RED]]Âû íå â ãðóïïå!