mcMMO/src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java

622 lines
24 KiB
Java
Raw Normal View History

package com.gmail.nossr50.skills.utilities;
2012-01-09 20:00:13 +01:00
import java.util.ArrayList;
import java.util.List;
2013-02-14 22:02:42 +01:00
import org.bukkit.Material;
2012-03-09 07:23:32 +01:00
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
2012-01-09 20:00:13 +01:00
import org.bukkit.entity.Player;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
2013-02-18 16:32:29 +01:00
import org.bukkit.plugin.PluginManager;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
2012-01-09 20:00:13 +01:00
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO;
2012-11-21 21:49:54 +01:00
import com.gmail.nossr50.config.AdvancedConfig;
2012-04-26 16:27:57 +02:00
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig;
2012-01-09 20:00:13 +01:00
import com.gmail.nossr50.datatypes.PlayerProfile;
2012-03-27 07:09:28 +02:00
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
2013-02-18 16:32:29 +01:00
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.locale.LocaleLoader;
2013-01-30 17:35:33 +01:00
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.spout.SpoutConfig;
import com.gmail.nossr50.spout.SpoutTools;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
2013-02-20 16:40:47 +01:00
import com.gmail.nossr50.util.ParticleEffectUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.Users;
2012-01-09 20:00:13 +01:00
2013-01-26 23:01:55 +01:00
public class SkillTools {
public static void handleFoodSkills(Player player, SkillType skill, FoodLevelChangeEvent event, int baseLevel, int maxLevel, int rankChange) {
int skillLevel = Users.getPlayer(player).getProfile().getSkillLevel(skill);
int currentFoodLevel = player.getFoodLevel();
int newFoodLevel = event.getFoodLevel();
int foodChange = newFoodLevel - currentFoodLevel;
for (int i = baseLevel; i <= maxLevel; i+= rankChange) {
if (skillLevel >= i) {
foodChange++;
}
}
event.setFoodLevel(currentFoodLevel + foodChange);
}
2012-03-13 19:09:32 +01:00
/**
* Checks to see if the cooldown for an item or ability is expired.
*
* @param oldTime The time the ability or item was last used
* @param cooldown The amount of time that must pass between uses
* @param player The player whose cooldown is being checked
2012-03-13 19:09:32 +01:00
* @return true if the cooldown is over, false otherwise
*/
2013-01-10 05:03:17 +01:00
public static boolean cooldownOver(long oldTime, int cooldown, Player player) {
2012-03-13 19:09:32 +01:00
long currentTime = System.currentTimeMillis();
int adjustedCooldown = PerksUtils.handleCooldownPerks(player, cooldown);
if (currentTime - oldTime >= (adjustedCooldown * Misc.TIME_CONVERSION_FACTOR)) {
2012-03-13 19:09:32 +01:00
return true;
}
2013-01-10 04:43:21 +01:00
return false;
2012-01-09 20:00:13 +01:00
}
2012-03-13 19:09:32 +01:00
/**
* Calculate the time remaining until the cooldown expires.
*
* @param deactivatedTimeStamp Time of deactivation
* @param cooldown The length of the cooldown
* @return the number of seconds remaining before the cooldown expires
*/
public static int calculateTimeLeft(long deactivatedTimeStamp, int cooldown, Player player) {
return (int) (((deactivatedTimeStamp + (PerksUtils.handleCooldownPerks(player, cooldown) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR);
2012-01-09 20:00:13 +01:00
}
2012-03-13 19:09:32 +01:00
/**
* Sends a message to the player when the cooldown expires.
*
* @param player The player to send a message to
2012-07-03 16:04:04 +02:00
* @param profile The profile of the player
2012-03-13 19:09:32 +01:00
* @param ability The ability to watch cooldowns for
*/
2012-07-03 16:04:04 +02:00
public static void watchCooldown(Player player, PlayerProfile profile, AbilityType ability) {
2013-01-10 05:03:17 +01:00
if (player == null || profile == null || ability == null)
return;
if (!profile.getAbilityInformed(ability) && cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
2012-07-03 16:04:04 +02:00
profile.setAbilityInformed(ability, true);
2012-03-13 19:09:32 +01:00
player.sendMessage(ability.getAbilityRefresh());
}
}
/**
* Process activating abilities & readying the tool.
*
* @param player The player using the ability
* @param skill The skill the ability is tied to
*/
public static void activationCheck(Player player, SkillType skill) {
if (Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && !player.isSneaking()) {
2012-03-13 19:09:32 +01:00
return;
}
PlayerProfile profile = Users.getPlayer(player).getProfile();
2012-03-13 19:09:32 +01:00
AbilityType ability = skill.getAbility();
ToolType tool = skill.getTool();
ItemStack inHand = player.getItemInHand();
if (ModChecks.isCustomTool(inHand) && !ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
return;
}
2012-03-13 19:09:32 +01:00
/* Check if any abilities are active */
if (profile == null) {
return;
}
2012-07-03 16:04:04 +02:00
if (!profile.getAbilityUse()) {
2012-03-13 19:09:32 +01:00
return;
}
for (AbilityType x : AbilityType.values()) {
2012-07-03 16:04:04 +02:00
if (profile.getAbilityMode(x)) {
return;
}
}
2012-03-13 19:09:32 +01:00
/* Woodcutting & Axes need to be treated differently.
* Basically the tool always needs to ready and we check to see if the cooldown is over when the user takes action
*/
2012-07-03 16:04:04 +02:00
if (ability.getPermissions(player) && tool.inHand(inHand) && !profile.getToolPreparationMode(tool)) {
2012-04-05 05:30:56 +02:00
if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) {
if (!profile.getAbilityMode(ability) && !cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Skills.TooTired", calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)));
2012-04-05 05:30:56 +02:00
return;
2012-03-13 19:09:32 +01:00
}
}
if (Config.getInstance().getAbilityMessagesEnabled()) {
2012-03-13 19:09:32 +01:00
player.sendMessage(tool.getRaiseTool());
}
2012-07-03 16:04:04 +02:00
profile.setToolPreparationATS(tool, System.currentTimeMillis());
profile.setToolPreparationMode(tool, true);
2012-03-13 19:09:32 +01:00
}
2012-01-09 20:00:13 +01:00
}
2012-03-13 19:09:32 +01:00
/**
* Monitors various things relating to skill abilities.
*
* @param player The player using the skill
2012-07-03 16:04:04 +02:00
* @param profile The profile of the player
2012-03-13 19:09:32 +01:00
* @param curTime The current system time
* @param skill The skill being monitored
*/
2012-07-03 16:04:04 +02:00
public static void monitorSkill(Player player, PlayerProfile profile, long curTime, SkillType skill) {
2012-03-13 19:09:32 +01:00
final int FOUR_SECONDS = 4000;
ToolType tool = skill.getTool();
AbilityType ability = skill.getAbility();
if (profile == null) {
return;
}
if (profile.getToolPreparationMode(tool) && curTime - (profile.getToolPreparationATS(tool) * Misc.TIME_CONVERSION_FACTOR) >= FOUR_SECONDS) {
2012-07-03 16:04:04 +02:00
profile.setToolPreparationMode(tool, false);
if (Config.getInstance().getAbilityMessagesEnabled()) {
player.sendMessage(tool.getLowerTool());
}
2012-03-13 19:09:32 +01:00
}
if (ability.getPermissions(player)) {
if (profile.getAbilityMode(ability) && (profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR) <= curTime) {
if (ability == AbilityType.BERSERK) {
player.setCanPickupItems(true);
}
else if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) {
handleAbilitySpeedDecrease(player);
}
2012-07-03 16:04:04 +02:00
profile.setAbilityMode(ability, false);
profile.setAbilityInformed(ability, false);
2013-02-20 16:40:47 +01:00
ParticleEffectUtils.playAbilityDisabledEffect(player);
if (profile.useChatNotifications()) {
player.sendMessage(ability.getAbilityOff());
}
2012-03-13 19:09:32 +01:00
sendSkillMessage(player, ability.getAbilityPlayerOff(player));
2012-03-13 19:09:32 +01:00
}
}
2012-01-09 20:00:13 +01:00
}
2012-03-13 19:09:32 +01:00
/**
* Check the XP of a skill.
*
* @param skillType The skill to check
* @param player The player whose skill to check
* @param profile The profile of the player whose skill to check
2012-03-13 19:09:32 +01:00
*/
public static void xpCheckSkill(SkillType skillType, Player player, PlayerProfile profile) {
2012-03-29 04:45:34 +02:00
int skillups = 0;
int xpRemoved = 0;
if (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
while (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Config.getInstance().getPowerLevelCap() >= Users.getPlayer(player).getPowerLevel() + 1)) {
int xp = profile.getXpToLevel(skillType);
xpRemoved += xp;
profile.removeXp(skillType, xp);
2012-03-13 19:09:32 +01:00
skillups++;
profile.skillUp(skillType, 1);
2012-03-13 19:09:32 +01:00
}
else {
profile.addLevels(skillType, 0);
}
2012-03-13 19:09:32 +01:00
}
McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType, skillups);
mcMMO.p.getServer().getPluginManager().callEvent(eventToFire);
if (eventToFire.isCancelled()) {
profile.modifySkill(skillType, profile.getSkillLevel(skillType) - skillups);
profile.setSkillXpLevel(skillType, profile.getSkillXpLevel(skillType) + xpRemoved);
return;
}
String capitalized = StringUtils.getCapitalized(skillType.toString());
2012-03-13 19:09:32 +01:00
/* Spout Stuff */
if (mcMMO.spoutEnabled) {
2012-07-03 16:14:01 +02:00
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
2012-03-13 19:09:32 +01:00
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
SpoutTools.levelUpNotification(skillType, spoutPlayer);
2012-04-03 16:08:37 +02:00
/* Update custom titles */
if (SpoutConfig.getInstance().getShowPowerLevel()) {
2013-02-02 08:55:49 +01:00
spoutPlayer.setTitle(LocaleLoader.getString("Spout.Title", spoutPlayer.getName(), Users.getPlayer(player).getPowerLevel()));
2012-04-03 16:08:37 +02:00
}
2012-03-13 19:09:32 +01:00
}
else {
2013-02-15 19:56:30 +01:00
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", skillups, profile.getSkillLevel(skillType)));
2012-03-13 19:09:32 +01:00
}
}
else {
2013-02-15 19:56:30 +01:00
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", skillups, profile.getSkillLevel(skillType)));
2012-03-13 19:09:32 +01:00
}
}
if (mcMMO.spoutEnabled) {
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
if (SpoutConfig.getInstance().getXPBarEnabled()) {
profile.getSpoutHud().updateXpBar();
2012-03-29 04:45:34 +02:00
}
}
}
2012-01-09 20:00:13 +01:00
}
2012-03-13 19:09:32 +01:00
/**
* Checks if the given string represents a valid skill
*
* @param skillName The name of the skill to check
2012-03-13 19:09:32 +01:00
* @return true if this is a valid skill, false otherwise
*/
public static boolean isSkill(String skillName) {
if (!Config.getInstance().getLocale().equalsIgnoreCase("en_US")) {
return isLocalizedSkill(skillName);
}
if (SkillType.getSkill(skillName) != null) {
2012-03-13 19:09:32 +01:00
return true;
}
2013-01-10 04:43:21 +01:00
return false;
2012-01-09 20:00:13 +01:00
}
2012-03-13 19:09:32 +01:00
private static boolean isLocalizedSkill(String skillName) {
for (SkillType skill : SkillType.values()) {
if (skillName.equalsIgnoreCase(LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".SkillName"))) {
return true;
}
}
return false;
}
public static String getSkillName(SkillType skill) {
if (!Config.getInstance().getLocale().equalsIgnoreCase("en_US")) {
return StringUtils.getCapitalized(LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".SkillName"));
}
return StringUtils.getCapitalized(skill.toString());
2013-01-16 20:03:07 +01:00
}
2012-03-13 19:09:32 +01:00
/**
* Check if the player has any combat skill permissions.
*
* @param player The player to check permissions for
* @return true if the player has combat skills, false otherwise
*/
public static boolean hasCombatSkills(Player player) {
if (Permissions.skillEnabled(player, SkillType.AXES)
|| Permissions.skillEnabled(player, SkillType.ARCHERY)
|| Permissions.skillEnabled(player, SkillType.SWORDS)
|| Permissions.skillEnabled(player, SkillType.TAMING)
|| Permissions.skillEnabled(player, SkillType.UNARMED)) {
2012-03-13 19:09:32 +01:00
return true;
}
2013-01-10 04:43:21 +01:00
return false;
2012-03-13 19:09:32 +01:00
}
/**
* Check if the player has any gathering skill permissions.
*
* @param player The player to check permissions for
* @return true if the player has gathering skills, false otherwise
*/
public static boolean hasGatheringSkills(Player player) {
if (Permissions.skillEnabled(player, SkillType.EXCAVATION)
|| Permissions.skillEnabled(player, SkillType.FISHING)
|| Permissions.skillEnabled(player, SkillType.HERBALISM)
|| Permissions.skillEnabled(player, SkillType.MINING)
|| Permissions.skillEnabled(player, SkillType.WOODCUTTING)) {
2012-03-13 19:09:32 +01:00
return true;
}
2013-01-10 04:43:21 +01:00
return false;
2012-03-13 19:09:32 +01:00
}
/**
* Check if the player has any misc skill permissions.
*
* @param player The player to check permissions for
* @return true if the player has misc skills, false otherwise
*/
public static boolean hasMiscSkills(Player player) {
if (Permissions.skillEnabled(player, SkillType.ACROBATICS)
|| Permissions.skillEnabled(player, SkillType.SMELTING)
|| Permissions.skillEnabled(player, SkillType.REPAIR)) {
2012-03-13 19:09:32 +01:00
return true;
}
2013-01-10 04:43:21 +01:00
return false;
2012-03-13 19:09:32 +01:00
}
/**
* Check to see if an ability can be activated.
2012-03-13 19:09:32 +01:00
*
* @param player The player activating the ability
* @param type The skill the ability is based on
*/
2012-03-13 19:09:32 +01:00
public static void abilityCheck(Player player, SkillType type) {
PlayerProfile profile = Users.getPlayer(player).getProfile();
ToolType tool = type.getTool();
AbilityType ability = type.getAbility();
2012-03-13 19:09:32 +01:00
2012-07-03 16:04:04 +02:00
profile.setToolPreparationMode(tool, false);
2012-03-13 19:09:32 +01:00
2012-06-22 20:20:28 +02:00
/* Axes and Woodcutting are odd because they share the same tool.
* We show them the too tired message when they take action.
*/
if (type == SkillType.WOODCUTTING || type == SkillType.AXES) {
if (!profile.getAbilityMode(ability) && !cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
2013-02-02 08:55:49 +01:00
player.sendMessage(LocaleLoader.getString("Skills.TooTired", calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)));
2012-06-22 20:20:28 +02:00
return;
}
2012-06-22 20:20:28 +02:00
}
2012-07-03 16:04:04 +02:00
if (!profile.getAbilityMode(ability) && cooldownOver(profile.getSkillDATS(ability), ability.getCooldown(), player)) {
int ticks = PerksUtils.handleActivationPerks(player, 2 + (profile.getSkillLevel(type) / AdvancedConfig.getInstance().getAbilityLength()), ability.getMaxTicks());
2012-06-22 20:20:28 +02:00
2013-02-20 16:40:47 +01:00
ParticleEffectUtils.playAbilityEnabledEffect(player);
if (profile.useChatNotifications()) {
player.sendMessage(ability.getAbilityOn());
}
SkillTools.sendSkillMessage(player, ability.getAbilityPlayer(player));
2012-06-22 20:20:28 +02:00
profile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
2012-07-03 16:04:04 +02:00
profile.setAbilityMode(ability, true);
if (ability == AbilityType.BERSERK) {
player.setCanPickupItems(false);
}
else if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) {
handleAbilitySpeedIncrease(player);
}
2012-03-13 19:09:32 +01:00
}
}
2012-03-13 19:09:32 +01:00
/**
* Check to see if ability should be triggered.
*
* @param player The player using the ability
* @param block The block modified by the ability
* @param ability The ability to check
* @return true if the ability should activate, false otherwise
*/
2012-03-09 07:23:32 +01:00
public static boolean triggerCheck(Player player, Block block, AbilityType ability) {
2012-03-13 19:09:32 +01:00
boolean activate = true;
switch (ability) {
case BERSERK:
case LEAF_BLOWER:
if (!ability.blockCheck(block.getState())) {
activate = false;
break;
}
2013-02-18 16:32:29 +01:00
if (!blockBreakSimulate(block, player, true)) {
2012-03-13 19:09:32 +01:00
activate = false;
break;
}
break;
2012-03-13 19:09:32 +01:00
case GIGA_DRILL_BREAKER:
case SUPER_BREAKER:
2012-03-13 19:09:32 +01:00
case GREEN_TERRA:
if (!ability.blockCheck(block.getState())) {
2012-03-13 19:09:32 +01:00
activate = false;
break;
}
break;
2012-03-13 19:09:32 +01:00
default:
activate = false;
break;
}
return activate;
2012-03-09 07:23:32 +01:00
}
public static void sendSkillMessage(Player player, String message) {
for (Player otherPlayer : player.getWorld().getPlayers()) {
if (otherPlayer != player && Misc.isNear(player.getLocation(), otherPlayer.getLocation(), Misc.SKILL_MESSAGE_MAX_SENDING_DISTANCE)) {
otherPlayer.sendMessage(message);
}
}
}
/**
* Check if a skill level is higher than the max bonus level of the ability.
*
* @param skillLevel Skill level to check
* @param maxLevel Max level of the ability
* @return whichever value is lower
*/
public static int skillCheck(int skillLevel, int maxLevel) {
//TODO: Could we just use Math.min(skillLevel, maxLevel) here?
if (skillLevel > maxLevel) {
return maxLevel;
}
return skillLevel;
}
public static void handleAbilitySpeedIncrease(Player player) {
if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
ItemStack heldItem = player.getItemInHand();
if (heldItem == null || heldItem.getType() == Material.AIR ) {
return;
}
int efficiencyLevel = heldItem.getEnchantmentLevel(Enchantment.DIG_SPEED);
ItemMeta itemMeta = heldItem.getItemMeta();
List<String> itemLore = new ArrayList<String>();
if (itemMeta.hasLore()) {
itemLore = itemMeta.getLore();
}
itemLore.add("mcMMO Ability Tool");
itemMeta.addEnchant(Enchantment.DIG_SPEED, efficiencyLevel + 5, true);
itemMeta.setLore(itemLore);
heldItem.setItemMeta(itemMeta);
}
else {
int duration = 0;
int amplifier = 0;
if (player.hasPotionEffect(PotionEffectType.FAST_DIGGING)) {
for (PotionEffect effect : player.getActivePotionEffects()) {
if (effect.getType() == PotionEffectType.FAST_DIGGING) {
duration = effect.getDuration();
amplifier = effect.getAmplifier();
break;
}
}
}
PlayerProfile profile = Users.getPlayer(player).getProfile();
int ticks = 0;
if (profile.getAbilityMode(AbilityType.SUPER_BREAKER)) {
ticks = ((int) (profile.getSkillDATS(AbilityType.SUPER_BREAKER) - System.currentTimeMillis())) / Misc.TIME_CONVERSION_FACTOR;
}
else if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
ticks = ((int) (profile.getSkillDATS(AbilityType.GIGA_DRILL_BREAKER) - System.currentTimeMillis())) / Misc.TIME_CONVERSION_FACTOR;
}
PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10);
player.addPotionEffect(abilityBuff, true);
}
}
public static void handleAbilitySpeedDecrease(Player player) {
if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
PlayerInventory playerInventory = player.getInventory();
for (int i = 0; i < playerInventory.getContents().length; i++) {
ItemStack item = playerInventory.getItem(i);
playerInventory.setItem(i, removeAbilityBuff(item));
}
}
else {
player.removePotionEffect(PotionEffectType.FAST_DIGGING);
2013-02-15 01:02:50 +01:00
}
}
public static ItemStack removeAbilityBuff(ItemStack item) {
if (item == null || item.getType() == Material.AIR ) {
return item;
}
2013-02-14 22:02:42 +01:00
if (!ItemChecks.isPickaxe(item) && !ItemChecks.isShovel(item)) {
return item;
}
2013-02-15 01:02:50 +01:00
if (item.containsEnchantment(Enchantment.DIG_SPEED)) {
ItemMeta itemMeta = item.getItemMeta();
2013-02-15 01:02:50 +01:00
if (itemMeta.hasLore()) {
List<String> itemLore = itemMeta.getLore();
if (itemLore.remove("mcMMO Ability Tool")) {
int efficiencyLevel = item.getEnchantmentLevel(Enchantment.DIG_SPEED);
2013-02-15 01:02:50 +01:00
if (efficiencyLevel <= 5) {
itemMeta.removeEnchant(Enchantment.DIG_SPEED);
}
else {
itemMeta.addEnchant(Enchantment.DIG_SPEED, efficiencyLevel - 5, true);
}
2013-02-15 01:02:50 +01:00
itemMeta.setLore(itemLore);
item.setItemMeta(itemMeta);
}
}
}
2013-02-15 01:02:50 +01:00
return item;
}
2013-02-18 16:32:29 +01:00
/**
* Simulate a block break event.
*
* @param block The block to break
* @param player The player breaking the block
* @param shouldArmSwing true if an armswing event should be fired, false otherwise
* @return true if the event wasn't cancelled, false otherwise
*/
public static boolean blockBreakSimulate(Block block, Player player, Boolean shouldArmSwing) {
PluginManager pluginManger = mcMMO.p.getServer().getPluginManager();
2013-02-18 16:32:29 +01:00
//Support for NoCheat
if (shouldArmSwing) {
pluginManger.callEvent(new FakePlayerAnimationEvent(player));
2013-02-18 16:32:29 +01:00
}
FakeBlockDamageEvent damageEvent = new FakeBlockDamageEvent(player, block, player.getItemInHand(), true);
pluginManger.callEvent(damageEvent);
FakeBlockBreakEvent breakEvent = new FakeBlockBreakEvent(block, player);
pluginManger.callEvent(breakEvent);
if (!damageEvent.isCancelled() && !breakEvent.isCancelled()) {
return true;
}
return false;
}
public static boolean activationSuccessful(Player player, SkillType skill, double maxChance, int maxLevel) {
int skillLevel = Users.getPlayer(player).getProfile().getSkillLevel(skill);
int activationChance = PerksUtils.handleLuckyPerks(player, skill);
double chance = (maxChance / maxLevel) * Math.min(skillLevel, maxLevel);
return chance > Misc.getRandom().nextInt(activationChance);
}
public static boolean activationSuccessful(Player player, SkillType skill, double chance) {
return chance > Misc.getRandom().nextInt(PerksUtils.handleLuckyPerks(player, skill));
}
public static boolean unlockLevelReached(Player player, SkillType skill, int unlockLevel) {
return Users.getPlayer(player).getProfile().getSkillLevel(skill) > unlockLevel;
}
2012-01-09 20:00:13 +01:00
}