Random update. :D

This commit is contained in:
GJ 2012-03-26 11:04:17 -04:00
parent ca2949dcaf
commit 945fb5ed55
14 changed files with 89 additions and 40 deletions

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -17,6 +19,8 @@ import com.gmail.nossr50.events.McMMOItemSpawnEvent;
public class m {
private static Random random = new Random();
/**
* Gets a capitalized version of the target string.
*
@ -224,7 +228,7 @@ public class m {
* @param chance The percentage chance for the item to drop
*/
public static void mcRandomDropItem(Location location, ItemStack is, double chance) {
if (Math.random() * 100 < chance) {
if (random.nextInt(100) < chance) {
mcDropItem(location, is);
}
}

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.skills;
import java.util.Random;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
@ -14,6 +16,8 @@ import com.gmail.nossr50.party.Party;
public class Acrobatics {
private static Random random = new Random();
/**
* Check for fall damage reduction.
*
@ -39,7 +43,7 @@ public class Acrobatics {
acrovar = acrovar * 2;
}
if ((acrovar > MAX_BONUS_LEVEL || Math.random() * 1000 <= acrovar) && mcPermissions.getInstance().roll(player)) {
if ((acrovar > MAX_BONUS_LEVEL || random.nextInt(1000) <= acrovar) && mcPermissions.getInstance().roll(player)) {
int threshold = 7;
if (gracefulRoll) {
@ -103,7 +107,7 @@ public class Acrobatics {
int skillLevel = PPd.getSkillLevel(SkillType.ACROBATICS);
int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (Math.random() * 4000 <= skillCheck && mcPermissions.getInstance().dodge(defender)) {
if (random.nextInt(4000) <= skillCheck && mcPermissions.getInstance().dodge(defender)) {
defender.sendMessage(mcLocale.getString("Acrobatics.Dodge"));
if (System.currentTimeMillis() >= (5000 + PPd.getRespawnATS()) && defender.getHealth() >= 1) {

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.skills;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
@ -17,6 +19,8 @@ import com.gmail.nossr50.party.Party;
public class Archery {
private static Random random = new Random();
/**
* Track arrows fired for later retrieval.
*
@ -32,7 +36,7 @@ public class Archery {
plugin.arrowTracker.put(entity, 0);
}
if (skillLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= skillLevel)) {
if (skillLevel > MAX_BONUS_LEVEL || (random.nextInt(1000) <= skillLevel)) {
plugin.arrowTracker.put(entity, 1);
}
}
@ -55,7 +59,7 @@ public class Archery {
PlayerProfile PPa = Users.getProfile(attacker);
if (Math.random() * 100 <= IGNITION_CHANCE) {
if (random.nextInt(100) <= IGNITION_CHANCE) {
int ignition = 20;
/* Add 20 ticks for every 200 skill levels */
@ -94,14 +98,14 @@ public class Archery {
Location loc = defender.getLocation();
int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (Math.random() * 10 > 5) {
if (random.nextInt(10) > 5) {
loc.setPitch(90);
}
else {
loc.setPitch(-90);
}
if (Math.random() * 2000 <= skillCheck && mcPermissions.getInstance().daze(attacker)) {
if (random.nextInt(2000) <= skillCheck && mcPermissions.getInstance().daze(attacker)) {
defender.teleport(loc);
defender.sendMessage(mcLocale.getString("Combat.TouchedFuzzy"));
attacker.sendMessage(mcLocale.getString("Combat.TargetDazed"));

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.skills;
import java.util.Random;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
@ -18,6 +20,8 @@ import com.gmail.nossr50.party.Party;
public class Axes {
private static Random random = new Random();
/**
* Apply bonus to damage done by axes.
*
@ -72,7 +76,7 @@ public class Axes {
int skillLevel = PPa.getSkillLevel(SkillType.AXES);
int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (Math.random() * 2000 <= skillCheck && !entity.isDead()){
if (random.nextInt(2000) <= skillCheck && !entity.isDead()){
int damage = event.getDamage();
if (entity instanceof Player){
@ -133,7 +137,7 @@ public class Axes {
final int GREATER_IMPACT_CHANCE = 25;
final double GREATER_IMPACT_MULTIPLIER = 1.5;
if (Math.random() * 100 <= GREATER_IMPACT_CHANCE) {
if (random.nextInt(100) <= GREATER_IMPACT_CHANCE) {
event.setDamage(event.getDamage() + 2);
target.setVelocity(attacker.getLocation().getDirection().normalize().multiply(GREATER_IMPACT_MULTIPLIER));
attacker.sendMessage(mcLocale.getString("Axes.GreaterImpactOnEnemy"));

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -25,6 +26,8 @@ import com.gmail.nossr50.locale.mcLocale;
public class BlastMining {
private static Random random = new Random();
/**
* Handler for what blocks drop from the explosion.
*
@ -43,7 +46,7 @@ public class BlastMining {
while (iterator2.hasNext()) {
Block temp = iterator2.next();
if ((float) Math.random() < (yield + oreBonus)) {
if (random.nextFloat() < (yield + oreBonus)) {
blocksDropped.add(temp);
Mining.miningDrops(temp);
@ -66,7 +69,7 @@ public class BlastMining {
while (iterator3.hasNext()) {
Block temp = iterator3.next();
if ((float) Math.random() < (yield - debrisReduction))
if (random.nextFloat() < (yield - debrisReduction))
Mining.miningDrops(temp);
}
}

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.skills;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -25,6 +26,8 @@ import org.getspout.spoutapi.sound.SoundEffect;
public class Excavation {
private static Random random = new Random();
/**
* Check to see if a block can be broken by Giga Drill Breaker.
*
@ -101,7 +104,7 @@ public class Excavation {
for (ExcavationTreasure treasure : treasures) {
if (skillLevel >= treasure.getDropLevel()) {
if (Math.random() * 100 <= treasure.getDropChance()) {
if (random.nextInt(100) <= treasure.getDropChance()) {
xp += treasure.getXp();
is.add(treasure.getDrop());
}

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.skills;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.Material;
@ -29,6 +30,8 @@ import com.gmail.nossr50.locale.mcLocale;
public class Fishing {
private static Random random = new Random();
/**
* Get the player's current fishing loot tier.
*
@ -95,9 +98,9 @@ public class Fishing {
}
if (LoadProperties.fishingDrops) {
FishingTreasure treasure = rewards.get((int) (Math.random() * rewards.size()));
FishingTreasure treasure = rewards.get(random.nextInt(rewards.size()));
if (Math.random() * 100 <= treasure.getDropChance()) {
if (random.nextInt(100) <= treasure.getDropChance()) {
Users.getProfile(player).addXP(SkillType.FISHING, treasure.getXp(), player);
theCatch.setItemStack(treasure.getDrop());
}
@ -106,7 +109,7 @@ public class Fishing {
theCatch.setItemStack(new ItemStack(Material.RAW_FISH));
}
theCatch.getItemStack().setDurability((short) (Math.random() * theCatch.getItemStack().getType().getMaxDurability())); //Change durability to random value
theCatch.getItemStack().setDurability((short) (random.nextInt(theCatch.getItemStack().getType().getMaxDurability()))); //Change durability to random value
m.mcDropItem(player.getLocation(), new ItemStack(Material.RAW_FISH)); //Always drop a fish
PP.addXP(SkillType.FISHING, LoadProperties.mfishing, player);
@ -132,7 +135,7 @@ public class Fishing {
player.sendMessage(mcLocale.getString("Fishing.ItemFound"));
if (ItemChecks.isArmor(fishingResults) || ItemChecks.isTool(fishingResults)) {
if (Math.random() * 100 <= ENCHANTMENT_CHANCE) {
if (random.nextInt(100) <= ENCHANTMENT_CHANCE) {
for (Enchantment newEnchant : Enchantment.values()) {
if (newEnchant.canEnchantItem(fishingResults)) {
Map<Enchantment, Integer> resultEnchantments = fishingResults.getEnchantments();
@ -144,9 +147,9 @@ public class Fishing {
}
/* Actual chance to have an enchantment is related to your fishing skill */
if (Math.random() * 15 < Fishing.getFishingLootTier(PP)) {
if (random.nextInt(15) < Fishing.getFishingLootTier(PP)) {
enchanted = true;
int randomEnchantLevel = (int) (Math.random() * newEnchant.getMaxLevel()) + 1;
int randomEnchantLevel = random.nextInt(newEnchant.getMaxLevel()) + 1;
if (randomEnchantLevel < newEnchant.getStartLevel()) {
randomEnchantLevel = newEnchant.getStartLevel();
@ -171,7 +174,7 @@ public class Fishing {
* @param event The event to modify
*/
public static void shakeMob(PlayerFishEvent event) {
final int DROP_NUMBER = (int) (Math.random() * 101);
final int DROP_NUMBER = random.nextInt(100);
LivingEntity le = (LivingEntity) event.getCaught();
EntityType type = le.getType();
@ -275,7 +278,7 @@ public class Fishing {
wool.setColor(sheep.getColor());
ItemStack theWool = wool.toItemStack();
theWool.setAmount((int)(Math.random() * 6));
theWool.setAmount(1 + random.nextInt(6));
m.mcDropItem(loc, theWool);
sheep.setSheared(true);

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.skills;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.CropState;
import org.bukkit.Location;
@ -22,6 +24,8 @@ import com.gmail.nossr50.runnables.GreenThumbTimer;
public class Herbalism {
private static Random random = new Random();
/**
* Activate the Green Terra ability.
*
@ -137,7 +141,7 @@ public class Herbalism {
if (b.getType().equals(Material.CACTUS)) {
mat = Material.CACTUS;
if (!b.hasMetadata("mcmmoPlacedBlock")) {
if(herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= herbLevel)) {
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
catciDrops++;
}
xp += LoadProperties.mcactus;
@ -193,7 +197,7 @@ public class Herbalism {
if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) {
mat = Material.SUGAR_CANE;
if (!b.hasMetadata("mcmmoPlacedBlock")) {
if(herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= herbLevel)) {
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
caneDrops++;
}
xp += LoadProperties.msugar;
@ -226,7 +230,7 @@ public class Herbalism {
else {
ItemStack is = new ItemStack(mat);
if (herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= herbLevel)) {
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
if (type.equals(Material.CACTUS)) {
m.mcDropItems(loc, is, catciDrops);
}
@ -268,7 +272,7 @@ public class Herbalism {
boolean hasSeeds = inventory.contains(Material.SEEDS);
Location loc = block.getLocation();
if (hasSeeds && PP.getGreenTerraMode() || hasSeeds && (herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1500 <= herbLevel))) {
if (hasSeeds && PP.getGreenTerraMode() || hasSeeds && (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1500) <= herbLevel)) {
event.setCancelled(true);
m.mcDropItem(loc, new ItemStack(Material.WHEAT));
@ -297,7 +301,7 @@ public class Herbalism {
player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
if (skillLevel > MAX_BONUS_LEVEL || Math.random() * 1500 <= skillLevel) {
if (skillLevel > MAX_BONUS_LEVEL || random.nextInt(1500) <= skillLevel) {
greenTerra(player, block);
}
else {

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.skills;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.CoalType;
import org.bukkit.Location;
@ -19,9 +21,9 @@ import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
public class Mining {
public class Mining
{
private static Random random = new Random();
/**
* Drop items from Mining & Blast Mining skills.
@ -165,7 +167,7 @@ public class Mining
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
if ((skillLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= skillLevel)) && mcPermissions.getInstance().miningDoubleDrops(player)) {
if ((skillLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= skillLevel) && mcPermissions.getInstance().miningDoubleDrops(player)) {
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
m.mcDropItem(block.getLocation(), new ItemStack(block.getType()));
}

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.skills;
import java.util.Map;
import java.util.Random;
import java.util.Map.Entry;
import org.bukkit.ChatColor;
@ -24,6 +25,8 @@ import com.gmail.nossr50.locale.mcLocale;
public class Repair {
private static Random random = new Random();
/**
* Handle all the item repair checks.
*
@ -203,11 +206,11 @@ public class Repair {
for (Entry<Enchantment, Integer> enchant : enchants.entrySet()) {
Enchantment enchantment = enchant.getKey();
if (Math.random() * 100 <= getEnchantChance(rank)) {
if (random.nextInt(100) <= getEnchantChance(rank)) {
int enchantLevel = enchant.getValue();
if (LoadProperties.mayDowngradeEnchants && enchantLevel > 1) {
if (Math.random() * 100 <= getDowngradeChance(rank)) {
if (random.nextInt(100) <= getDowngradeChance(rank)) {
is.addEnchantment(enchantment, enchantLevel--);
downgraded = true;
}
@ -412,7 +415,7 @@ public class Repair {
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR);
if ((skillLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= skillLevel)) && mcPermissions.getInstance().repairBonus(player)) {
if ((skillLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= skillLevel) && mcPermissions.getInstance().repairBonus(player)) {
player.sendMessage(mcLocale.getString("Skills.FeltEasy"));
return true;
}

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.skills;
import java.util.Random;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
@ -21,6 +23,8 @@ import com.gmail.nossr50.runnables.mcBleedTimer;
public class Swords {
private static Random random = new Random();
/**
* Check for Bleed effect.
*
@ -52,7 +56,7 @@ public class Swords {
int skillLevel = PPa.getSkillLevel(SkillType.SWORDS);
int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (Math.random() * 1000 <= skillCheck && !entity.isDead()) {
if (random.nextInt(1000) <= skillCheck && !entity.isDead()) {
if (entity instanceof Player) {
Player target = (Player) entity;
int bleedTicks;
@ -98,7 +102,7 @@ public class Swords {
int skillLevel = PPd.getSkillLevel(SkillType.SWORDS);
int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (Math.random() * 2000 <= skillCheck) {
if (random.nextInt(2000) <= skillCheck) {
Combat.dealDamage((LivingEntity) attacker, event.getDamage() / COUNTER_ATTACK_MODIFIER);
defender.sendMessage(mcLocale.getString("Swords.CounterAttacked"));

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.skills;
import java.util.Random;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.AnimalTamer;
@ -28,6 +30,8 @@ import com.gmail.nossr50.runnables.mcBleedTimer;
public class Taming {
private static Random random = new Random();
/**
* Apply the Fast Food Service ability.
*
@ -45,7 +49,7 @@ public class Taming {
if (PPo.getSkillLevel(SkillType.TAMING) >= SKILL_ACTIVATION_LEVEL) {
if (health < maxHealth) {
if (Math.random() * 100 < ACTIVATION_CHANCE) {
if (random.nextInt(100) < ACTIVATION_CHANCE) {
if (health + damage <= maxHealth) {
theWolf.setHealth(health + damage);
}
@ -83,7 +87,7 @@ public class Taming {
public static void gore(PlayerProfile PPo, EntityDamageEvent event, Player master, mcMMO plugin) {
final int GORE_MULTIPLIER = 2;
if (Math.random() * 1000 <= PPo.getSkillLevel(SkillType.TAMING)) {
if (random.nextInt(1000) <= PPo.getSkillLevel(SkillType.TAMING)) {
Entity entity = event.getEntity();
event.setDamage(event.getDamage() * GORE_MULTIPLIER);
@ -245,7 +249,7 @@ public class Taming {
((Tameable) entity).setOwner(player);
if (entity.getType().equals(EntityType.OCELOT)) {
((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + (int) (Math.random() * 3)));
((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + random.nextInt(3)));
}
player.setItemInHand(new ItemStack(summonItem, item.getAmount() - summonAmount));

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.skills;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -14,6 +16,8 @@ import com.gmail.nossr50.locale.mcLocale;
public class Unarmed {
private static Random random = new Random();
/**
* Apply bonus to Unarmed damage.
*
@ -46,7 +50,7 @@ public class Unarmed {
int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (defender.getItemInHand().getType().equals(Material.AIR)) {
if (Math.random() * 3000 <= skillCheck) {
if (random.nextInt(3000) <= skillCheck) {
ItemStack item = defender.getItemInHand();
defender.sendMessage(mcLocale.getString("Skills.Disarmed"));
@ -69,7 +73,7 @@ public class Unarmed {
int skillLevel = Users.getProfile(defender).getSkillLevel(SkillType.UNARMED);
int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (Math.random() * 2000 <= skillCheck && mcPermissions.getInstance().deflect(defender)) {
if (random.nextInt(2000) <= skillCheck && mcPermissions.getInstance().deflect(defender)) {
event.setCancelled(true);
defender.sendMessage(mcLocale.getString("Combat.ArrowDeflect"));
}

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.skills;
import java.util.ArrayList;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.TreeSpecies;
@ -26,6 +27,8 @@ import org.getspout.spoutapi.sound.SoundEffect;
public class WoodCutting {
private static Random random = new Random();
/**
* Handle the Tree Feller ability.
*
@ -69,7 +72,7 @@ public class WoodCutting {
int health = player.getHealth();
if (health >= 2) {
Combat.dealDamage(player, (int)(Math.random() * (health - 1)));
Combat.dealDamage(player, random.nextInt(health - 1));
}
return;
}
@ -249,7 +252,7 @@ public class WoodCutting {
byte type = block.getData();
Material mat = Material.getMaterial(block.getTypeId());
if ((skillLevel > MAX_SKILL_LEVEL || Math.random() * 1000 <= skillLevel) && mcPermissions.getInstance().woodcuttingDoubleDrops(player)) {
if ((skillLevel > MAX_SKILL_LEVEL || random.nextInt(1000) <= skillLevel) && mcPermissions.getInstance().woodcuttingDoubleDrops(player)) {
ItemStack item = new ItemStack(mat, 1, (short) 0, type);
m.mcDropItem(block.getLocation(), item);
}