From 083a89c1a36770710bfe751290f73c3f8fc06d4d Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 18 Feb 2013 11:41:44 -0500 Subject: [PATCH] Handle all our donor perks in one class. --- .../gmail/nossr50/datatypes/McMMOPlayer.java | 19 +---- .../gmail/nossr50/skills/SkillCommand.java | 17 +--- .../gmail/nossr50/skills/SkillManager.java | 4 +- .../nossr50/skills/excavation/Excavation.java | 4 +- .../gmail/nossr50/skills/fishing/Fishing.java | 5 +- .../nossr50/skills/fishing/ShakeMob.java | 4 +- .../nossr50/skills/herbalism/Herbalism.java | 9 +- .../gmail/nossr50/skills/repair/Repair.java | 6 +- .../skills/unarmed/UnarmedManager.java | 4 +- .../nossr50/skills/utilities/PerksUtils.java | 78 +++++++++++++++++ .../nossr50/skills/utilities/SkillTools.java | 83 +------------------ .../skills/woodcutting/Woodcutting.java | 4 +- .../java/com/gmail/nossr50/util/Motd.java | 42 ++-------- 13 files changed, 115 insertions(+), 164 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/skills/utilities/PerksUtils.java diff --git a/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java index c4ebf3215..72b67f84f 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java @@ -12,6 +12,7 @@ import com.gmail.nossr50.mods.datatypes.CustomTool; import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.ShareHandler; +import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.spout.huds.SpoutHud; @@ -140,23 +141,7 @@ public class McMMOPlayer { } } - // TODO: Too many permission checks here, is there no way to avoid that? - if (player.hasPermission("mcmmo.perks.xp.quadruple")) { - xp *= 4; - } - else if (player.hasPermission("mcmmo.perks.xp.triple")) { - xp *= 3; - } - else if (player.hasPermission("mcmmo.perks.xp.150percentboost")) { - xp *= 2.5; - } - else if (player.hasPermission("mcmmo.perks.xp.150percentboost")) { - xp *= 2; - } - else if (player.hasPermission("mcmmo.perks.xp.50percentboost")) { - xp *= 1.5; - } - + xp = PerksUtils.handleXpPerks(player, xp); return xp; } diff --git a/src/main/java/com/gmail/nossr50/skills/SkillCommand.java b/src/main/java/com/gmail/nossr50/skills/SkillCommand.java index 2fed8c054..26ed0cfaa 100644 --- a/src/main/java/com/gmail/nossr50/skills/SkillCommand.java +++ b/src/main/java/com/gmail/nossr50/skills/SkillCommand.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.StringUtils; @@ -124,26 +125,12 @@ public abstract class SkillCommand implements CommandExecutor { protected String[] calculateLengthDisplayValues() { int maxLength = skill.getAbility().getMaxTicks(); int length = 2 + (int) (skillValue / SkillTools.abilityLengthIncreaseLevel); - int enduranceLength = 0; - - if (player.hasPermission("mcmmo.perks.activationtime.twelveseconds")) { - enduranceLength = length + 12; - } - else if (player.hasPermission("mcmmo.perks.activationtime.eightseconds")) { - enduranceLength = length + 8; - } - else if (player.hasPermission("mcmmo.perks.activationtime.fourseconds")) { - enduranceLength = length + 4; - } + int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength); if (maxLength != 0) { if (length > maxLength) { length = maxLength; } - - if (enduranceLength > maxLength) { - enduranceLength = maxLength; - } } return new String[] { String.valueOf(length), String.valueOf(enduranceLength) }; diff --git a/src/main/java/com/gmail/nossr50/skills/SkillManager.java b/src/main/java/com/gmail/nossr50/skills/SkillManager.java index b6dc2c06b..2a1cd7614 100644 --- a/src/main/java/com/gmail/nossr50/skills/SkillManager.java +++ b/src/main/java/com/gmail/nossr50/skills/SkillManager.java @@ -1,7 +1,7 @@ package com.gmail.nossr50.skills; import com.gmail.nossr50.datatypes.McMMOPlayer; -import com.gmail.nossr50.skills.utilities.SkillTools; +import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Permissions; @@ -13,7 +13,7 @@ public abstract class SkillManager { public SkillManager(McMMOPlayer mcMMOPlayer, SkillType skill) { this.mcMMOPlayer = mcMMOPlayer; this.skillLevel = mcMMOPlayer.getProfile().getSkillLevel(skill); - this.activationChance = SkillTools.calculateActivationChance(Permissions.lucky(mcMMOPlayer.getPlayer(), skill)); + this.activationChance = PerksUtils.handleLuckyPerks(Permissions.lucky(mcMMOPlayer.getPlayer(), skill)); } public McMMOPlayer getMcMMOPlayer() { diff --git a/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java b/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java index 4d9cdffcc..424cf2b47 100644 --- a/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java @@ -13,7 +13,7 @@ import com.gmail.nossr50.config.TreasuresConfig; import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; import com.gmail.nossr50.mods.ModChecks; -import com.gmail.nossr50.skills.utilities.SkillTools; +import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -105,7 +105,7 @@ public class Excavation { for (ExcavationTreasure treasure : treasures) { if (mcMMOPlayer.getProfile().getSkillLevel(SkillType.EXCAVATION) >= treasure.getDropLevel()) { - int activationChance = SkillTools.calculateActivationChance(Permissions.luckyExcavation(player)); + int activationChance = PerksUtils.handleLuckyPerks(Permissions.luckyExcavation(player)); if (Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) { xp += treasure.getXp(); diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java b/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java index a2b073204..2acef48bf 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java @@ -18,6 +18,7 @@ import com.gmail.nossr50.config.TreasuresConfig; import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.treasure.FishingTreasure; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.ItemChecks; @@ -160,7 +161,7 @@ public final class Fishing { FishingTreasure treasure = rewards.get(Misc.getRandom().nextInt(rewards.size())); ItemStack treasureDrop = treasure.getDrop(); - int activationChance = SkillTools.calculateActivationChance(Permissions.luckyFishing(player)); + int activationChance = PerksUtils.handleLuckyPerks(Permissions.luckyFishing(player)); if (Misc.getRandom().nextDouble() * activationChance > treasure.getDropChance()) { return null; @@ -189,7 +190,7 @@ public final class Fishing { return false; } - int activationChance = SkillTools.calculateActivationChance(Permissions.luckyFishing(player)); + int activationChance = PerksUtils.handleLuckyPerks(Permissions.luckyFishing(player)); if (storm) { activationChance = (int) (activationChance * 0.909); diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/ShakeMob.java b/src/main/java/com/gmail/nossr50/skills/fishing/ShakeMob.java index 24632fb3f..c4e728213 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/ShakeMob.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/ShakeMob.java @@ -18,7 +18,7 @@ import org.bukkit.potion.PotionType; import com.gmail.nossr50.skills.fishing.Fishing.Tier; import com.gmail.nossr50.skills.utilities.CombatTools; -import com.gmail.nossr50.skills.utilities.SkillTools; +import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -33,7 +33,7 @@ public final class ShakeMob { * @param skillLevel Fishing level of the player */ public static void process(Player player, LivingEntity mob, int skillLevel) { - int activationChance = SkillTools.calculateActivationChance(Permissions.luckyFishing(player)); + int activationChance = PerksUtils.handleLuckyPerks(Permissions.luckyFishing(player)); if (getShakeProbability(skillLevel) <= Misc.getRandom().nextInt(activationChance)) { return; diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java index 06fb45b2d..fcc4f06fb 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java @@ -25,6 +25,7 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mods.ModChecks; import com.gmail.nossr50.mods.datatypes.CustomBlock; import com.gmail.nossr50.skills.utilities.AbilityType; +import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Misc; @@ -190,7 +191,7 @@ public class Herbalism { } if (Permissions.herbalismDoubleDrops(player)) { - int activationChance = SkillTools.calculateActivationChance(Permissions.luckyHerbalism(player)); + int activationChance = PerksUtils.handleLuckyPerks(Permissions.luckyHerbalism(player)); double chance = (doubleDropsMaxChance / doubleDropsMaxLevel) * SkillTools.skillCheck(herbLevel, doubleDropsMaxLevel); if (chance > Misc.getRandom().nextInt(activationChance)) { @@ -254,7 +255,7 @@ public class Herbalism { return; } - int activationChance = SkillTools.calculateActivationChance(Permissions.luckyHerbalism(player)); + int activationChance = PerksUtils.handleLuckyPerks(Permissions.luckyHerbalism(player)); float chance = (float) (greenThumbMaxChance / greenThumbMaxLevel * herbLevel); if (chance > greenThumbMaxChance) { @@ -301,7 +302,7 @@ public class Herbalism { player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1)); - int activationChance = SkillTools.calculateActivationChance(Permissions.luckyHerbalism(player)); + int activationChance = PerksUtils.handleLuckyPerks(Permissions.luckyHerbalism(player)); float chance = (float) ((greenThumbMaxChance / greenThumbMaxLevel) * skillLevel); if (chance > greenThumbMaxChance) chance = (float) greenThumbMaxChance; @@ -318,7 +319,7 @@ public class Herbalism { int skillLevel = Users.getPlayer(player).getProfile().getSkillLevel(SkillType.HERBALISM); double chance = (hylianLuckMaxChance / hylianLuckMaxLevel) * SkillTools.skillCheck(skillLevel, hylianLuckMaxLevel); - int activationChance = SkillTools.calculateActivationChance(Permissions.luckyHerbalism(player)); + int activationChance = PerksUtils.handleLuckyPerks(Permissions.luckyHerbalism(player)); if (chance > Misc.getRandom().nextInt(activationChance)) { List treasures = new ArrayList(); diff --git a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java index 68ae81615..066baf04d 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java @@ -17,7 +17,7 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.skills.utilities.SkillTools; +import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -110,7 +110,7 @@ public class Repair { for (Entry enchant : enchants.entrySet()) { Enchantment enchantment = enchant.getKey(); - int activationChance = SkillTools.calculateActivationChance(Permissions.luckyRepair(player)); + int activationChance = PerksUtils.handleLuckyPerks(Permissions.luckyRepair(player)); if (Misc.getRandom().nextInt(activationChance) <= getEnchantChance(rank)) { int enchantLevel = enchant.getValue(); @@ -237,7 +237,7 @@ public class Repair { int chance = (int) ((SUPER_REPAIR_CHANCE_MAX / SUPER_REPAIR_MAX_BONUS_LEVEL) * skillLevel); if (skillLevel >= SUPER_REPAIR_MAX_BONUS_LEVEL) chance = (int) SUPER_REPAIR_CHANCE_MAX; - int activationChance = SkillTools.calculateActivationChance(Permissions.luckyRepair(player)); + int activationChance = PerksUtils.handleLuckyPerks(Permissions.luckyRepair(player)); if (chance > Misc.getRandom().nextInt(activationChance) && Permissions.repairBonus(player)) { player.sendMessage(LocaleLoader.getString("Repair.Skills.FeltEasy")); diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java index 2395a724a..36915c8fc 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java @@ -6,7 +6,7 @@ import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.skills.SkillManager; -import com.gmail.nossr50.skills.utilities.SkillTools; +import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -87,7 +87,7 @@ public class UnarmedManager extends SkillManager { double chance = (Unarmed.ironGripMaxChance / Unarmed.ironGripMaxBonusLevel) * eventHandler.skillModifier; - if (chance > Misc.getRandom().nextInt(SkillTools.calculateActivationChance(Permissions.luckyUnarmed(defender)))) { + if (chance > Misc.getRandom().nextInt(PerksUtils.handleLuckyPerks(Permissions.luckyUnarmed(defender)))) { eventHandler.sendAbilityMessages(); return true; } diff --git a/src/main/java/com/gmail/nossr50/skills/utilities/PerksUtils.java b/src/main/java/com/gmail/nossr50/skills/utilities/PerksUtils.java new file mode 100644 index 000000000..163b3de9c --- /dev/null +++ b/src/main/java/com/gmail/nossr50/skills/utilities/PerksUtils.java @@ -0,0 +1,78 @@ +package com.gmail.nossr50.skills.utilities; + +import org.bukkit.entity.Player; + +import com.gmail.nossr50.util.Permissions; + +public final class PerksUtils { + private static final int LUCKY_SKILL_ACTIVATION_CHANCE = 75; + private static final int NORMAL_SKILL_ACTIVATION_CHANCE = 100; + + private PerksUtils() {}; + + public static int handleCooldownPerks(Player player, int cooldown) { + if (Permissions.cooldownsHalved(player)) { + cooldown *= 0.5; + } + else if (Permissions.cooldownsThirded(player)) { + cooldown *= (1.0 / 3.0); + } + else if (Permissions.cooldownsQuartered(player)) { + cooldown *= 0.75; + } + + return cooldown; + } + + public static int handleActivationPerks(Player player, int ticks, int maxTicks) { + if (Permissions.activationTwelve(player)) { + ticks += 12; + } + else if (Permissions.activationEight(player)) { + ticks += 8; + } + else if (Permissions.activationFour(player)) { + ticks += 4; + } + + if (maxTicks != 0 && ticks > maxTicks) { + ticks = maxTicks; + } + + return ticks; + } + + public static int handleXpPerks(Player player, int xp) { + if (player.hasPermission("mcmmo.perks.xp.quadruple")) { + xp *= 4; + } + else if (player.hasPermission("mcmmo.perks.xp.triple")) { + xp *= 3; + } + else if (player.hasPermission("mcmmo.perks.xp.150percentboost")) { + xp *= 2.5; + } + else if (player.hasPermission("mcmmo.perks.xp.150percentboost")) { + xp *= 2; + } + else if (player.hasPermission("mcmmo.perks.xp.50percentboost")) { + xp *= 1.5; + } + + return xp; + } + + /** + * Calculate activation chance for a skill. + * + * @param isLucky true if the player has the appropriate "lucky" perk, false otherwise + * @return the activation chance + */ + public static int handleLuckyPerks(boolean isLucky) { + if (isLucky) { + return LUCKY_SKILL_ACTIVATION_CHANCE; + } + + return NORMAL_SKILL_ACTIVATION_CHANCE; + } +} diff --git a/src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java b/src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java index 4eabef72c..c3765bab3 100644 --- a/src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java +++ b/src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java @@ -41,9 +41,6 @@ public class SkillTools { public static int toolDurabilityLoss = Config.getInstance().getAbilityToolDamage(); public static int abilityLengthIncreaseLevel = AdvancedConfig.getInstance().getAbilityLength(); - public static final int LUCKY_SKILL_ACTIVATION_CHANCE = 75; - public static final int NORMAL_SKILL_ACTIVATION_CHANCE = 100; - public static void handleFoodSkills(Player player, SkillType skill, FoodLevelChangeEvent event, int baseLevel, int maxLevel, int rankChange) { int skillLevel = Users.getPlayer(player).getProfile().getSkillLevel(skill); @@ -70,18 +67,7 @@ public class SkillTools { */ public static boolean cooldownOver(long oldTime, int cooldown, Player player) { long currentTime = System.currentTimeMillis(); - int adjustedCooldown = cooldown; - - //Reduced Cooldown Donor Perks - if (Permissions.cooldownsHalved(player)) { - adjustedCooldown = (int) (adjustedCooldown * 0.5); - } - else if (Permissions.cooldownsThirded(player)) { - adjustedCooldown = (int) (adjustedCooldown * 0.66); - } - else if (Permissions.cooldownsQuartered(player)) { - adjustedCooldown = (int) (adjustedCooldown * 0.75); - } + int adjustedCooldown = PerksUtils.handleCooldownPerks(player, cooldown); if (currentTime - oldTime >= (adjustedCooldown * Misc.TIME_CONVERSION_FACTOR)) { return true; @@ -98,20 +84,7 @@ public class SkillTools { * @return the number of seconds remaining before the cooldown expires */ public static int calculateTimeLeft(long deactivatedTimeStamp, int cooldown, Player player) { - int adjustedCooldown = cooldown; - - //Reduced Cooldown Donor Perks - if (Permissions.cooldownsHalved(player)) { - adjustedCooldown = (int) (adjustedCooldown * 0.5); - } - else if (Permissions.cooldownsThirded(player)) { - adjustedCooldown = (int) (adjustedCooldown * 0.66); - } - else if (Permissions.cooldownsQuartered(player)) { - adjustedCooldown = (int) (adjustedCooldown * 0.75); - } - - return (int) (((deactivatedTimeStamp + (adjustedCooldown * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR); + return (int) (((deactivatedTimeStamp + (PerksUtils.handleCooldownPerks(player, cooldown) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR); } /** @@ -386,24 +359,6 @@ public class SkillTools { 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 (Config.getInstance().getAbilitiesDamageTools()) { - if (inHand.containsEnchantment(Enchantment.DURABILITY)) { - int level = inHand.getEnchantmentLevel(Enchantment.DURABILITY); - if (Misc.getRandom().nextInt(level + 1) > 0) { - return; - } - } - inHand.setDurability((short) (inHand.getDurability() + durabilityLoss)); - } - } - /** * Check to see if an ability can be activated. * @@ -427,30 +382,12 @@ public class SkillTools { } } - int ticks = 2 + (profile.getSkillLevel(type) / abilityLengthIncreaseLevel); - - if (Permissions.activationTwelve(player)) { - ticks = ticks + 12; - } - else if (Permissions.activationEight(player)) { - ticks = ticks + 8; - } - else if (Permissions.activationFour(player)) { - ticks = ticks + 4; - } - - int maxTicks = ability.getMaxTicks(); - - if (maxTicks != 0 && ticks > maxTicks) { - ticks = maxTicks; - } - if (!profile.getAbilityMode(ability) && cooldownOver(profile.getSkillDATS(ability), ability.getCooldown(), player)) { player.sendMessage(ability.getAbilityOn()); SkillTools.sendSkillMessage(player, ability.getAbilityPlayer(player)); - profile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR)); + profile.setSkillDATS(ability, System.currentTimeMillis() + (PerksUtils.handleActivationPerks(player, 2 + (profile.getSkillLevel(type) / abilityLengthIncreaseLevel), ability.getMaxTicks()) * Misc.TIME_CONVERSION_FACTOR)); profile.setAbilityMode(ability, true); if (ability == AbilityType.BERSERK) { @@ -504,20 +441,6 @@ public class SkillTools { return activate; } - /** - * Calculate activation chance for a skill. - * - * @param isLucky true if the player has the appropriate "lucky" perk, false otherwise - * @return the activation chance - */ - public static int calculateActivationChance(boolean isLucky) { - if (isLucky) { - return LUCKY_SKILL_ACTIVATION_CHANCE; - } - - return NORMAL_SKILL_ACTIVATION_CHANCE; - } - public static void sendSkillMessage(Player player, String message) { for (Player otherPlayer : player.getWorld().getPlayers()) { if (otherPlayer != player && Misc.isNear(player.getLocation(), otherPlayer.getLocation(), Misc.SKILL_MESSAGE_MAX_SENDING_DISTANCE)) { diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java index dc82c79e6..933a7701d 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java @@ -15,7 +15,7 @@ import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.mods.ModChecks; import com.gmail.nossr50.mods.datatypes.CustomBlock; -import com.gmail.nossr50.skills.utilities.SkillTools; +import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -143,7 +143,7 @@ public final class Woodcutting { double configDoubleDropChance = ADVANCED_CONFIG.getWoodcuttingDoubleDropChance(); int configDoubleDropMaxLevel = ADVANCED_CONFIG.getWoodcuttingDoubleDropMaxLevel(); int probability = (int) ((configDoubleDropChance / configDoubleDropMaxLevel) * Users.getPlayer(player).getProfile().getSkillLevel(SkillType.WOODCUTTING)); - int activationChance = SkillTools.calculateActivationChance(Permissions.luckyWoodcutting(player)); + int activationChance = PerksUtils.handleLuckyPerks(Permissions.luckyWoodcutting(player)); if (probability > configDoubleDropChance) { probability = (int) configDoubleDropChance; diff --git a/src/main/java/com/gmail/nossr50/util/Motd.java b/src/main/java/com/gmail/nossr50/util/Motd.java index b2af293d9..c3ed504af 100644 --- a/src/main/java/com/gmail/nossr50/util/Motd.java +++ b/src/main/java/com/gmail/nossr50/util/Motd.java @@ -1,11 +1,14 @@ package com.gmail.nossr50.util; +import java.text.DecimalFormat; + import org.bukkit.entity.Player; import org.bukkit.plugin.PluginDescriptionFile; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.skills.utilities.SkillType; public final class Motd { @@ -56,21 +59,7 @@ public final class Motd { * @param player Target player */ public static void displayXpPerks(Player player) { - if (Permissions.xpQuadruple(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", 4))); - } - else if (Permissions.xpTriple(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", 3))); - } - else if (Permissions.xpDoubleAndOneHalf(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", 2.5))); - } - else if (Permissions.xpDouble(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", 2))); - } - else if (Permissions.xpOneAndOneHalf(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", 1.5))); - } + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.xp.name"), LocaleLoader.getString("Perks.xp.desc", PerksUtils.handleXpPerks(player, 1)))); } /** @@ -78,15 +67,10 @@ public final class Motd { * @param player Target player */ public static void displayCooldownPerks(Player player) { - if (Permissions.cooldownsHalved(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.cooldowns.name"), LocaleLoader.getString("Perks.cooldowns.desc", "1/2"))); - } - else if (Permissions.cooldownsThirded(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.cooldowns.name"), LocaleLoader.getString("Perks.cooldowns.desc", "1/3"))); - } - else if (Permissions.cooldownsQuartered(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.cooldowns.name"), LocaleLoader.getString("Perks.cooldowns.desc", "1/4"))); - } + double cooldownReduction = 1 - (PerksUtils.handleCooldownPerks(player, 12) / 12.0); + DecimalFormat percent = new DecimalFormat("##0.00%"); + + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.cooldowns.name"), LocaleLoader.getString("Perks.cooldowns.desc", percent.format(cooldownReduction)))); } /** @@ -94,15 +78,7 @@ public final class Motd { * @param player Target player */ public static void displayActivationPerks(Player player) { - if (Permissions.activationTwelve(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.activationtime.name"), LocaleLoader.getString("Perks.activationtime.desc", 12))); - } - else if (Permissions.activationEight(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.activationtime.name"), LocaleLoader.getString("Perks.activationtime.desc", 8))); - } - else if (Permissions.activationFour(player)) { - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.activationtime.name"), LocaleLoader.getString("Perks.activationtime.desc", 4))); - } + player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.activationtime.name"), LocaleLoader.getString("Perks.activationtime.desc", PerksUtils.handleActivationPerks(player, 0, 0)))); } /**