2013-01-30 17:53:51 +01:00
|
|
|
package com.gmail.nossr50.skills.utilities;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2013-02-14 19:12:15 +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;
|
2012-03-04 09:54:26 +01:00
|
|
|
import org.bukkit.enchantments.Enchantment;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2013-01-24 21:46:29 +01:00
|
|
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
2012-03-04 09:54:26 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2013-02-14 19:12:15 +01:00
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
2013-02-18 16:32:29 +01:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
2013-02-16 20:36:46 +01:00
|
|
|
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;
|
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
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;
|
2013-02-16 20:36:46 +01:00
|
|
|
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;
|
2013-01-22 18:43:25 +01:00
|
|
|
import com.gmail.nossr50.spout.SpoutConfig;
|
2013-01-30 14:08:29 +01:00
|
|
|
import com.gmail.nossr50.spout.SpoutTools;
|
2013-01-22 18:43:25 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2013-02-20 16:40:47 +01:00
|
|
|
import com.gmail.nossr50.util.ParticleEffectUtils;
|
2013-01-22 18:43:25 +01:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2013-02-13 17:45:48 +01:00
|
|
|
import com.gmail.nossr50.util.StringUtils;
|
2013-01-22 18:43:25 +01:00
|
|
|
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 {
|
2012-12-24 22:56:25 +01:00
|
|
|
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
2013-01-24 20:19:26 +01:00
|
|
|
public static boolean abilitiesEnabled = Config.getInstance().getAbilitiesEnabled();
|
2013-02-18 16:26:19 +01:00
|
|
|
public static int toolDurabilityLoss = Config.getInstance().getAbilityToolDamage();
|
|
|
|
public static int abilityLengthIncreaseLevel = AdvancedConfig.getInstance().getAbilityLength();
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2013-01-24 21:46:29 +01:00
|
|
|
public static void handleFoodSkills(Player player, SkillType skill, FoodLevelChangeEvent event, int baseLevel, int maxLevel, int rankChange) {
|
2013-02-04 14:09:24 +01:00
|
|
|
int skillLevel = Users.getPlayer(player).getProfile().getSkillLevel(skill);
|
2013-02-06 05:58:15 +01:00
|
|
|
|
2013-01-24 21:46:29 +01:00
|
|
|
int currentFoodLevel = player.getFoodLevel();
|
|
|
|
int newFoodLevel = event.getFoodLevel();
|
|
|
|
int foodChange = newFoodLevel - currentFoodLevel;
|
|
|
|
|
|
|
|
for (int i = baseLevel; i <= maxLevel; i+= rankChange) {
|
|
|
|
if (skillLevel >= i) {
|
|
|
|
foodChange++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-06 05:58:15 +01:00
|
|
|
event.setFoodLevel(currentFoodLevel + foodChange);
|
2013-01-24 21:46:29 +01:00
|
|
|
}
|
|
|
|
|
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
|
2012-06-22 03:50:48 +02:00
|
|
|
* @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();
|
2013-02-18 17:41:44 +01:00
|
|
|
int adjustedCooldown = PerksUtils.handleCooldownPerks(player, cooldown);
|
2012-06-22 03:50:48 +02:00
|
|
|
|
2013-01-10 03:49:17 +01:00
|
|
|
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
|
|
|
|
*/
|
2012-11-13 06:57:57 +01:00
|
|
|
public static int calculateTimeLeft(long deactivatedTimeStamp, int cooldown, Player player) {
|
2013-02-18 17:41:44 +01:00
|
|
|
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)
|
2012-11-08 04:04:17 +01:00
|
|
|
return;
|
|
|
|
|
2013-01-10 03:49:17 +01:00
|
|
|
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) {
|
2012-04-27 05:58:21 +02:00
|
|
|
if (Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && !player.isSneaking()) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-04 14:09:24 +01:00
|
|
|
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();
|
|
|
|
|
2012-06-28 17:20:53 +02:00
|
|
|
if (ModChecks.isCustomTool(inHand) && !ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/* Check if any abilities are active */
|
2012-07-10 20:02:48 +02:00
|
|
|
if (profile == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
if (!profile.getAbilityUse()) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-27 08:33:35 +02:00
|
|
|
for (AbilityType x : AbilityType.values()) {
|
2012-07-03 16:04:04 +02:00
|
|
|
if (profile.getAbilityMode(x)) {
|
2012-03-27 08:33:35 +02:00
|
|
|
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) {
|
2013-01-10 03:49:17 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-27 05:58:21 +02: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();
|
|
|
|
|
2012-07-10 20:02:48 +02:00
|
|
|
if (profile == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-10 03:49:17 +01:00
|
|
|
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);
|
2012-07-03 14:40:56 +02:00
|
|
|
|
|
|
|
if (Config.getInstance().getAbilityMessagesEnabled()) {
|
|
|
|
player.sendMessage(tool.getLowerTool());
|
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ability.getPermissions(player)) {
|
2013-01-10 03:49:17 +01:00
|
|
|
if (profile.getAbilityMode(ability) && (profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR) <= curTime) {
|
2013-01-24 15:44:28 +01:00
|
|
|
if (ability == AbilityType.BERSERK) {
|
|
|
|
player.setCanPickupItems(true);
|
|
|
|
}
|
2013-02-14 19:12:15 +01:00
|
|
|
else if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) {
|
|
|
|
handleAbilitySpeedDecrease(player);
|
|
|
|
}
|
2013-01-24 15:44:28 +01:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
profile.setAbilityMode(ability, false);
|
|
|
|
profile.setAbilityInformed(ability, false);
|
2013-02-20 14:42:25 +01:00
|
|
|
|
2013-02-20 16:40:47 +01:00
|
|
|
ParticleEffectUtils.playAbilityDisabledEffect(player);
|
2013-02-19 19:25:59 +01:00
|
|
|
|
|
|
|
if (profile.useChatNotifications()) {
|
|
|
|
player.sendMessage(ability.getAbilityOff());
|
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2013-02-13 22:45:49 +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
|
2012-06-04 15:30:51 +02:00
|
|
|
* @param profile The profile of the player whose skill to check
|
2012-03-13 19:09:32 +01:00
|
|
|
*/
|
2012-06-04 15:30:51 +02:00
|
|
|
public static void xpCheckSkill(SkillType skillType, Player player, PlayerProfile profile) {
|
2012-03-29 04:45:34 +02:00
|
|
|
int skillups = 0;
|
2013-02-18 14:35:52 +01:00
|
|
|
int xpRemoved = 0;
|
2012-04-03 06:56:05 +02:00
|
|
|
|
2012-06-04 15:30:51 +02:00
|
|
|
if (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
|
2012-03-28 20:37:17 +02:00
|
|
|
|
2012-06-04 15:30:51 +02:00
|
|
|
while (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
|
2013-02-18 16:11:43 +01:00
|
|
|
if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Config.getInstance().getPowerLevelCap() >= Users.getPlayer(player).getPowerLevel() + 1)) {
|
2013-02-18 14:35:52 +01:00
|
|
|
int xp = profile.getXpToLevel(skillType);
|
|
|
|
xpRemoved += xp;
|
|
|
|
|
|
|
|
profile.removeXp(skillType, xp);
|
2012-03-13 19:09:32 +01:00
|
|
|
skillups++;
|
2012-06-04 15:30:51 +02:00
|
|
|
profile.skillUp(skillType, 1);
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-04-18 14:19:49 +02:00
|
|
|
else {
|
2012-06-04 15:30:51 +02:00
|
|
|
profile.addLevels(skillType, 0);
|
2012-04-18 14:19:49 +02:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
|
2013-02-18 14:35:52 +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;
|
|
|
|
}
|
|
|
|
|
2013-02-13 17:45:48 +01:00
|
|
|
String capitalized = StringUtils.getCapitalized(skillType.toString());
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
/* Spout Stuff */
|
2012-07-07 19:58:51 +02:00
|
|
|
if (mcMMO.spoutEnabled) {
|
2012-07-03 16:14:01 +02:00
|
|
|
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2012-07-07 19:58:51 +02:00
|
|
|
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
2013-01-30 14:08:29 +01:00
|
|
|
SpoutTools.levelUpNotification(skillType, spoutPlayer);
|
2012-04-17 22:22:57 +02:00
|
|
|
|
2012-04-03 16:08:37 +02:00
|
|
|
/* Update custom titles */
|
2012-05-23 16:50:47 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2012-03-29 16:44:37 +02:00
|
|
|
|
2012-07-07 19:58:51 +02:00
|
|
|
if (mcMMO.spoutEnabled) {
|
2013-02-03 01:20:31 +01:00
|
|
|
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
2012-07-07 19:58:51 +02:00
|
|
|
|
|
|
|
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
2012-05-23 16:50:47 +02:00
|
|
|
if (SpoutConfig.getInstance().getXPBarEnabled()) {
|
2012-07-07 19:58:51 +02:00
|
|
|
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
|
|
|
|
*
|
2013-01-31 01:42:40 +01:00
|
|
|
* @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) {
|
2013-02-15 15:26:01 +01:00
|
|
|
if (!Config.getInstance().getLocale().equalsIgnoreCase("en_US")) {
|
|
|
|
return isLocalizedSkill(skillName);
|
|
|
|
}
|
|
|
|
|
2013-02-07 18:17:18 +01:00
|
|
|
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
|
|
|
|
2013-02-15 15:26:01 +01:00
|
|
|
private static boolean isLocalizedSkill(String skillName) {
|
2013-01-16 06:06:14 +01:00
|
|
|
for (SkillType skill : SkillType.values()) {
|
2013-02-15 15:26:01 +01:00
|
|
|
if (skillName.equalsIgnoreCase(LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".SkillName"))) {
|
2013-01-16 06:06:14 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-15 15:26:01 +01:00
|
|
|
public static String getSkillName(SkillType skill) {
|
|
|
|
if (!Config.getInstance().getLocale().equalsIgnoreCase("en_US")) {
|
|
|
|
return StringUtils.getCapitalized(LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".SkillName"));
|
2013-01-16 06:06:14 +01:00
|
|
|
}
|
|
|
|
|
2013-02-15 15:26:01 +01:00
|
|
|
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) {
|
2013-02-19 06:56:25 +01:00
|
|
|
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) {
|
2013-02-19 06:56:25 +01:00
|
|
|
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) {
|
2013-02-19 06:56:25 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-02-27 23:28:32 +01:00
|
|
|
/**
|
|
|
|
* Check to see if an ability can be activated.
|
2012-03-13 19:09:32 +01:00
|
|
|
*
|
2012-02-27 23:28: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) {
|
2013-02-04 14:09:24 +01:00
|
|
|
PlayerProfile profile = Users.getPlayer(player).getProfile();
|
2012-03-27 08:33:35 +02:00
|
|
|
ToolType tool = type.getTool();
|
2013-01-25 18:33:48 +01:00
|
|
|
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) {
|
2013-01-10 03:49:17 +01:00
|
|
|
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 05:01:02 +02:00
|
|
|
}
|
2012-06-22 20:20:28 +02:00
|
|
|
}
|
2012-06-22 05:01:02 +02:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
if (!profile.getAbilityMode(ability) && cooldownOver(profile.getSkillDATS(ability), ability.getCooldown(), player)) {
|
2013-02-19 19:02:08 +01:00
|
|
|
int ticks = PerksUtils.handleActivationPerks(player, 2 + (profile.getSkillLevel(type) / abilityLengthIncreaseLevel), ability.getMaxTicks());
|
2012-06-22 20:20:28 +02:00
|
|
|
|
2013-02-20 16:40:47 +01:00
|
|
|
ParticleEffectUtils.playAbilityEnabledEffect(player);
|
2013-02-19 19:25:59 +01:00
|
|
|
|
|
|
|
if (profile.useChatNotifications()) {
|
|
|
|
player.sendMessage(ability.getAbilityOn());
|
|
|
|
}
|
|
|
|
|
2013-02-13 22:45:49 +01:00
|
|
|
SkillTools.sendSkillMessage(player, ability.getAbilityPlayer(player));
|
2012-06-22 20:20:28 +02:00
|
|
|
|
2013-02-19 19:02:08 +01:00
|
|
|
profile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
|
2012-07-03 16:04:04 +02:00
|
|
|
profile.setAbilityMode(ability, true);
|
2013-02-14 19:12:15 +01:00
|
|
|
|
2013-01-24 15:44:28 +01:00
|
|
|
if (ability == AbilityType.BERSERK) {
|
|
|
|
player.setCanPickupItems(false);
|
|
|
|
}
|
2013-02-14 19:12:15 +01:00
|
|
|
else if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) {
|
2013-02-16 17:34:39 +01:00
|
|
|
handleAbilitySpeedIncrease(player);
|
2013-02-14 19:12:15 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-02-27 23:28: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 GIGA_DRILL_BREAKER:
|
|
|
|
case SUPER_BREAKER:
|
|
|
|
case LEAF_BLOWER:
|
2012-06-14 16:24:58 +02:00
|
|
|
if (!ability.blockCheck(block)) {
|
|
|
|
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;
|
|
|
|
}
|
2012-06-14 16:24:58 +02:00
|
|
|
break;
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
case GREEN_TERRA:
|
2012-05-10 15:54:29 +02:00
|
|
|
if (!ability.blockCheck(block)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
activate = false;
|
|
|
|
break;
|
|
|
|
}
|
2012-03-14 18:33:00 +01:00
|
|
|
break;
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
activate = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return activate;
|
2012-03-09 07:23:32 +01:00
|
|
|
}
|
2013-02-13 22:45:49 +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;
|
|
|
|
}
|
2013-02-14 19:12:15 +01:00
|
|
|
|
2013-02-16 17:34:39 +01:00
|
|
|
public static void handleAbilitySpeedIncrease(Player player) {
|
2013-02-16 20:36:46 +01:00
|
|
|
if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
|
|
|
|
ItemStack heldItem = player.getItemInHand();
|
2013-02-16 17:34:39 +01:00
|
|
|
|
2013-02-16 20:36:46 +01:00
|
|
|
if (heldItem == null || heldItem.getType() == Material.AIR ) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-16 17:34:39 +01:00
|
|
|
|
2013-02-16 20:36:46 +01:00
|
|
|
int efficiencyLevel = heldItem.getEnchantmentLevel(Enchantment.DIG_SPEED);
|
|
|
|
ItemMeta itemMeta = heldItem.getItemMeta();
|
|
|
|
List<String> itemLore = new ArrayList<String>();
|
2013-02-14 19:12:15 +01:00
|
|
|
|
2013-02-16 20:36:46 +01:00
|
|
|
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);
|
2013-02-14 19:12:15 +01:00
|
|
|
}
|
2013-02-16 20:36:46 +01:00
|
|
|
else {
|
|
|
|
int duration = 0;
|
|
|
|
int amplifier = 0;
|
2013-02-14 19:12:15 +01:00
|
|
|
|
2013-02-16 20:36:46 +01:00
|
|
|
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;
|
|
|
|
}
|
2013-02-14 19:12:15 +01:00
|
|
|
|
2013-02-16 20:36:46 +01:00
|
|
|
PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10);
|
|
|
|
player.addPotionEffect(abilityBuff, true);
|
|
|
|
}
|
2013-02-14 19:12:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void handleAbilitySpeedDecrease(Player player) {
|
2013-02-16 20:36:46 +01:00
|
|
|
if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
|
|
|
|
PlayerInventory playerInventory = player.getInventory();
|
2013-02-14 19:12:15 +01:00
|
|
|
|
2013-02-16 20:36:46 +01:00
|
|
|
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
|
|
|
|
2013-02-15 01:02:50 +01:00
|
|
|
if (item.containsEnchantment(Enchantment.DIG_SPEED)) {
|
|
|
|
ItemMeta itemMeta = item.getItemMeta();
|
2013-02-14 19:12:15 +01:00
|
|
|
|
2013-02-15 01:02:50 +01:00
|
|
|
if (itemMeta.hasLore()) {
|
|
|
|
List<String> itemLore = itemMeta.getLore();
|
|
|
|
|
|
|
|
if (itemLore.remove("mcMMO Ability Tool")) {
|
2013-02-14 19:12:15 +01:00
|
|
|
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-14 19:12:15 +01:00
|
|
|
}
|
2013-02-15 01:02:50 +01:00
|
|
|
|
|
|
|
itemMeta.setLore(itemLore);
|
|
|
|
item.setItemMeta(itemMeta);
|
2013-02-14 19:12:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-15 01:02:50 +01:00
|
|
|
|
|
|
|
return item;
|
2013-02-14 19:12:15 +01:00
|
|
|
}
|
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) {
|
|
|
|
|
|
|
|
//Support for NoCheat
|
|
|
|
if (shouldArmSwing) {
|
|
|
|
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginManager pluginManger = mcMMO.p.getServer().getPluginManager();
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|