From 55b88f02747d134569e0d857f6b5c9fd63610b69 Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 13 Feb 2013 16:45:49 -0500 Subject: [PATCH] These belong better in SkillTools than Misc --- .../gmail/nossr50/skills/SkillManager.java | 4 +- .../skills/acrobatics/DodgeEventHandler.java | 3 +- .../skills/acrobatics/RollEventHandler.java | 4 +- .../archery/ArrowTrackingEventHandler.java | 4 +- .../skills/archery/DazeEventHandler.java | 3 +- .../skills/axes/CriticalHitEventHandler.java | 4 +- .../nossr50/skills/excavation/Excavation.java | 2 +- .../gmail/nossr50/skills/fishing/Fishing.java | 4 +- .../nossr50/skills/fishing/ShakeMob.java | 3 +- .../nossr50/skills/herbalism/Herbalism.java | 12 ++--- .../mining/MiningBlockEventHandler.java | 4 +- .../mining/RemoteDetonationEventHandler.java | 2 +- .../gmail/nossr50/skills/repair/Repair.java | 5 ++- .../smelting/FluxMiningEventHandler.java | 3 +- .../smelting/SmeltResourceEventHandler.java | 4 +- .../skills/swords/BleedEventHandler.java | 4 +- .../swords/CounterAttackEventHandler.java | 4 +- .../skills/taming/GoreEventHandler.java | 4 +- .../skills/unarmed/DeflectEventHandler.java | 4 +- .../skills/unarmed/DisarmEventHandler.java | 3 +- .../skills/unarmed/IronGripEventHandler.java | 4 +- .../skills/unarmed/UnarmedManager.java | 3 +- .../nossr50/skills/utilities/SkillTools.java | 45 ++++++++++++++++++- .../skills/woodcutting/Woodcutting.java | 3 +- .../java/com/gmail/nossr50/util/Misc.java | 41 ----------------- 25 files changed, 92 insertions(+), 84 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/SkillManager.java b/src/main/java/com/gmail/nossr50/skills/SkillManager.java index f4a484248..b6dc2c06b 100644 --- a/src/main/java/com/gmail/nossr50/skills/SkillManager.java +++ b/src/main/java/com/gmail/nossr50/skills/SkillManager.java @@ -1,8 +1,8 @@ package com.gmail.nossr50.skills; import com.gmail.nossr50.datatypes.McMMOPlayer; +import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillType; -import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; public abstract class SkillManager { @@ -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 = Misc.calculateActivationChance(Permissions.lucky(mcMMOPlayer.getPlayer(), skill)); + this.activationChance = SkillTools.calculateActivationChance(Permissions.lucky(mcMMOPlayer.getPlayer(), skill)); } public McMMOPlayer getMcMMOPlayer() { diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java index a7d9ccf4c..f8048ace9 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java @@ -4,6 +4,7 @@ import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Misc; @@ -17,7 +18,7 @@ public class DodgeEventHandler extends AcrobaticsEventHandler { @Override protected void calculateSkillModifier() { - this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Acrobatics.dodgeMaxBonusLevel); + this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Acrobatics.dodgeMaxBonusLevel); } @Override diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java index 2ef4e2862..81fb9367d 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java @@ -4,8 +4,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillType; -import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; public class RollEventHandler extends AcrobaticsEventHandler { @@ -29,7 +29,7 @@ public class RollEventHandler extends AcrobaticsEventHandler { skillModifer = skillModifer * 2; } - skillModifer = Misc.skillCheck(skillModifer, Acrobatics.rollMaxBonusLevel); + skillModifer = SkillTools.skillCheck(skillModifer, Acrobatics.rollMaxBonusLevel); this.skillModifier = skillModifer; } diff --git a/src/main/java/com/gmail/nossr50/skills/archery/ArrowTrackingEventHandler.java b/src/main/java/com/gmail/nossr50/skills/archery/ArrowTrackingEventHandler.java index 311f1a422..6b662c62d 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/ArrowTrackingEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/ArrowTrackingEventHandler.java @@ -2,7 +2,7 @@ package com.gmail.nossr50.skills.archery; import org.bukkit.entity.LivingEntity; -import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.skills.utilities.SkillTools; public class ArrowTrackingEventHandler { private ArcheryManager manager; @@ -18,7 +18,7 @@ public class ArrowTrackingEventHandler { } protected void calculateSkillModifier() { - this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Archery.retrieveMaxBonusLevel); + this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Archery.retrieveMaxBonusLevel); } protected void addToTracker() { diff --git a/src/main/java/com/gmail/nossr50/skills/archery/DazeEventHandler.java b/src/main/java/com/gmail/nossr50/skills/archery/DazeEventHandler.java index 6693274d1..59f1b7bea 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/DazeEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/DazeEventHandler.java @@ -5,6 +5,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.util.Misc; public class DazeEventHandler { @@ -25,7 +26,7 @@ public class DazeEventHandler { } protected void calculateSkillModifier() { - this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Archery.dazeMaxBonusLevel); + this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Archery.dazeMaxBonusLevel); } protected void handleDazeEffect() { diff --git a/src/main/java/com/gmail/nossr50/skills/axes/CriticalHitEventHandler.java b/src/main/java/com/gmail/nossr50/skills/axes/CriticalHitEventHandler.java index e72d72dc2..d47d91155 100644 --- a/src/main/java/com/gmail/nossr50/skills/axes/CriticalHitEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/axes/CriticalHitEventHandler.java @@ -5,7 +5,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.skills.utilities.SkillTools; public class CriticalHitEventHandler { private AxeManager manager; @@ -42,6 +42,6 @@ public class CriticalHitEventHandler { } private void calculateSkillModifier() { - this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Axes.criticalHitMaxBonusLevel); + this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Axes.criticalHitMaxBonusLevel); } } 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 88d39edd8..e71fce6d6 100644 --- a/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java @@ -109,7 +109,7 @@ public class Excavation { for (ExcavationTreasure treasure : treasures) { if (mcMMOPlayer.getProfile().getSkillLevel(SkillType.EXCAVATION) >= treasure.getDropLevel()) { - int activationChance = Misc.calculateActivationChance(Permissions.luckyExcavation(player)); + int activationChance = SkillTools.calculateActivationChance(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 353e1b53a..a2b073204 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/Fishing.java @@ -160,7 +160,7 @@ public final class Fishing { FishingTreasure treasure = rewards.get(Misc.getRandom().nextInt(rewards.size())); ItemStack treasureDrop = treasure.getDrop(); - int activationChance = Misc.calculateActivationChance(Permissions.luckyFishing(player)); + int activationChance = SkillTools.calculateActivationChance(Permissions.luckyFishing(player)); if (Misc.getRandom().nextDouble() * activationChance > treasure.getDropChance()) { return null; @@ -189,7 +189,7 @@ public final class Fishing { return false; } - int activationChance = Misc.calculateActivationChance(Permissions.luckyFishing(player)); + int activationChance = SkillTools.calculateActivationChance(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 fee79099a..e1da3a822 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/ShakeMob.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/ShakeMob.java @@ -17,6 +17,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.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -31,7 +32,7 @@ public final class ShakeMob { * @param skillLevel Fishing level of the player */ public static void process(Player player, LivingEntity mob, int skillLevel) { - int activationChance = Misc.calculateActivationChance(Permissions.luckyFishing(player)); + int activationChance = SkillTools.calculateActivationChance(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 c069d05c2..a0a251081 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java @@ -190,8 +190,8 @@ public class Herbalism { } if (Permissions.herbalismDoubleDrops(player)) { - int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player)); - double chance = (doubleDropsMaxChance / doubleDropsMaxLevel) * Misc.skillCheck(herbLevel, doubleDropsMaxLevel); + int activationChance = SkillTools.calculateActivationChance(Permissions.luckyHerbalism(player)); + double chance = (doubleDropsMaxChance / doubleDropsMaxLevel) * SkillTools.skillCheck(herbLevel, doubleDropsMaxLevel); if (chance > Misc.getRandom().nextInt(activationChance)) { Location location = block.getLocation(); @@ -259,7 +259,7 @@ public class Herbalism { break; } - int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player)); + int activationChance = SkillTools.calculateActivationChance(Permissions.luckyHerbalism(player)); float chance = (float) ((greenThumbMaxChance / greenThumbMaxLevel) * herbLevel); if (chance > greenThumbMaxChance) chance = (float) greenThumbMaxChance; @@ -326,7 +326,7 @@ public class Herbalism { player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1)); - int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player)); + int activationChance = SkillTools.calculateActivationChance(Permissions.luckyHerbalism(player)); float chance = (float) ((greenThumbMaxChance / greenThumbMaxLevel) * skillLevel); if (chance > greenThumbMaxChance) chance = (float) greenThumbMaxChance; @@ -342,8 +342,8 @@ public class Herbalism { public static void hylianLuck(Block block, Player player, BlockBreakEvent event) { int skillLevel = Users.getPlayer(player).getProfile().getSkillLevel(SkillType.HERBALISM); - double chance = (hylianLuckMaxChance / hylianLuckMaxLevel) * Misc.skillCheck(skillLevel, hylianLuckMaxLevel); - int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player)); + double chance = (hylianLuckMaxChance / hylianLuckMaxLevel) * SkillTools.skillCheck(skillLevel, hylianLuckMaxLevel); + int activationChance = SkillTools.calculateActivationChance(Permissions.luckyHerbalism(player)); if (chance > Misc.getRandom().nextInt(activationChance)) { List treasures = new ArrayList(); diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java index 0264dfb2a..2926ef90a 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java @@ -5,7 +5,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; -import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.skills.utilities.SkillTools; public class MiningBlockEventHandler { private MiningManager manager; @@ -24,7 +24,7 @@ public class MiningBlockEventHandler { } private void calculateSkillModifier() { - this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Mining.doubleDropsMaxLevel); + this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Mining.doubleDropsMaxLevel); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/mining/RemoteDetonationEventHandler.java b/src/main/java/com/gmail/nossr50/skills/mining/RemoteDetonationEventHandler.java index 6d3cd975e..d37e52f26 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/RemoteDetonationEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/RemoteDetonationEventHandler.java @@ -55,7 +55,7 @@ public class RemoteDetonationEventHandler { protected void sendMessages() { Player player = manager.getMcMMOPlayer().getPlayer(); - Misc.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player)); + SkillTools.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player)); player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom")); } 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 2050d66fd..68ae81615 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java @@ -17,6 +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.SkillType; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -109,7 +110,7 @@ public class Repair { for (Entry enchant : enchants.entrySet()) { Enchantment enchantment = enchant.getKey(); - int activationChance = Misc.calculateActivationChance(Permissions.luckyRepair(player)); + int activationChance = SkillTools.calculateActivationChance(Permissions.luckyRepair(player)); if (Misc.getRandom().nextInt(activationChance) <= getEnchantChance(rank)) { int enchantLevel = enchant.getValue(); @@ -236,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 = Misc.calculateActivationChance(Permissions.luckyRepair(player)); + int activationChance = SkillTools.calculateActivationChance(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/smelting/FluxMiningEventHandler.java b/src/main/java/com/gmail/nossr50/skills/smelting/FluxMiningEventHandler.java index f1e0d9853..2e50b5ac8 100644 --- a/src/main/java/com/gmail/nossr50/skills/smelting/FluxMiningEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/smelting/FluxMiningEventHandler.java @@ -9,6 +9,7 @@ import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.mining.Mining; +import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -51,7 +52,7 @@ public class FluxMiningEventHandler { McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer(); if (Permissions.secondSmelt(mcMMOPlayer.getPlayer())) { - int chance = (int) ((Mining.doubleDropsMaxChance / Mining.doubleDropsMaxLevel) * (Misc.skillCheck(mcMMOPlayer.getProfile().getSkillLevel(SkillType.MINING), Mining.doubleDropsMaxLevel))); + int chance = (int) ((Mining.doubleDropsMaxChance / Mining.doubleDropsMaxLevel) * (SkillTools.skillCheck(mcMMOPlayer.getProfile().getSkillLevel(SkillType.MINING), Mining.doubleDropsMaxLevel))); Misc.randomDropItem(location, item, chance); } } diff --git a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltResourceEventHandler.java b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltResourceEventHandler.java index 5040b98d3..d617a3a7e 100644 --- a/src/main/java/com/gmail/nossr50/skills/smelting/SmeltResourceEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/smelting/SmeltResourceEventHandler.java @@ -7,8 +7,8 @@ import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.McMMOPlayer; +import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillType; -import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; public class SmeltResourceEventHandler { @@ -23,7 +23,7 @@ public class SmeltResourceEventHandler { } protected void calculateSkillModifier() { - this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Smelting.secondSmeltMaxLevel); + this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Smelting.secondSmeltMaxLevel); } protected void handleXPGain() { diff --git a/src/main/java/com/gmail/nossr50/skills/swords/BleedEventHandler.java b/src/main/java/com/gmail/nossr50/skills/swords/BleedEventHandler.java index ed0d1aa96..332e98b8d 100644 --- a/src/main/java/com/gmail/nossr50/skills/swords/BleedEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/swords/BleedEventHandler.java @@ -5,7 +5,7 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.runnables.BleedTimer; -import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.skills.utilities.SkillTools; public class BleedEventHandler { private SwordsManager manager; @@ -22,7 +22,7 @@ public class BleedEventHandler { } protected void calculateSkillModifier() { - this.skillModifier = Misc.skillCheck(skillLevel, Swords.bleedMaxBonusLevel); + this.skillModifier = SkillTools.skillCheck(skillLevel, Swords.bleedMaxBonusLevel); } protected void addBleedTicks() { diff --git a/src/main/java/com/gmail/nossr50/skills/swords/CounterAttackEventHandler.java b/src/main/java/com/gmail/nossr50/skills/swords/CounterAttackEventHandler.java index 5c12913c0..15022eadd 100644 --- a/src/main/java/com/gmail/nossr50/skills/swords/CounterAttackEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/swords/CounterAttackEventHandler.java @@ -5,7 +5,7 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.utilities.CombatTools; -import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.skills.utilities.SkillTools; public class CounterAttackEventHandler { private SwordsManager manager; @@ -20,7 +20,7 @@ public class CounterAttackEventHandler { } protected void calculateSkillModifier() { - this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Swords.counterAttackMaxBonusLevel); + this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Swords.counterAttackMaxBonusLevel); } protected void dealDamage() { diff --git a/src/main/java/com/gmail/nossr50/skills/taming/GoreEventHandler.java b/src/main/java/com/gmail/nossr50/skills/taming/GoreEventHandler.java index 710606ef5..ae069ba02 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/GoreEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/GoreEventHandler.java @@ -7,7 +7,7 @@ import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.runnables.BleedTimer; -import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.skills.utilities.SkillTools; public class GoreEventHandler { private TamingManager manager; @@ -23,7 +23,7 @@ public class GoreEventHandler { } protected void calculateSkillModifier() { - this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Taming.goreMaxBonusLevel); + this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Taming.goreMaxBonusLevel); } protected void modifyEventDamage() { diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/DeflectEventHandler.java b/src/main/java/com/gmail/nossr50/skills/unarmed/DeflectEventHandler.java index f4940e2ef..2fadd16ac 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/DeflectEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/DeflectEventHandler.java @@ -3,7 +3,7 @@ package com.gmail.nossr50.skills.unarmed; import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.skills.utilities.SkillTools; public class DeflectEventHandler { private UnarmedManager manager; @@ -18,7 +18,7 @@ public class DeflectEventHandler { } protected void calculateSkillModifier() { - this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Unarmed.deflectMaxBonusLevel); + this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Unarmed.deflectMaxBonusLevel); } protected void sendAbilityMessage() { diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/DisarmEventHandler.java b/src/main/java/com/gmail/nossr50/skills/unarmed/DisarmEventHandler.java index 91a02c727..272a88e52 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/DisarmEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/DisarmEventHandler.java @@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.events.skills.McMMOPlayerDisarmEvent; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.util.Misc; public class DisarmEventHandler { @@ -26,7 +27,7 @@ public class DisarmEventHandler { } protected void calculateSkillModifier() { - this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Unarmed.disarmMaxBonusLevel); + this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Unarmed.disarmMaxBonusLevel); } private void sendAbilityMessage() { diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/IronGripEventHandler.java b/src/main/java/com/gmail/nossr50/skills/unarmed/IronGripEventHandler.java index fd12e99d5..554d189ab 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/IronGripEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/IronGripEventHandler.java @@ -3,8 +3,8 @@ package com.gmail.nossr50.skills.unarmed; import org.bukkit.entity.Player; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillType; -import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Users; public class IronGripEventHandler { @@ -20,7 +20,7 @@ public class IronGripEventHandler { } protected void calculateSkillModifier() { - this.skillModifier = Misc.skillCheck(Users.getPlayer(defender).getProfile().getSkillLevel(SkillType.UNARMED), Unarmed.ironGripMaxBonusLevel); + this.skillModifier = SkillTools.skillCheck(Users.getPlayer(defender).getProfile().getSkillLevel(SkillType.UNARMED), Unarmed.ironGripMaxBonusLevel); } protected void sendAbilityMessages() { 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 9d1f0dc92..2395a724a 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java @@ -6,6 +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.SkillType; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -86,7 +87,7 @@ public class UnarmedManager extends SkillManager { double chance = (Unarmed.ironGripMaxChance / Unarmed.ironGripMaxBonusLevel) * eventHandler.skillModifier; - if (chance > Misc.getRandom().nextInt(Misc.calculateActivationChance(Permissions.luckyUnarmed(defender)))) { + if (chance > Misc.getRandom().nextInt(SkillTools.calculateActivationChance(Permissions.luckyUnarmed(defender)))) { eventHandler.sendAbilityMessages(); return true; } 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 f814387e4..079c2f968 100644 --- a/src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java +++ b/src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java @@ -27,6 +27,9 @@ public class SkillTools { public static int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength(); public static boolean abilitiesEnabled = Config.getInstance().getAbilitiesEnabled(); + 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); @@ -205,7 +208,7 @@ public class SkillTools { profile.setAbilityInformed(ability, false); player.sendMessage(ability.getAbilityOff()); - Misc.sendSkillMessage(player, ability.getAbilityPlayerOff(player)); + sendSkillMessage(player, ability.getAbilityPlayerOff(player)); } } } @@ -420,7 +423,7 @@ public class SkillTools { if (!profile.getAbilityMode(ability) && cooldownOver(profile.getSkillDATS(ability), ability.getCooldown(), player)) { player.sendMessage(ability.getAbilityOn()); - Misc.sendSkillMessage(player, ability.getAbilityPlayer(player)); + SkillTools.sendSkillMessage(player, ability.getAbilityPlayer(player)); profile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR)); profile.setAbilityMode(ability, true); @@ -471,4 +474,42 @@ 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)) { + otherPlayer.sendMessage(message); + } + } + } + + /** + * Check if a skill level is higher than the max bonus level of the ability. + * + * @param skillLevel Skill level to check + * @param maxLevel Max level of the ability + * @return whichever value is lower + */ + public static int skillCheck(int skillLevel, int maxLevel) { + //TODO: Could we just use Math.min(skillLevel, maxLevel) here? + if (skillLevel > maxLevel) { + return maxLevel; + } + + return skillLevel; + } } 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 c29bc8ece..6fc07d39f 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java @@ -15,6 +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.SkillType; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -132,7 +133,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 = Misc.calculateActivationChance(Permissions.luckyWoodcutting(player)); + int activationChance = SkillTools.calculateActivationChance(Permissions.luckyWoodcutting(player)); if (probability > configDoubleDropChance) { probability = (int) configDoubleDropChance; diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 4d2e3ddcc..eca640cdb 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -33,9 +33,6 @@ public final class Misc { public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5; public static final int TIME_CONVERSION_FACTOR = 1000; public static final double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0; - public static final int NORMAL_SKILL_ACTIVATION_CHANCE = 100; - public static final int LUCKY_SKILL_ACTIVATION_CHANCE = 75; - //Sound Pitches & Volumes from CB public static final float ANVIL_USE_PITCH = 0.3F; // Not in CB directly, I went off the place sound values public static final float ANVIL_USE_VOLUME = 1.0F; // Not in CB directly, I went off the place sound values @@ -46,20 +43,6 @@ public final class Misc { private Misc() {}; - /** - * 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 boolean isFriendlyPet(Player attacker, Tameable pet) { if (pet.isTamed()) { AnimalTamer tamer = pet.getOwner(); @@ -92,14 +75,6 @@ public final class Misc { return false; } - 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)) { - otherPlayer.sendMessage(message); - } - } - } - /** * Checks to see if an entity is currently invincible. * @@ -269,22 +244,6 @@ public final class Misc { newItem.setItemStack(cloned); } - /** - * Check if a skill level is higher than the max bonus level of the ability. - * - * @param skillLevel Skill level to check - * @param maxLevel Max level of the ability - * @return whichever value is lower - */ - public static int skillCheck(int skillLevel, int maxLevel) { - //TODO: Could we just use Math.min(skillLevel, maxLevel) here? - if (skillLevel > maxLevel) { - return maxLevel; - } - - return skillLevel; - } - /** * Get the max power level for a player. *