Because we don't need that many Random objects.

This commit is contained in:
gmcferrin 2013-01-09 23:46:35 -05:00
parent e036b7ac70
commit c1463c3257
24 changed files with 52 additions and 118 deletions

View File

@ -1,12 +1,9 @@
package com.gmail.nossr50.skills.acrobatics; package com.gmail.nossr50.skills.acrobatics;
import java.util.Random;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
public class Acrobatics { public class Acrobatics {
private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); 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_CHANCE = advancedConfig.getDodgeChanceMax();
public static final int DODGE_MAX_BONUS_LEVEL = advancedConfig.getDodgeMaxBonusLevel(); 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 ROLL_XP_MODIFIER = advancedConfig.getRollXPModifier();
public static final int FALL_XP_MODIFIER = advancedConfig.getFallXPModifier(); public static final int FALL_XP_MODIFIER = advancedConfig.getFallXPModifier();
protected static Random getRandom() {
return random;
}
} }

View File

@ -53,7 +53,7 @@ public class AcrobaticsManager {
chance = ((float) Acrobatics.ROLL_MAX_CHANCE / Acrobatics.ROLL_MAX_BONUS_LEVEL) * eventHandler.skillModifier; 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.modifyEventDamage();
eventHandler.sendAbilityMessage(); eventHandler.sendAbilityMessage();
eventHandler.processXPGain(eventHandler.damage * Acrobatics.ROLL_XP_MODIFIER); 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; 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.modifyEventDamage();
eventHandler.sendAbilityMessage(); eventHandler.sendAbilityMessage();
eventHandler.processXPGain(eventHandler.damage * Acrobatics.DODGE_XP_MODIFIER); eventHandler.processXPGain(eventHandler.damage * Acrobatics.DODGE_XP_MODIFIER);

View File

@ -3,7 +3,6 @@ package com.gmail.nossr50.skills.archery;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -14,7 +13,6 @@ import com.gmail.nossr50.util.Misc;
public class Archery { public class Archery {
private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
private static Random random = new Random();
private static List<TrackedEntity> trackedEntities = new ArrayList<TrackedEntity>(); private static List<TrackedEntity> trackedEntities = new ArrayList<TrackedEntity>();
public static final int ARROW_TRACKING_MAX_BONUS_LEVEL = advancedConfig.getRetrieveMaxBonusLevel(); public static final int ARROW_TRACKING_MAX_BONUS_LEVEL = advancedConfig.getRetrieveMaxBonusLevel();
@ -66,8 +64,4 @@ public class Archery {
} }
} }
} }
protected static Random getRandom() {
return random;
}
} }

View File

@ -40,7 +40,7 @@ public class ArcheryManager {
float chance = ((float) Archery.ARROW_TRACKING_MAX_BONUS / Archery.ARROW_TRACKING_MAX_BONUS_LEVEL) * eventHandler.skillModifier; 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(); eventHandler.addToTracker();
} }
} }
@ -65,7 +65,7 @@ public class ArcheryManager {
float chance = ((float) Archery.DAZE_MAX_BONUS / Archery.DAZE_MAX_BONUS_LEVEL) * eventHandler.skillModifier; 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.handleDazeEffect();
eventHandler.sendAbilityMessages(); eventHandler.sendAbilityMessages();
} }

View File

@ -31,7 +31,7 @@ public class DazeEventHandler {
protected void handleDazeEffect() { protected void handleDazeEffect() {
Location location = defender.getLocation(); Location location = defender.getLocation();
if (Archery.getRandom().nextInt(100) > DAZE_CHANCE) { if (Misc.getRandom().nextInt(100) > DAZE_CHANCE) {
location.setPitch(90); location.setPitch(90);
} }
else { else {

View File

@ -1,7 +1,5 @@
package com.gmail.nossr50.skills.combat; package com.gmail.nossr50.skills.combat;
import java.util.Random;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -24,8 +22,6 @@ import com.gmail.nossr50.util.Users;
public class Axes { public class Axes {
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
private static Random random = new Random();
/** /**
* Apply bonus to damage done by axes. * Apply bonus to damage done by axes.
* *
@ -95,7 +91,7 @@ public class Axes {
randomChance = (int) (randomChance * 0.75); randomChance = (int) (randomChance * 0.75);
} }
if (chance > random.nextInt(randomChance) && !entity.isDead()) { if (chance > Misc.getRandom().nextInt(randomChance) && !entity.isDead()) {
int damage = event.getDamage(); int damage = event.getDamage();
if (entity instanceof Player) { if (entity instanceof Player) {
@ -145,7 +141,7 @@ public class Axes {
for (int i = 0; i <= durabilityDamage; i ++) { for (int i = 0; i <= durabilityDamage; i ++) {
if (armor.containsEnchantment(Enchantment.DURABILITY)) { if (armor.containsEnchantment(Enchantment.DURABILITY)) {
int level = armor.getEnchantmentLevel(Enchantment.DURABILITY); int level = armor.getEnchantmentLevel(Enchantment.DURABILITY);
if (random.nextInt(level + 1) > 0) { if (Misc.getRandom().nextInt(level + 1) > 0) {
lowerdamage++; lowerdamage++;
} }
} }
@ -189,7 +185,7 @@ public class Axes {
randomChance = (int) (randomChance * 0.75); 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); event.setDamage(event.getDamage() + GREATER_IMPACT_DAMAGE);
target.setVelocity(attacker.getLocation().getDirection().normalize().multiply(GREATER_IMPACT_MULTIPLIER)); target.setVelocity(attacker.getLocation().getDirection().normalize().multiply(GREATER_IMPACT_MULTIPLIER));
attacker.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc")); attacker.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));

View File

@ -2,7 +2,6 @@ package com.gmail.nossr50.skills.gathering;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -29,8 +28,6 @@ import com.gmail.nossr50.util.Users;
public class Excavation { public class Excavation {
private static Random random = new Random();
/** /**
* Check to see if treasures were found. * Check to see if treasures were found.
* *
@ -103,7 +100,7 @@ public class Excavation {
randomChance = (int) (randomChance * 0.75); randomChance = (int) (randomChance * 0.75);
} }
if (random.nextDouble() * randomChance <= treasure.getDropChance()) { if (Misc.getRandom().nextDouble() * randomChance <= treasure.getDropChance()) {
xp += treasure.getXp(); xp += treasure.getXp();
is.add(treasure.getDrop()); is.add(treasure.getDrop());
} }

View File

@ -3,7 +3,6 @@ package com.gmail.nossr50.skills.gathering;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -38,8 +37,6 @@ import com.gmail.nossr50.util.Skills;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class Fishing { public class Fishing {
private static Random random = new Random();
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
/** /**
@ -112,7 +109,7 @@ public class Fishing {
if (Config.getInstance().getFishingDropsEnabled() && rewards.size() > 0 if (Config.getInstance().getFishingDropsEnabled() && rewards.size() > 0
&& Permissions.fishingTreasures(player)) { && Permissions.fishingTreasures(player)) {
FishingTreasure treasure; FishingTreasure treasure;
treasure = rewards.get(random.nextInt(rewards.size())); treasure = rewards.get(Misc.getRandom().nextInt(rewards.size()));
int randomChance = 100; int randomChance = 100;
@ -120,7 +117,7 @@ public class Fishing {
randomChance = (int) (randomChance * 0.75); 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()); Users.getPlayer(player).addXP(SkillType.FISHING,treasure.getXp());
theCatch.setItemStack(treasure.getDrop()); theCatch.setItemStack(treasure.getDrop());
} }
@ -131,7 +128,7 @@ public class Fishing {
short maxDurability = theCatch.getItemStack().getType().getMaxDurability(); short maxDurability = theCatch.getItemStack().getType().getMaxDurability();
if (maxDurability > 0) { 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()); Skills.xpProcessing(player, profile, SkillType.FISHING, Config.getInstance().getFishingBaseXP());
@ -167,7 +164,7 @@ public class Fishing {
randomChance = (int) (randomChance * 0.75); randomChance = (int) (randomChance * 0.75);
} }
if (random.nextInt(randomChance) <= ENCHANTMENT_CHANCE if (Misc.getRandom().nextInt(randomChance) <= ENCHANTMENT_CHANCE
&& Permissions.fishingMagic(player)) { && Permissions.fishingMagic(player)) {
for (Enchantment newEnchant : Enchantment.values()) { for (Enchantment newEnchant : Enchantment.values()) {
if (newEnchant.canEnchantItem(fishingResults)) { if (newEnchant.canEnchantItem(fishingResults)) {
@ -182,9 +179,9 @@ public class Fishing {
* Actual chance to have an enchantment is related * Actual chance to have an enchantment is related
* to your fishing skill * to your fishing skill
*/ */
if (random.nextInt(15) < Fishing.getFishingLootTier(profile)) { if (Misc.getRandom().nextInt(15) < Fishing.getFishingLootTier(profile)) {
enchanted = true; enchanted = true;
int randomEnchantLevel = random.nextInt(newEnchant.getMaxLevel()) + 1; int randomEnchantLevel = Misc.getRandom().nextInt(newEnchant.getMaxLevel()) + 1;
if (randomEnchantLevel < newEnchant.getStartLevel()) { if (randomEnchantLevel < newEnchant.getStartLevel()) {
randomEnchantLevel = newEnchant.getStartLevel(); randomEnchantLevel = newEnchant.getStartLevel();
@ -230,8 +227,8 @@ public class Fishing {
dropChance = (int) (dropChance * 1.25); dropChance = (int) (dropChance * 1.25);
} }
final int DROP_CHANCE = random.nextInt(100); final int DROP_CHANCE = Misc.getRandom().nextInt(100);
final int DROP_NUMBER = random.nextInt(randomChance) + 1; final int DROP_NUMBER = Misc.getRandom().nextInt(randomChance) + 1;
LivingEntity le = (LivingEntity) event.getCaught(); LivingEntity le = (LivingEntity) event.getCaught();
EntityType type = le.getType(); EntityType type = le.getType();
@ -341,7 +338,7 @@ public class Fishing {
wool.setColor(sheep.getColor()); wool.setColor(sheep.getColor());
final ItemStack theWool = wool.toItemStack(); final ItemStack theWool = wool.toItemStack();
theWool.setAmount(1 + random.nextInt(6)); theWool.setAmount(1 + Misc.getRandom().nextInt(6));
Misc.dropItem(location, theWool); Misc.dropItem(location, theWool);
sheep.setSheared(true); sheep.setSheared(true);
@ -404,7 +401,7 @@ public class Fishing {
break; break;
case WITCH: 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 > 95) {
if (DROP_NUMBER_2 > 66) { if (DROP_NUMBER_2 > 66) {
Misc.dropItem(location, new Potion(PotionType.INSTANT_HEAL).toItemStack(1)); Misc.dropItem(location, new Potion(PotionType.INSTANT_HEAL).toItemStack(1));

View File

@ -1,7 +1,5 @@
package com.gmail.nossr50.skills.gathering; package com.gmail.nossr50.skills.gathering;
import java.util.Random;
import org.bukkit.CropState; import org.bukkit.CropState;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -30,8 +28,6 @@ import com.gmail.nossr50.util.Skills;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class Herbalism { public class Herbalism {
private static Random random = new Random();
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
/** /**
@ -129,7 +125,7 @@ public class Herbalism {
if (b.getType().equals(Material.CACTUS)) { if (b.getType().equals(Material.CACTUS)) {
mat = Material.CACTUS; mat = Material.CACTUS;
if (!mcMMO.placeStore.isTrue(b)) { if (!mcMMO.placeStore.isTrue(b)) {
if (chance > random.nextInt(randomChance)) { if (chance > Misc.getRandom().nextInt(randomChance)) {
catciDrops++; catciDrops++;
} }
xp += Config.getInstance().getHerbalismXPCactus(); xp += Config.getInstance().getHerbalismXPCactus();
@ -189,7 +185,7 @@ public class Herbalism {
if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) { if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) {
mat = Material.SUGAR_CANE; mat = Material.SUGAR_CANE;
if (!mcMMO.placeStore.isTrue(b)) { if (!mcMMO.placeStore.isTrue(b)) {
if (chance > random.nextInt(randomChance)) { if (chance > Misc.getRandom().nextInt(randomChance)) {
caneDrops++; caneDrops++;
} }
xp += Config.getInstance().getHerbalismXPSugarCane(); 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(); Config configInstance = Config.getInstance();
switch (type) { switch (type) {
@ -456,7 +452,7 @@ public class Herbalism {
float chance = (float) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * herbLevel); float chance = (float) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * herbLevel);
if (chance > MAX_CHANCE) chance = (float) MAX_CHANCE; 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); event.setCancelled(true);
switch(type) { switch(type) {
@ -526,7 +522,7 @@ public class Herbalism {
float chance = (float) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * skillLevel); float chance = (float) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * skillLevel);
if (chance > MAX_CHANCE) chance = (float) MAX_CHANCE; if (chance > MAX_CHANCE) chance = (float) MAX_CHANCE;
if (chance > random.nextInt(randomChance)) { if (chance > Misc.getRandom().nextInt(randomChance)) {
greenTerraConvert(player, block); greenTerraConvert(player, block);
} }
else { else {

View File

@ -1,7 +1,6 @@
package com.gmail.nossr50.skills.gathering; package com.gmail.nossr50.skills.gathering;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -35,7 +34,6 @@ import com.gmail.nossr50.util.Users;
public class WoodCutting { public class WoodCutting {
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
private static Random random = new Random();
/** /**
* Handle the Tree Feller ability. * Handle the Tree Feller ability.
@ -82,7 +80,7 @@ public class WoodCutting {
int health = player.getHealth(); int health = player.getHealth();
if (health >= 2) { if (health >= 2) {
Combat.dealDamage(player, random.nextInt(health - 1)); Combat.dealDamage(player, Misc.getRandom().nextInt(health - 1));
} }
inHand.setDurability(inHand.getType().getMaxDurability()); inHand.setDurability(inHand.getType().getMaxDurability());
return; return;
@ -94,7 +92,7 @@ public class WoodCutting {
int health = player.getHealth(); int health = player.getHealth();
if (health >= 2) { if (health >= 2) {
Combat.dealDamage(player, random.nextInt(health - 1)); Combat.dealDamage(player, Misc.getRandom().nextInt(health - 1));
} }
inHand.setDurability(inHand.getType().getMaxDurability()); inHand.setDurability(inHand.getType().getMaxDurability());
return; return;
@ -361,7 +359,7 @@ public class WoodCutting {
randomChance = (int) (randomChance * 0.75); 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(); Config configInstance = Config.getInstance();
ItemStack item; ItemStack item;
Location location; Location location;
@ -503,7 +501,7 @@ public class WoodCutting {
private static int durabilityLossCalulate(ArrayList<Block> toBeFelled, int level) { private static int durabilityLossCalulate(ArrayList<Block> toBeFelled, int level) {
int durabilityLoss = 0; int durabilityLoss = 0;
for (Block x : toBeFelled) { 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))) { else if (x.getType().equals(Material.LOG) || (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(x))) {
durabilityLoss = durabilityLoss + Config.getInstance().getAbilityToolDamage(); durabilityLoss = durabilityLoss + Config.getInstance().getAbilityToolDamage();
} }

View File

@ -1,12 +1,9 @@
package com.gmail.nossr50.skills.mining; package com.gmail.nossr50.skills.mining;
import java.util.Random;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
public class BlastMining { public class BlastMining {
private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); 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_1 = advancedConfig.getBlastMiningRank1();
public final static int BLAST_MINING_RANK_2 = advancedConfig.getBlastMiningRank2(); 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 BLAST_MINING_RANK_8 = advancedConfig.getBlastMiningRank8();
public final static int MAXIMUM_REMOTE_DETONATION_DISTANCE = 100; public final static int MAXIMUM_REMOTE_DETONATION_DISTANCE = 100;
protected static Random getRandom() {
return random;
}
} }

View File

@ -62,7 +62,7 @@ public class BlastMiningDropEventHandler {
Location location = block.getLocation(); Location location = block.getLocation();
Material type = block.getType(); Material type = block.getType();
if (BlastMining.getRandom().nextFloat() < (yield + oreBonus)) { if (Misc.getRandom().nextFloat() < (yield + oreBonus)) {
droppedOres.add(block); droppedOres.add(block);
Mining.miningDrops(block, location, type); Mining.miningDrops(block, location, type);
@ -82,7 +82,7 @@ public class BlastMiningDropEventHandler {
Location location = block.getLocation(); Location location = block.getLocation();
Material type = block.getType(); Material type = block.getType();
if (BlastMining.getRandom().nextFloat() < debrisYield) { if (Misc.getRandom().nextFloat() < debrisYield) {
Misc.dropItem(location, new ItemStack(type)); Misc.dropItem(location, new ItemStack(type));
} }
} }

View File

@ -1,7 +1,5 @@
package com.gmail.nossr50.skills.mining; package com.gmail.nossr50.skills.mining;
import java.util.Random;
import org.bukkit.CoalType; import org.bukkit.CoalType;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -23,7 +21,6 @@ import com.gmail.nossr50.util.Skills;
public class Mining { public class Mining {
private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
private static Config config = Config.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_BONUS_LEVEL = advancedConfig.getMiningDoubleDropMaxLevel();
public static final int DOUBLE_DROPS_MAX_CHANCE = advancedConfig.getMiningDoubleDropChance(); public static final int DOUBLE_DROPS_MAX_CHANCE = advancedConfig.getMiningDoubleDropChance();
@ -315,8 +312,4 @@ public class Mining {
break; break;
} }
} }
protected static Random getRandom() {
return random;
}
} }

View File

@ -147,7 +147,7 @@ public class MiningManager {
float chance = ((float) Mining.DOUBLE_DROPS_MAX_CHANCE / Mining.DOUBLE_DROPS_MAX_BONUS_LEVEL) * eventHandler.skillModifier; 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(); eventHandler.processDrops();
} }
} }

View File

@ -2,7 +2,6 @@ package com.gmail.nossr50.skills.repair;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; 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.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Skills; import com.gmail.nossr50.util.Skills;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class Repair { public class Repair {
private static Random random = new Random();
private static Config configInstance = Config.getInstance(); private static Config configInstance = Config.getInstance();
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
@ -121,11 +119,11 @@ public class Repair {
randomChance = (int) (randomChance * 0.75); randomChance = (int) (randomChance * 0.75);
} }
if (random.nextInt(randomChance) <= getEnchantChance(rank)) { if (Misc.getRandom().nextInt(randomChance) <= getEnchantChance(rank)) {
int enchantLevel = enchant.getValue(); int enchantLevel = enchant.getValue();
if (configInstance.getArcaneForgingDowngradeEnabled() && enchantLevel > 1) { if (configInstance.getArcaneForgingDowngradeEnabled() && enchantLevel > 1) {
if (random.nextInt(randomChance) < getDowngradeChance(rank)) { if (Misc.getRandom().nextInt(randomChance) < getDowngradeChance(rank)) {
is.addEnchantment(enchantment, --enchantLevel); is.addEnchantment(enchantment, --enchantLevel);
downgraded = true; downgraded = true;
} }
@ -249,7 +247,7 @@ public class Repair {
if (Permissions.luckyRepair(player)) randomChance = (int) (randomChance * 0.75); 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")); player.sendMessage(LocaleLoader.getString("Repair.Skills.FeltEasy"));
return true; return true;
} }

View File

@ -1,7 +1,5 @@
package com.gmail.nossr50.skills.swords; package com.gmail.nossr50.skills.swords;
import java.util.Random;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
public class Swords { 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_MODIFIER = advancedConfig.getSerratedStrikesModifier();
public static final int SERRATED_STRIKES_BLEED_TICKS = advancedConfig.getSerratedStrikesTicks(); public static final int SERRATED_STRIKES_BLEED_TICKS = advancedConfig.getSerratedStrikesTicks();
private static Random random = new Random();
protected static Random getRandom() {
return random;
}
} }

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.util.Combat; import com.gmail.nossr50.util.Combat;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; 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); 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.BLEED_CHANCE_MAX) chance = Swords.BLEED_CHANCE_MAX;
if (chance > Swords.getRandom().nextInt(randomChance)) { if (chance > Misc.getRandom().nextInt(randomChance)) {
eventHandler.addBleedTicks(); eventHandler.addBleedTicks();
eventHandler.sendAbilityMessages(); 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); 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.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.dealDamage();
eventHandler.sendAbilityMessages(); eventHandler.sendAbilityMessages();
} }

View File

@ -72,7 +72,7 @@ public class CallOfTheWildEventHandler {
((Tameable) entity).setOwner(player); ((Tameable) entity).setOwner(player);
if (type == EntityType.OCELOT) { 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 { else {
entity.setHealth(entity.getMaxHealth()); entity.setHealth(entity.getMaxHealth());

View File

@ -1,7 +1,5 @@
package com.gmail.nossr50.skills.taming; package com.gmail.nossr50.skills.taming;
import java.util.Random;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
public class Taming { 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_ACTIVATION_LEVEL = advancedConfig.getThickFurUnlock();
public static final int THICK_FUR_MODIFIER = advancedConfig.getThickFurModifier(); public static final int THICK_FUR_MODIFIER = advancedConfig.getThickFurModifier();
private static Random random = new Random();
public static Random getRandom() {
return random;
}
} }

View File

@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
@ -48,7 +49,7 @@ public class TamingManager {
randomChance = (int) (randomChance * 0.75); 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); FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf);
eventHandler.modifyHealth(damage); 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); 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.GORE_CHANCE_MAX) chance = Taming.GORE_CHANCE_MAX;
if (chance > Taming.getRandom().nextInt(randomChance)) { if (chance > Misc.getRandom().nextInt(randomChance)) {
eventHandler.modifyEventDamage(); eventHandler.modifyEventDamage();
eventHandler.applyBleed(); eventHandler.applyBleed();
eventHandler.sendAbilityMessage(); eventHandler.sendAbilityMessage();

View File

@ -1,7 +1,5 @@
package com.gmail.nossr50.skills.unarmed; package com.gmail.nossr50.skills.unarmed;
import java.util.Random;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
public class Unarmed { public class Unarmed {
@ -17,11 +15,5 @@ public class Unarmed {
public static final int DISARM_MAX_BONUS_LEVEL = advancedConfig.getDeflectMaxBonusLevel(); 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_CHANCE = advancedConfig.getIronGripChanceMax();
public static final int IRON_GRIP_MAX_BONUS_LEVEL = advancedConfig.getIronGripMaxBonusLevel(); public static final int IRON_GRIP_MAX_BONUS_LEVEL = advancedConfig.getIronGripMaxBonusLevel();
private static Random random = new Random();
protected static Random getRandom() {
return random;
}
} }

View File

@ -5,6 +5,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; 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); 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.DISARM_MAX_CHANCE) chance = Unarmed.DISARM_MAX_CHANCE;
if (chance > Unarmed.getRandom().nextInt(randomChance)) { if (chance > Misc.getRandom().nextInt(randomChance)) {
if (!hasIronGrip(defender)) { if (!hasIronGrip(defender)) {
eventHandler.sendAbilityMessage(); eventHandler.sendAbilityMessage();
eventHandler.handleDisarm(); eventHandler.handleDisarm();
@ -80,7 +81,7 @@ public class UnarmedManager {
float chance = (float) (((double) Unarmed.DEFLECT_MAX_CHANCE / (double) Unarmed.DEFLECT_MAX_BONUS_LEVEL) * skillLevel); 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.DEFLECT_MAX_CHANCE) chance = Unarmed.DEFLECT_MAX_CHANCE;
if (chance > Unarmed.getRandom().nextInt(randomChance)) { if (chance > Misc.getRandom().nextInt(randomChance)) {
eventHandler.cancelEvent(); eventHandler.cancelEvent();
eventHandler.sendAbilityMessage(); 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); 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.IRON_GRIP_MAX_CHANCE) chance = Unarmed.IRON_GRIP_MAX_CHANCE;
if (chance > Unarmed.getRandom().nextInt(randomChance)) { if (chance > Misc.getRandom().nextInt(randomChance)) {
eventHandler.sendAbilityMessages(); eventHandler.sendAbilityMessages();
return true; return true;
} }

View File

@ -308,4 +308,8 @@ public class Misc {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
public static Random getRandom() {
return random;
}
} }

View File

@ -1,7 +1,5 @@
package com.gmail.nossr50.util; package com.gmail.nossr50.util;
import java.util.Random;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -28,8 +26,6 @@ public class Skills {
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
public static int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength(); 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. * 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 (Config.getInstance().getAbilitiesDamageTools()) {
if (inHand.containsEnchantment(Enchantment.DURABILITY)) { if (inHand.containsEnchantment(Enchantment.DURABILITY)) {
int level = inHand.getEnchantmentLevel(Enchantment.DURABILITY); int level = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
if (random.nextInt(level + 1) > 0) { if (Misc.getRandom().nextInt(level + 1) > 0) {
return; return;
} }
} }