本文整理汇总了Java中net.dmulloy2.util.Util.random方法的典型用法代码示例。如果您正苦于以下问题:Java Util.random方法的具体用法?Java Util.random怎么用?Java Util.random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.dmulloy2.util.Util
的用法示例。
在下文中一共展示了Util.random方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onEntityDamageLowest
import net.dmulloy2.util.Util; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDamageLowest(EntityDamageEvent event)
{
if (event.isCancelled() || event.getDamage() <= 0 || ! gracefulRollEnabled)
return;
if (event.getCause() != DamageCause.FALL)
return;
Entity entity = event.getEntity();
if (plugin.isDisabledWorld(entity))
return;
if (entity instanceof Player)
{
if (Util.random(gracefulRollOdds) == 0)
{
event.setDamage(0);
Player player = (Player) entity;
player.sendMessage(plugin.getPrefix() + FormatUtil.format(plugin.getMessage("graceful_roll")));
}
}
}
示例2: onEntityDeath
import net.dmulloy2.util.Util; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDeath(EntityDeathEvent event)
{
Entity killer = event.getEntity().getKiller();
if (killer instanceof Player)
{
Player player = (Player) killer;
double health = player.getHealth();
double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
if (health > 0.0D && health < maxHealth)
{
PlayerData data = plugin.getPlayerDataCache().getData(player);
int level = data.getLevel(25);
if (Util.random(75 / level) == 0)
{
player.setHealth(Math.min(health + 1.0D, maxHealth));
double heartsStolen = (player.getHealth() - health) / 2;
player.sendMessage(plugin.getPrefix() + FormatUtil.format(plugin.getMessage("life_steal"),
heartsStolen, getName(event.getEntity())));
}
}
}
}
示例3: onPlayerToggleSprint
import net.dmulloy2.util.Util; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerToggleSprint(PlayerToggleSprintEvent event)
{
if (! speedBoostEnabled || event.isCancelled())
return;
Player player = event.getPlayer();
if (plugin.isDisabledWorld(player))
return;
if (! player.isSprinting() || player.getGameMode() != GameMode.SURVIVAL)
return;
if (plugin.isSwornNationsEnabled() && plugin.getSwornNationsHandler().isApplicable(player, false))
return;
if (Util.random(speedBoostOdds) == 0)
{
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, speedBoostDuration, speedBoostStrength));
player.sendMessage(plugin.getPrefix() + FormatUtil.format(plugin.getMessage("speed_boost")));
}
}
示例4: run
import net.dmulloy2.util.Util; //导入方法依赖的package包/类
@Override
public void run()
{
if (! Config.hourlyRewardsEnabled)
{
getServer().getScheduler().cancelTask(rewardTask);
return;
}
String message = getMessage("hourly_reward");
String serverName = Config.serverName;
for (Player player : Util.getOnlinePlayers())
{
List<String> rewards = Config.hourlyRewards;
if (! rewards.isEmpty())
{
int rand = Util.random(rewards.size());
String entry = rewards.get(rand);
if (entry != null)
{
String[] split = entry.split(";");
String command = replacePlayerVars(split[0], player);
getServer().dispatchCommand(getServer().getConsoleSender(), command);
player.sendMessage(FormatUtil.format(message, serverName, split[1]));
}
}
}
}
示例5: onEntityDamageByEntity
import net.dmulloy2.util.Util; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
if (event.isCancelled() || event.getDamage() <= 0 || ! instaKillEnabled)
return;
Entity damaged = event.getEntity();
if (plugin.isDisabledWorld(damaged))
return;
if (! (damaged instanceof Player))
{
Entity damager = event.getDamager();
if (damager instanceof Player)
{
Player player = (Player) damager;
if (player.getGameMode() == GameMode.CREATIVE)
return;
if (damaged instanceof LivingEntity)
{
LivingEntity lentity = (LivingEntity) damaged;
if (lentity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() < 100.0D)
{
if (Util.random(instaKillOdds) == 0)
{
lentity.setHealth(0.0D);
player.sendMessage(plugin.getPrefix() + FormatUtil.format(plugin.getMessage("insta_kill")));
}
}
}
}
}
}
示例6: randomElement
import net.dmulloy2.util.Util; //导入方法依赖的package包/类
private static <E> E randomElement(E[] elements)
{
return elements[Util.random(elements.length)];
}
示例7: onBlockPlace
import net.dmulloy2.util.Util; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event)
{
final Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE)
return;
Block block = event.getBlock();
if (plugin.isDisabledWorld(block))
return;
Material material = block.getType();
if (! material.isBlock() || redemptionBlacklist.contains(material))
return;
PlayerData data = plugin.getPlayerDataCache().getData(player);
int chance = universalChance != -1 ? universalChance : 300 / data.getLevel(100);
if (Util.random(chance) == 0)
{
final ItemStack itemStack = new ItemStack(material);
MaterialData materialData = block.getState().getData();
if (materialData != null)
itemStack.setData(materialData);
class DelayedGiveTask extends BukkitRunnable
{
@Override
public void run()
{
InventoryUtil.giveItem(player, itemStack);
String itemName = MaterialUtil.getName(itemStack);
player.sendMessage(plugin.getPrefix() + FormatUtil.format(plugin.getMessage("building_redeem"), itemName));
}
}
// Run the next tick to hopefully fix duplication
new DelayedGiveTask().runTaskLater(plugin, 20L);
}
}
示例8: onEntityTame
import net.dmulloy2.util.Util; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityTame(EntityTameEvent event)
{
AnimalTamer owner = event.getOwner();
if (owner instanceof Player)
{
Player player = (Player) owner;
if (! plugin.isDisabledWorld(player))
{
// XP Gain
String mobname = FormatUtil.getFriendlyName(event.getEntity().getType());
String article = FormatUtil.getArticle(mobname);
String message = plugin.getPrefix() +
FormatUtil.format(plugin.getMessage("taming_gain"), xpGain, article, mobname);
plugin.getExperienceHandler().handleXpGain(player, xpGain, message);
// Wolf/Ocelot's Pal
PlayerData data = plugin.getPlayerDataCache().getData(player);
int level = data.getLevel(50);
if (Util.random(150 / level) == 0)
{
if (event.getEntity() instanceof Wolf)
{
Wolf wolf = (Wolf) player.getLocation().getWorld().spawnEntity(player.getLocation(), EntityType.WOLF);
wolf.setOwner(player);
}
else if (event.getEntity() instanceof Ocelot)
{
Ocelot ocelot = (Ocelot) player.getLocation().getWorld().spawnEntity(player.getLocation(), EntityType.OCELOT);
ocelot.setOwner(player);
}
}
// Taming Bomb!
if (Util.random(150 / level) == 0)
{
boolean sendMessage = false;
List<Entity> entities = player.getNearbyEntities(10, 10, 10);
if (entities.size() > 0)
{
for (Entity entity : entities)
{
if (entity != null && entity instanceof Tameable)
{
Tameable tameable = (Tameable) entity;
if (! tameable.isTamed())
{
tameable.setOwner(player);
sendMessage = true;
}
}
}
}
if (sendMessage)
{
player.sendMessage(plugin.getPrefix() + FormatUtil.format(plugin.getMessage("tame_bomb")));
}
}
}
}
}
示例9: tick
import net.dmulloy2.util.Util; //导入方法依赖的package包/类
public void tick()
{
this.duration -= 1;
if (duration < 0)
{
plugin.removeEffect(this);
return;
}
double yRad = radius;
if (type.equals(Effect.MOBSPAWNER_FLAMES))
{
yRad = 0.75D;
for (Player player : Util.getOnlinePlayers())
{
if (player.getWorld().getUID() == location.getWorld().getUID())
{
if (location.distance(player.getLocation()) < radius)
{
player.setFireTicks(20);
}
}
}
}
for (double i = -radius; i <= radius; i += 1.0D)
{
for (double ii = -radius; ii <= radius; ii += 1.0D)
{
for (double iii = 0.0D; iii <= yRad * 2.0D; iii += 1.0D)
{
int rand = Util.random(8);
if (rand == 2)
{
Location newloc = location.clone().add(i, iii - 1.0D, ii);
Location testLoc = location.clone().add(0.0D, yRad - 1.0D, 0.0D);
if (newloc.distance(testLoc) <= radius)
{
byte dat = (byte) Util.random(8);
if (specialDat > -1)
dat = specialDat;
newloc.getWorld().playEffect(newloc, type, dat);
}
}
}
}
}
}