From c1463c3257e87414841b777e483470edc0101c27 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Wed, 9 Jan 2013 23:46:35 -0500 Subject: [PATCH] Because we don't need that many Random objects. --- .../nossr50/skills/acrobatics/Acrobatics.java | 7 ------ .../skills/acrobatics/AcrobaticsManager.java | 4 ++-- .../gmail/nossr50/skills/archery/Archery.java | 6 ----- .../skills/archery/ArcheryManager.java | 4 ++-- .../skills/archery/DazeEventHandler.java | 2 +- .../com/gmail/nossr50/skills/combat/Axes.java | 10 +++----- .../nossr50/skills/gathering/Excavation.java | 5 +--- .../nossr50/skills/gathering/Fishing.java | 23 ++++++++----------- .../nossr50/skills/gathering/Herbalism.java | 14 ++++------- .../nossr50/skills/gathering/WoodCutting.java | 10 ++++---- .../nossr50/skills/mining/BlastMining.java | 7 ------ .../mining/BlastMiningDropEventHandler.java | 4 ++-- .../gmail/nossr50/skills/mining/Mining.java | 7 ------ .../nossr50/skills/mining/MiningManager.java | 2 +- .../gmail/nossr50/skills/repair/Repair.java | 10 ++++---- .../gmail/nossr50/skills/swords/Swords.java | 8 ------- .../nossr50/skills/swords/SwordsManager.java | 5 ++-- .../taming/CallOfTheWildEventHandler.java | 2 +- .../gmail/nossr50/skills/taming/Taming.java | 8 ------- .../nossr50/skills/taming/TamingManager.java | 5 ++-- .../gmail/nossr50/skills/unarmed/Unarmed.java | 10 +------- .../skills/unarmed/UnarmedManager.java | 7 +++--- .../java/com/gmail/nossr50/util/Misc.java | 4 ++++ .../java/com/gmail/nossr50/util/Skills.java | 6 +---- 24 files changed, 52 insertions(+), 118 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java index d36c49d56..aa0889ddb 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java @@ -1,12 +1,9 @@ package com.gmail.nossr50.skills.acrobatics; -import java.util.Random; - import com.gmail.nossr50.config.AdvancedConfig; public class Acrobatics { private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); - private static Random random = new Random(); public static final int DODGE_MAX_CHANCE = advancedConfig.getDodgeChanceMax(); public static final int DODGE_MAX_BONUS_LEVEL = advancedConfig.getDodgeMaxBonusLevel(); @@ -19,8 +16,4 @@ public class Acrobatics { public static final int ROLL_XP_MODIFIER = advancedConfig.getRollXPModifier(); public static final int FALL_XP_MODIFIER = advancedConfig.getFallXPModifier(); - - protected static Random getRandom() { - return random; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java index 473836f3c..059d4ce57 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java @@ -53,7 +53,7 @@ public class AcrobaticsManager { chance = ((float) Acrobatics.ROLL_MAX_CHANCE / Acrobatics.ROLL_MAX_BONUS_LEVEL) * eventHandler.skillModifier; } - if (chance > Acrobatics.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) { + if (chance > Misc.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) { eventHandler.modifyEventDamage(); eventHandler.sendAbilityMessage(); eventHandler.processXPGain(eventHandler.damage * Acrobatics.ROLL_XP_MODIFIER); @@ -82,7 +82,7 @@ public class AcrobaticsManager { float chance = ((float) Acrobatics.DODGE_MAX_CHANCE / Acrobatics.DODGE_MAX_BONUS_LEVEL) * eventHandler.skillModifier; - if (chance > Acrobatics.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) { + if (chance > Misc.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) { eventHandler.modifyEventDamage(); eventHandler.sendAbilityMessage(); eventHandler.processXPGain(eventHandler.damage * Acrobatics.DODGE_XP_MODIFIER); diff --git a/src/main/java/com/gmail/nossr50/skills/archery/Archery.java b/src/main/java/com/gmail/nossr50/skills/archery/Archery.java index b261731a1..274238419 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/Archery.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/Archery.java @@ -3,7 +3,6 @@ package com.gmail.nossr50.skills.archery; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Random; import org.bukkit.Material; import org.bukkit.entity.LivingEntity; @@ -14,7 +13,6 @@ import com.gmail.nossr50.util.Misc; public class Archery { private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); - private static Random random = new Random(); private static List trackedEntities = new ArrayList(); public static final int ARROW_TRACKING_MAX_BONUS_LEVEL = advancedConfig.getRetrieveMaxBonusLevel(); @@ -66,8 +64,4 @@ public class Archery { } } } - - protected static Random getRandom() { - return random; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java index 2c83e3b48..25da631cf 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java @@ -40,7 +40,7 @@ public class ArcheryManager { float chance = ((float) Archery.ARROW_TRACKING_MAX_BONUS / Archery.ARROW_TRACKING_MAX_BONUS_LEVEL) * eventHandler.skillModifier; - if (chance > Archery.getRandom().nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { eventHandler.addToTracker(); } } @@ -65,7 +65,7 @@ public class ArcheryManager { float chance = ((float) Archery.DAZE_MAX_BONUS / Archery.DAZE_MAX_BONUS_LEVEL) * eventHandler.skillModifier; - if (chance > Archery.getRandom().nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { eventHandler.handleDazeEffect(); eventHandler.sendAbilityMessages(); } 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 b22e6422f..bc1774fdb 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/DazeEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/DazeEventHandler.java @@ -31,7 +31,7 @@ public class DazeEventHandler { protected void handleDazeEffect() { Location location = defender.getLocation(); - if (Archery.getRandom().nextInt(100) > DAZE_CHANCE) { + if (Misc.getRandom().nextInt(100) > DAZE_CHANCE) { location.setPitch(90); } else { diff --git a/src/main/java/com/gmail/nossr50/skills/combat/Axes.java b/src/main/java/com/gmail/nossr50/skills/combat/Axes.java index 625fa8963..f2157fa30 100644 --- a/src/main/java/com/gmail/nossr50/skills/combat/Axes.java +++ b/src/main/java/com/gmail/nossr50/skills/combat/Axes.java @@ -1,7 +1,5 @@ package com.gmail.nossr50.skills.combat; -import java.util.Random; - import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Entity; @@ -24,8 +22,6 @@ import com.gmail.nossr50.util.Users; public class Axes { static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); - private static Random random = new Random(); - /** * Apply bonus to damage done by axes. * @@ -95,7 +91,7 @@ public class Axes { randomChance = (int) (randomChance * 0.75); } - if (chance > random.nextInt(randomChance) && !entity.isDead()) { + if (chance > Misc.getRandom().nextInt(randomChance) && !entity.isDead()) { int damage = event.getDamage(); if (entity instanceof Player) { @@ -145,7 +141,7 @@ public class Axes { for (int i = 0; i <= durabilityDamage; i ++) { if (armor.containsEnchantment(Enchantment.DURABILITY)) { int level = armor.getEnchantmentLevel(Enchantment.DURABILITY); - if (random.nextInt(level + 1) > 0) { + if (Misc.getRandom().nextInt(level + 1) > 0) { lowerdamage++; } } @@ -189,7 +185,7 @@ public class Axes { randomChance = (int) (randomChance * 0.75); } - if (random.nextInt(randomChance) <= GREATER_IMPACT_CHANCE) { + if (Misc.getRandom().nextInt(randomChance) <= GREATER_IMPACT_CHANCE) { event.setDamage(event.getDamage() + GREATER_IMPACT_DAMAGE); target.setVelocity(attacker.getLocation().getDirection().normalize().multiply(GREATER_IMPACT_MULTIPLIER)); attacker.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc")); diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Excavation.java b/src/main/java/com/gmail/nossr50/skills/gathering/Excavation.java index 8c735470f..bc18844ac 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Excavation.java @@ -2,7 +2,6 @@ package com.gmail.nossr50.skills.gathering; import java.util.ArrayList; import java.util.List; -import java.util.Random; import org.bukkit.Location; import org.bukkit.Material; @@ -29,8 +28,6 @@ import com.gmail.nossr50.util.Users; public class Excavation { - private static Random random = new Random(); - /** * Check to see if treasures were found. * @@ -103,7 +100,7 @@ public class Excavation { randomChance = (int) (randomChance * 0.75); } - if (random.nextDouble() * randomChance <= treasure.getDropChance()) { + if (Misc.getRandom().nextDouble() * randomChance <= treasure.getDropChance()) { xp += treasure.getXp(); is.add(treasure.getDrop()); } diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java b/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java index f66eee191..32979b47d 100755 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java @@ -3,7 +3,6 @@ package com.gmail.nossr50.skills.gathering; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Random; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -38,8 +37,6 @@ import com.gmail.nossr50.util.Skills; import com.gmail.nossr50.util.Users; public class Fishing { - - private static Random random = new Random(); static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); /** @@ -112,7 +109,7 @@ public class Fishing { if (Config.getInstance().getFishingDropsEnabled() && rewards.size() > 0 && Permissions.fishingTreasures(player)) { FishingTreasure treasure; - treasure = rewards.get(random.nextInt(rewards.size())); + treasure = rewards.get(Misc.getRandom().nextInt(rewards.size())); int randomChance = 100; @@ -120,7 +117,7 @@ public class Fishing { randomChance = (int) (randomChance * 0.75); } - if (random.nextDouble() * randomChance <= treasure.getDropChance()) { + if (Misc.getRandom().nextDouble() * randomChance <= treasure.getDropChance()) { Users.getPlayer(player).addXP(SkillType.FISHING,treasure.getXp()); theCatch.setItemStack(treasure.getDrop()); } @@ -131,7 +128,7 @@ public class Fishing { short maxDurability = theCatch.getItemStack().getType().getMaxDurability(); if (maxDurability > 0) { - theCatch.getItemStack().setDurability((short) (random.nextInt(maxDurability))); // Change durability to random value + theCatch.getItemStack().setDurability((short) (Misc.getRandom().nextInt(maxDurability))); // Change durability to random value } Skills.xpProcessing(player, profile, SkillType.FISHING, Config.getInstance().getFishingBaseXP()); @@ -167,7 +164,7 @@ public class Fishing { randomChance = (int) (randomChance * 0.75); } - if (random.nextInt(randomChance) <= ENCHANTMENT_CHANCE + if (Misc.getRandom().nextInt(randomChance) <= ENCHANTMENT_CHANCE && Permissions.fishingMagic(player)) { for (Enchantment newEnchant : Enchantment.values()) { if (newEnchant.canEnchantItem(fishingResults)) { @@ -182,9 +179,9 @@ public class Fishing { * Actual chance to have an enchantment is related * to your fishing skill */ - if (random.nextInt(15) < Fishing.getFishingLootTier(profile)) { + if (Misc.getRandom().nextInt(15) < Fishing.getFishingLootTier(profile)) { enchanted = true; - int randomEnchantLevel = random.nextInt(newEnchant.getMaxLevel()) + 1; + int randomEnchantLevel = Misc.getRandom().nextInt(newEnchant.getMaxLevel()) + 1; if (randomEnchantLevel < newEnchant.getStartLevel()) { randomEnchantLevel = newEnchant.getStartLevel(); @@ -230,8 +227,8 @@ public class Fishing { dropChance = (int) (dropChance * 1.25); } - final int DROP_CHANCE = random.nextInt(100); - final int DROP_NUMBER = random.nextInt(randomChance) + 1; + final int DROP_CHANCE = Misc.getRandom().nextInt(100); + final int DROP_NUMBER = Misc.getRandom().nextInt(randomChance) + 1; LivingEntity le = (LivingEntity) event.getCaught(); EntityType type = le.getType(); @@ -341,7 +338,7 @@ public class Fishing { wool.setColor(sheep.getColor()); final ItemStack theWool = wool.toItemStack(); - theWool.setAmount(1 + random.nextInt(6)); + theWool.setAmount(1 + Misc.getRandom().nextInt(6)); Misc.dropItem(location, theWool); sheep.setSheared(true); @@ -404,7 +401,7 @@ public class Fishing { break; case WITCH: - final int DROP_NUMBER_2 = random.nextInt(randomChance) + 1; + final int DROP_NUMBER_2 = Misc.getRandom().nextInt(randomChance) + 1; if (DROP_NUMBER > 95) { if (DROP_NUMBER_2 > 66) { Misc.dropItem(location, new Potion(PotionType.INSTANT_HEAL).toItemStack(1)); diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java index 4a7163194..456ef88a7 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java @@ -1,7 +1,5 @@ package com.gmail.nossr50.skills.gathering; -import java.util.Random; - import org.bukkit.CropState; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -30,8 +28,6 @@ import com.gmail.nossr50.util.Skills; import com.gmail.nossr50.util.Users; public class Herbalism { - - private static Random random = new Random(); static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); /** @@ -129,7 +125,7 @@ public class Herbalism { if (b.getType().equals(Material.CACTUS)) { mat = Material.CACTUS; if (!mcMMO.placeStore.isTrue(b)) { - if (chance > random.nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { catciDrops++; } xp += Config.getInstance().getHerbalismXPCactus(); @@ -189,7 +185,7 @@ public class Herbalism { if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) { mat = Material.SUGAR_CANE; if (!mcMMO.placeStore.isTrue(b)) { - if (chance > random.nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { caneDrops++; } xp += Config.getInstance().getHerbalismXPSugarCane(); @@ -287,7 +283,7 @@ public class Herbalism { } } - if (chance > random.nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { Config configInstance = Config.getInstance(); switch (type) { @@ -456,7 +452,7 @@ public class Herbalism { float chance = (float) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * herbLevel); if (chance > MAX_CHANCE) chance = (float) MAX_CHANCE; - if (hasSeeds && profile.getAbilityMode(AbilityType.GREEN_TERRA) || hasSeeds && (chance > random.nextInt(randomChance))) { + if (hasSeeds && profile.getAbilityMode(AbilityType.GREEN_TERRA) || hasSeeds && (chance > Misc.getRandom().nextInt(randomChance))) { event.setCancelled(true); switch(type) { @@ -526,7 +522,7 @@ public class Herbalism { float chance = (float) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * skillLevel); if (chance > MAX_CHANCE) chance = (float) MAX_CHANCE; - if (chance > random.nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { greenTerraConvert(player, block); } else { diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java b/src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java index 065f2003d..7d3c6a261 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/WoodCutting.java @@ -1,7 +1,6 @@ package com.gmail.nossr50.skills.gathering; import java.util.ArrayList; -import java.util.Random; import org.bukkit.Location; import org.bukkit.Material; @@ -35,7 +34,6 @@ import com.gmail.nossr50.util.Users; public class WoodCutting { static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); - private static Random random = new Random(); /** * Handle the Tree Feller ability. @@ -82,7 +80,7 @@ public class WoodCutting { int health = player.getHealth(); if (health >= 2) { - Combat.dealDamage(player, random.nextInt(health - 1)); + Combat.dealDamage(player, Misc.getRandom().nextInt(health - 1)); } inHand.setDurability(inHand.getType().getMaxDurability()); return; @@ -94,7 +92,7 @@ public class WoodCutting { int health = player.getHealth(); if (health >= 2) { - Combat.dealDamage(player, random.nextInt(health - 1)); + Combat.dealDamage(player, Misc.getRandom().nextInt(health - 1)); } inHand.setDurability(inHand.getType().getMaxDurability()); return; @@ -361,7 +359,7 @@ public class WoodCutting { randomChance = (int) (randomChance * 0.75); } - if (chance > random.nextInt(randomChance) && Permissions.woodcuttingDoubleDrops(player)) { + if (chance > Misc.getRandom().nextInt(randomChance) && Permissions.woodcuttingDoubleDrops(player)) { Config configInstance = Config.getInstance(); ItemStack item; Location location; @@ -503,7 +501,7 @@ public class WoodCutting { private static int durabilityLossCalulate(ArrayList toBeFelled, int level) { int durabilityLoss = 0; for (Block x : toBeFelled) { - if (random.nextInt(level + 1) > 0) {}//Don't add durabilityLoss, because Unbreaking enchantment does it's work. + if (Misc.getRandom().nextInt(level + 1) > 0) {}//Don't add durabilityLoss, because Unbreaking enchantment does it's work. else if (x.getType().equals(Material.LOG) || (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(x))) { durabilityLoss = durabilityLoss + Config.getInstance().getAbilityToolDamage(); } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java b/src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java index 0f6ea5b92..509759622 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java @@ -1,12 +1,9 @@ package com.gmail.nossr50.skills.mining; -import java.util.Random; - import com.gmail.nossr50.config.AdvancedConfig; public class BlastMining { private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); - private static Random random = new Random(); public final static int BLAST_MINING_RANK_1 = advancedConfig.getBlastMiningRank1(); public final static int BLAST_MINING_RANK_2 = advancedConfig.getBlastMiningRank2(); @@ -18,8 +15,4 @@ public class BlastMining { public final static int BLAST_MINING_RANK_8 = advancedConfig.getBlastMiningRank8(); public final static int MAXIMUM_REMOTE_DETONATION_DISTANCE = 100; - - protected static Random getRandom() { - return random; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/BlastMiningDropEventHandler.java b/src/main/java/com/gmail/nossr50/skills/mining/BlastMiningDropEventHandler.java index 19010f8c4..1e315235f 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/BlastMiningDropEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/BlastMiningDropEventHandler.java @@ -62,7 +62,7 @@ public class BlastMiningDropEventHandler { Location location = block.getLocation(); Material type = block.getType(); - if (BlastMining.getRandom().nextFloat() < (yield + oreBonus)) { + if (Misc.getRandom().nextFloat() < (yield + oreBonus)) { droppedOres.add(block); Mining.miningDrops(block, location, type); @@ -82,7 +82,7 @@ public class BlastMiningDropEventHandler { Location location = block.getLocation(); Material type = block.getType(); - if (BlastMining.getRandom().nextFloat() < debrisYield) { + if (Misc.getRandom().nextFloat() < debrisYield) { Misc.dropItem(location, new ItemStack(type)); } } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java index 8f60987a8..67bee7c5e 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java @@ -1,7 +1,5 @@ package com.gmail.nossr50.skills.mining; -import java.util.Random; - import org.bukkit.CoalType; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -23,7 +21,6 @@ import com.gmail.nossr50.util.Skills; public class Mining { private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); private static Config config = Config.getInstance(); - private static Random random = new Random(); public static final int DOUBLE_DROPS_MAX_BONUS_LEVEL = advancedConfig.getMiningDoubleDropMaxLevel(); public static final int DOUBLE_DROPS_MAX_CHANCE = advancedConfig.getMiningDoubleDropChance(); @@ -315,8 +312,4 @@ public class Mining { break; } } - - protected static Random getRandom() { - return random; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index fadecb85c..b674a56a8 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -147,7 +147,7 @@ public class MiningManager { float chance = ((float) Mining.DOUBLE_DROPS_MAX_CHANCE / Mining.DOUBLE_DROPS_MAX_BONUS_LEVEL) * eventHandler.skillModifier; - if (chance > Mining.getRandom().nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { eventHandler.processDrops(); } } 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 992a9baac..510a81dc3 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java @@ -2,7 +2,6 @@ package com.gmail.nossr50.skills.repair; import java.util.Map; import java.util.Map.Entry; -import java.util.Random; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -18,13 +17,12 @@ import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.spout.SpoutSounds; +import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Skills; import com.gmail.nossr50.util.Users; public class Repair { - - private static Random random = new Random(); private static Config configInstance = Config.getInstance(); static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); @@ -121,11 +119,11 @@ public class Repair { randomChance = (int) (randomChance * 0.75); } - if (random.nextInt(randomChance) <= getEnchantChance(rank)) { + if (Misc.getRandom().nextInt(randomChance) <= getEnchantChance(rank)) { int enchantLevel = enchant.getValue(); if (configInstance.getArcaneForgingDowngradeEnabled() && enchantLevel > 1) { - if (random.nextInt(randomChance) < getDowngradeChance(rank)) { + if (Misc.getRandom().nextInt(randomChance) < getDowngradeChance(rank)) { is.addEnchantment(enchantment, --enchantLevel); downgraded = true; } @@ -249,7 +247,7 @@ public class Repair { if (Permissions.luckyRepair(player)) randomChance = (int) (randomChance * 0.75); - if (chance > random.nextInt(randomChance) && Permissions.repairBonus(player)) { + if (chance > Misc.getRandom().nextInt(randomChance) && Permissions.repairBonus(player)) { player.sendMessage(LocaleLoader.getString("Repair.Skills.FeltEasy")); return true; } diff --git a/src/main/java/com/gmail/nossr50/skills/swords/Swords.java b/src/main/java/com/gmail/nossr50/skills/swords/Swords.java index 16afa0d57..bdc8ed068 100644 --- a/src/main/java/com/gmail/nossr50/skills/swords/Swords.java +++ b/src/main/java/com/gmail/nossr50/skills/swords/Swords.java @@ -1,7 +1,5 @@ package com.gmail.nossr50.skills.swords; -import java.util.Random; - import com.gmail.nossr50.config.AdvancedConfig; public class Swords { @@ -18,10 +16,4 @@ public class Swords { public static final int SERRATED_STRIKES_MODIFIER = advancedConfig.getSerratedStrikesModifier(); public static final int SERRATED_STRIKES_BLEED_TICKS = advancedConfig.getSerratedStrikesTicks(); - - private static Random random = new Random(); - - protected static Random getRandom() { - return random; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java index a8e862a4b..62c482c01 100644 --- a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.util.Combat; +import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; @@ -45,7 +46,7 @@ public class SwordsManager { float chance = (float) (((double) Swords.BLEED_CHANCE_MAX / (double) Swords.BLEED_MAX_BONUS_LEVEL) * skillLevel); if (chance > Swords.BLEED_CHANCE_MAX) chance = Swords.BLEED_CHANCE_MAX; - if (chance > Swords.getRandom().nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { eventHandler.addBleedTicks(); eventHandler.sendAbilityMessages(); } @@ -74,7 +75,7 @@ public class SwordsManager { float chance = (float) (((double) Swords.COUNTER_ATTACK_CHANCE_MAX / (double) Swords.COUNTER_ATTACK_MAX_BONUS_LEVEL) * skillLevel); if (chance > Swords.COUNTER_ATTACK_CHANCE_MAX) chance = Swords.COUNTER_ATTACK_CHANCE_MAX; - if (chance > Swords.getRandom().nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { eventHandler.dealDamage(); eventHandler.sendAbilityMessages(); } diff --git a/src/main/java/com/gmail/nossr50/skills/taming/CallOfTheWildEventHandler.java b/src/main/java/com/gmail/nossr50/skills/taming/CallOfTheWildEventHandler.java index 22fb213d1..8eafbfdfb 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/CallOfTheWildEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/CallOfTheWildEventHandler.java @@ -72,7 +72,7 @@ public class CallOfTheWildEventHandler { ((Tameable) entity).setOwner(player); if (type == EntityType.OCELOT) { - ((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + Taming.getRandom().nextInt(3))); + ((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + Misc.getRandom().nextInt(3))); } else { entity.setHealth(entity.getMaxHealth()); diff --git a/src/main/java/com/gmail/nossr50/skills/taming/Taming.java b/src/main/java/com/gmail/nossr50/skills/taming/Taming.java index 13cb89529..8a81d5af5 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/Taming.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/Taming.java @@ -1,7 +1,5 @@ package com.gmail.nossr50.skills.taming; -import java.util.Random; - import com.gmail.nossr50.config.AdvancedConfig; public class Taming { @@ -25,10 +23,4 @@ public class Taming { public static final int THICK_FUR_ACTIVATION_LEVEL = advancedConfig.getThickFurUnlock(); public static final int THICK_FUR_MODIFIER = advancedConfig.getThickFurModifier(); - - private static Random random = new Random(); - - public static Random getRandom() { - return random; - } } diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java index 855be7eb7..7737a14c1 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; @@ -48,7 +49,7 @@ public class TamingManager { randomChance = (int) (randomChance * 0.75); } - if (Taming.getRandom().nextInt(randomChance) < Taming.FAST_FOOD_SERVICE_ACTIVATION_CHANCE) { + if (Misc.getRandom().nextInt(randomChance) < Taming.FAST_FOOD_SERVICE_ACTIVATION_CHANCE) { FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf); eventHandler.modifyHealth(damage); @@ -100,7 +101,7 @@ public class TamingManager { float chance = (float) (((double) Taming.GORE_CHANCE_MAX / (double) Taming.GORE_MAX_BONUS_LEVEL) * skillLevel); if (chance > Taming.GORE_CHANCE_MAX) chance = Taming.GORE_CHANCE_MAX; - if (chance > Taming.getRandom().nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { eventHandler.modifyEventDamage(); eventHandler.applyBleed(); eventHandler.sendAbilityMessage(); diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java b/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java index 69ae2d9ba..f4775801f 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java @@ -1,7 +1,5 @@ package com.gmail.nossr50.skills.unarmed; -import java.util.Random; - import com.gmail.nossr50.config.AdvancedConfig; public class Unarmed { @@ -17,11 +15,5 @@ public class Unarmed { public static final int DISARM_MAX_BONUS_LEVEL = advancedConfig.getDeflectMaxBonusLevel(); public static final int IRON_GRIP_MAX_CHANCE = advancedConfig.getIronGripChanceMax(); - public static final int IRON_GRIP_MAX_BONUS_LEVEL = advancedConfig.getIronGripMaxBonusLevel(); - - private static Random random = new Random(); - - protected static Random getRandom() { - return random; - } + public static final int IRON_GRIP_MAX_BONUS_LEVEL = advancedConfig.getIronGripMaxBonusLevel(); } \ No newline at end of file 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 b254eaf61..37de84145 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java @@ -5,6 +5,7 @@ import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; @@ -46,7 +47,7 @@ public class UnarmedManager { float chance = (float) (((double) Unarmed.DISARM_MAX_CHANCE / (double) Unarmed.DISARM_MAX_BONUS_LEVEL) * skillLevel); if (chance > Unarmed.DISARM_MAX_CHANCE) chance = Unarmed.DISARM_MAX_CHANCE; - if (chance > Unarmed.getRandom().nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { if (!hasIronGrip(defender)) { eventHandler.sendAbilityMessage(); eventHandler.handleDisarm(); @@ -80,7 +81,7 @@ public class UnarmedManager { float chance = (float) (((double) Unarmed.DEFLECT_MAX_CHANCE / (double) Unarmed.DEFLECT_MAX_BONUS_LEVEL) * skillLevel); if (chance > Unarmed.DEFLECT_MAX_CHANCE) chance = Unarmed.DEFLECT_MAX_CHANCE; - if (chance > Unarmed.getRandom().nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { eventHandler.cancelEvent(); eventHandler.sendAbilityMessage(); } @@ -130,7 +131,7 @@ public class UnarmedManager { float chance = (float) (((double) Unarmed.IRON_GRIP_MAX_CHANCE / (double) Unarmed.IRON_GRIP_MAX_BONUS_LEVEL) * skillLevel); if (chance > Unarmed.IRON_GRIP_MAX_CHANCE) chance = Unarmed.IRON_GRIP_MAX_CHANCE; - if (chance > Unarmed.getRandom().nextInt(randomChance)) { + if (chance > Misc.getRandom().nextInt(randomChance)) { eventHandler.sendAbilityMessages(); return true; } diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 31f2aac4a..86984ec0d 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -308,4 +308,8 @@ public class Misc { return Integer.MAX_VALUE; } + + public static Random getRandom() { + return random; + } } diff --git a/src/main/java/com/gmail/nossr50/util/Skills.java b/src/main/java/com/gmail/nossr50/util/Skills.java index 69621adfc..423911c47 100644 --- a/src/main/java/com/gmail/nossr50/util/Skills.java +++ b/src/main/java/com/gmail/nossr50/util/Skills.java @@ -1,7 +1,5 @@ package com.gmail.nossr50.util; -import java.util.Random; - import org.bukkit.ChatColor; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; @@ -28,8 +26,6 @@ public class Skills { static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); public static int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength(); - private final static Random random = new Random(); - /** * Checks to see if the cooldown for an item or ability is expired. * @@ -387,7 +383,7 @@ public class Skills { if (Config.getInstance().getAbilitiesDamageTools()) { if (inHand.containsEnchantment(Enchantment.DURABILITY)) { int level = inHand.getEnchantmentLevel(Enchantment.DURABILITY); - if (random.nextInt(level + 1) > 0) { + if (Misc.getRandom().nextInt(level + 1) > 0) { return; } }