Moved ability and tool stuff from McMMOPlayer to SkillManager classes

Warning: Because Woodcutting and Repair don't have a "proper" manager
class, this doesn't work yet.
This commit is contained in:
bm01 2013-03-03 23:27:51 +01:00
parent 1b461ac96a
commit 12b548bf46
14 changed files with 174 additions and 198 deletions

View File

@ -3,45 +3,46 @@ package com.gmail.nossr50.api;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.player.UserManager;
public final class AbilityAPI {
private AbilityAPI() {}
public static boolean berserkEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.BERSERK);
return UserManager.getPlayer(player).getSkillManager(SkillType.UNARMED).getAbilityMode();
}
public static boolean gigaDrillBreakerEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.GIGA_DRILL_BREAKER);
return UserManager.getPlayer(player).getSkillManager(SkillType.EXCAVATION).getAbilityMode();
}
public static boolean greenTerraEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.GREEN_TERRA);
return UserManager.getPlayer(player).getSkillManager(SkillType.HERBALISM).getAbilityMode();
}
public static boolean serratedStrikesEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.SERRATED_STRIKES);
return UserManager.getPlayer(player).getSkillManager(SkillType.SWORDS).getAbilityMode();
}
public static boolean skullSplitterEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.SKULL_SPLITTER);
return UserManager.getPlayer(player).getSkillManager(SkillType.AXES).getAbilityMode();
}
public static boolean superBreakerEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.SUPER_BREAKER);
return UserManager.getPlayer(player).getSkillManager(SkillType.MINING).getAbilityMode();
}
public static boolean treeFellerEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.TREE_FELLER);
return UserManager.getPlayer(player).getSkillManager(SkillType.WOODCUTTING).getAbilityMode();
}
public static boolean isAnyAbilityEnabled(Player player) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
for (AbilityType ability : AbilityType.values()) {
if (mcMMOPlayer.getAbilityMode(ability)) {
for (SkillManager skillManager : mcMMOPlayer.getSkillManagers().values()) {
if (skillManager.getAbilityMode()) {
return true;
}
}

View File

@ -12,9 +12,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.datatypes.spout.huds.McMMOHud;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.party.PartyManager;
@ -69,11 +67,6 @@ public class McMMOPlayer {
private boolean placedSalvageAnvil;
private boolean godMode;
private Map<AbilityType, Boolean> abilityMode = new HashMap<AbilityType, Boolean>();
private Map<AbilityType, Boolean> abilityInformed = new HashMap<AbilityType, Boolean>();
private Map<ToolType, Boolean> toolPreparationMode = new HashMap<ToolType, Boolean>();
private Map<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
private int recentlyHurt;
private int respawnATS;
@ -103,16 +96,6 @@ public class McMMOPlayer {
e.printStackTrace();
mcMMO.p.getPluginLoader().disablePlugin(mcMMO.p);
}
for (AbilityType abilityType : AbilityType.values()) {
abilityMode.put(abilityType, false);
abilityInformed.put(abilityType, true); // This is intended
}
for (ToolType toolType : ToolType.values()) {
toolPreparationMode.put(toolType, false);
toolATS.put(toolType, 0);
}
}
public AcrobaticsManager getAcrobaticsManager() {
@ -159,6 +142,14 @@ public class McMMOPlayer {
return (UnarmedManager) skillManagers.get(SkillType.UNARMED);
}
public SkillManager getSkillManager(SkillType skillType) {
return skillManagers.get(skillType);
}
public Map<SkillType, SkillManager> getSkillManagers() {
return skillManagers;
}
/*
* Abilities
*/
@ -167,61 +158,11 @@ public class McMMOPlayer {
* Reset the mode of all abilities.
*/
public void resetAbilityMode() {
for (AbilityType ability : AbilityType.values()) {
setAbilityMode(ability, false);
for (SkillManager skillManager : skillManagers.values()) {
skillManager.setAbilityMode(false);
}
}
/**
* Get the mode of an ability.
*
* @param ability The ability to check
* @return true if the ability is enabled, false otherwise
*/
public boolean getAbilityMode(AbilityType ability) {
return abilityMode.get(ability);
}
/**
* Set the mode of an ability.
*
* @param ability The ability to check
* @param bool True if the ability is active, false otherwise
*/
public void setAbilityMode(AbilityType ability, boolean bool) {
abilityMode.put(ability, bool);
}
/**
* Get the informed state of an ability
*
* @param ability The ability to check
* @return true if the ability is informed, false otherwise
*/
public boolean getAbilityInformed(AbilityType ability) {
return abilityInformed.get(ability);
}
/**
* Set the informed state of an ability.
*
* @param ability The ability to check
* @param bool True if the ability is informed, false otherwise
*/
public void setAbilityInformed(AbilityType ability, boolean bool) {
abilityInformed.put(ability, bool);
}
/**
* Get the current prep mode of a tool.
*
* @param tool Tool to get the mode for
* @return true if the tool is prepped, false otherwise
*/
public boolean getToolPreparationMode(ToolType tool) {
return toolPreparationMode.get(tool);
}
public boolean getAbilityUse() {
return abilityUse;
}
@ -238,43 +179,11 @@ public class McMMOPlayer {
* Reset the prep modes of all tools.
*/
public void resetToolPrepMode() {
for (ToolType tool : ToolType.values()) {
setToolPreparationMode(tool, false);
for (SkillManager skillManager : skillManagers.values()) {
skillManager.getTool().setPreparationMode(false);
}
}
/**
* Set the current prep mode of a tool.
*
* @param tool Tool to set the mode for
* @param bool true if the tool should be prepped, false otherwise
*/
public void setToolPreparationMode(ToolType tool, boolean bool) {
toolPreparationMode.put(tool, bool);
}
/**
* Get the current prep ATS of a tool.
*
* @param tool Tool to get the ATS for
* @return the ATS for the tool
*/
public long getToolPreparationATS(ToolType tool) {
return toolATS.get(tool);
}
/**
* Set the current prep ATS of a tool.
*
* @param tool Tool to set the ATS for
* @param ATS the ATS of the tool
*/
public void setToolPreparationATS(ToolType tool, long ATS) {
int startTime = (int) (ATS / Misc.TIME_CONVERSION_FACTOR);
toolATS.put(tool, startTime);
}
/*
* Recently Hurt
*/

View File

@ -34,18 +34,18 @@ public enum SkillType {
private Class<? extends SkillManager> managerClass;
private AbilityType ability;
private ToolType tool;
private ToolType toolType;
private SkillType(Class<? extends SkillManager> managerClass) {
this.managerClass = managerClass;
ability = null;
tool = null;
toolType = null;
}
private SkillType(Class<? extends SkillManager> managerClass, AbilityType ability, ToolType tool) {
this.managerClass = managerClass;
this.ability = ability;
this.tool = tool;
this.toolType = tool;
}
public Class<? extends SkillManager> getManagerClass() {
@ -77,8 +77,8 @@ public enum SkillType {
return Config.getInstance().getDoubleDropsDisabled(this);
}
public ToolType getTool() {
return tool;
public ToolType getToolType() {
return toolType;
}
public double getXpModifier() {

View File

@ -0,0 +1,44 @@
package com.gmail.nossr50.datatypes.skills;
import java.util.HashMap;
import java.util.Map;
import com.gmail.nossr50.util.Misc;
public class Tool {
private static Map<ToolType, Tool> tools = new HashMap<ToolType, Tool>();
private boolean preparationMode = true;
private long preparationATS;
private Tool(ToolType toolType) {
tools.put(toolType, this);
}
public boolean getPreparationMode() {
return preparationMode;
}
public void setPreparationMode(boolean preparationMode) {
this.preparationMode = preparationMode;
}
public long getPreparationATS() {
return preparationATS;
}
public void setPreparationATS(long toolPreparationATS) {
int startTime = (int) (toolPreparationATS / Misc.TIME_CONVERSION_FACTOR);
preparationATS = startTime;
}
public static Tool getTool(ToolType toolType) {
Tool tool = tools.get(toolType);
if (tool == null) {
tool = new Tool(toolType);
}
return tool;
}
}

View File

@ -25,7 +25,6 @@ import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
@ -176,16 +175,17 @@ public class BlockListener implements Listener {
/* MINING */
else if (BlockUtils.affectedBySuperBreaker(blockState) && ItemUtils.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.placeStore.isTrue(blockState)) {
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
miningManager.miningBlockCheck(blockState);
if (mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER)) {
if (miningManager.getAbilityMode()) {
miningManager.miningBlockCheck(blockState);
}
}
/* WOOD CUTTING */
else if (BlockUtils.isLog(blockState) && Permissions.skillEnabled(player, SkillType.WOODCUTTING) && !mcMMO.placeStore.isTrue(blockState)) {
if (mcMMOPlayer.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(player) && ItemUtils.isAxe(heldItem)) {
if (mcMMOPlayer.getSkillManager(SkillType.WOODCUTTING).getAbilityMode() && Permissions.treeFeller(player) && ItemUtils.isAxe(heldItem)) {
Woodcutting.beginTreeFeller(blockState, player);
}
else {
@ -203,9 +203,10 @@ public class BlockListener implements Listener {
/* EXCAVATION */
else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(blockState)) {
ExcavationManager excavationManager = UserManager.getPlayer(player).getExcavationManager();
excavationManager.excavationBlockCheck(blockState);
if (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
if (excavationManager.getAbilityMode()) {
excavationManager.gigaDrillBreaker(blockState);
}
}
@ -281,29 +282,29 @@ public class BlockListener implements Listener {
ItemStack heldItem = player.getItemInHand();
if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
if ((ItemUtils.isPickaxe(heldItem) && !mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER)) || (ItemUtils.isShovel(heldItem) && !mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER))) {
if ((ItemUtils.isPickaxe(heldItem) && !mcMMOPlayer.getSkillManager(SkillType.MINING).getAbilityMode()) || (ItemUtils.isShovel(heldItem) && !mcMMOPlayer.getSkillManager(SkillType.EXCAVATION).getAbilityMode())) {
SkillUtils.removeAbilityBuff(heldItem);
}
}
else {
if ((mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER) && !BlockUtils.affectedBySuperBreaker(blockState)) || (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && !BlockUtils.affectedByGigaDrillBreaker(blockState))) {
if ((mcMMOPlayer.getSkillManager(SkillType.MINING).getAbilityMode() && !BlockUtils.affectedBySuperBreaker(blockState)) || (mcMMOPlayer.getSkillManager(SkillType.EXCAVATION).getAbilityMode() && !BlockUtils.affectedByGigaDrillBreaker(blockState))) {
SkillUtils.handleAbilitySpeedDecrease(player);
}
}
if (mcMMOPlayer.getToolPreparationMode(ToolType.HOE) && ItemUtils.isHoe(heldItem) && (BlockUtils.affectedByGreenTerra(blockState) || BlockUtils.canMakeMossy(blockState)) && Permissions.greenTerra(player)) {
if (mcMMOPlayer.getSkillManager(SkillType.HERBALISM).getTool().getPreparationMode() && ItemUtils.isHoe(heldItem) && (BlockUtils.affectedByGreenTerra(blockState) || BlockUtils.canMakeMossy(blockState)) && Permissions.greenTerra(player)) {
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.HERBALISM);
}
else if (mcMMOPlayer.getToolPreparationMode(ToolType.AXE) && ItemUtils.isAxe(heldItem) && BlockUtils.isLog(blockState) && Permissions.treeFeller(player)) {
else if (mcMMOPlayer.getSkillManager(SkillType.WOODCUTTING).getTool().getPreparationMode() && ItemUtils.isAxe(heldItem) && BlockUtils.isLog(blockState) && Permissions.treeFeller(player)) {
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.WOODCUTTING);
}
else if (mcMMOPlayer.getToolPreparationMode(ToolType.PICKAXE) && ItemUtils.isPickaxe(heldItem) && BlockUtils.affectedBySuperBreaker(blockState) && Permissions.superBreaker(player)) {
else if (mcMMOPlayer.getSkillManager(SkillType.MINING).getTool().getPreparationMode() && ItemUtils.isPickaxe(heldItem) && BlockUtils.affectedBySuperBreaker(blockState) && Permissions.superBreaker(player)) {
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.MINING);
}
else if (mcMMOPlayer.getToolPreparationMode(ToolType.SHOVEL) && ItemUtils.isShovel(heldItem) && BlockUtils.affectedByGigaDrillBreaker(blockState) && Permissions.gigaDrillBreaker(player)) {
else if (mcMMOPlayer.getSkillManager(SkillType.EXCAVATION).getTool().getPreparationMode() && ItemUtils.isShovel(heldItem) && BlockUtils.affectedByGigaDrillBreaker(blockState) && Permissions.gigaDrillBreaker(player)) {
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.EXCAVATION);
}
else if (mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && heldItem.getType() == Material.AIR && (BlockUtils.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW || BlockUtils.affectedByBlockCracker(blockState) && Permissions.berserk(player))) {
else if (mcMMOPlayer.getSkillManager(SkillType.UNARMED).getTool().getPreparationMode() && heldItem.getType() == Material.AIR && (BlockUtils.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW || BlockUtils.affectedByBlockCracker(blockState) && Permissions.berserk(player))) {
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.UNARMED);
}
}
@ -313,7 +314,7 @@ public class BlockListener implements Listener {
*
* We don't need to check permissions here because they've already been checked for the ability to even activate.
*/
if (mcMMOPlayer.getAbilityMode(AbilityType.TREE_FELLER) && BlockUtils.isLog(blockState)) {
if (mcMMOPlayer.getSkillManager(SkillType.WOODCUTTING).getTool().getPreparationMode() && BlockUtils.isLog(blockState)) {
player.playSound(blockState.getLocation(), Sound.FIZZ, Misc.FIZZ_VOLUME, Misc.FIZZ_PITCH);
}
}
@ -351,7 +352,7 @@ public class BlockListener implements Listener {
blockState.update(true);
}
}
else if (mcMMOPlayer.getAbilityMode(AbilityType.BERSERK)) {
else if (mcMMOPlayer.getSkillManager(SkillType.UNARMED).getTool().getPreparationMode()) {
if (SkillUtils.triggerCheck(player, block, AbilityType.BERSERK)) {
if (heldItem.getType() == Material.AIR) {
plugin.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));

View File

@ -30,7 +30,6 @@ import com.gmail.nossr50.chat.ChatManager;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.ShareHandler;
@ -140,7 +139,7 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer();
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) || mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER)) {
if (mcMMOPlayer.getSkillManager(SkillType.EXCAVATION).getAbilityMode() || mcMMOPlayer.getSkillManager(SkillType.MINING).getAbilityMode()) {
event.setCancelled(true);
return;
}

View File

@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.UserManager;
@ -23,20 +22,19 @@ public class SkillMonitorTask implements Runnable {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
/*
* MONITOR SKILLS
* MONITOR SKILLS & COOLDOWN
*/
for (SkillType skill : SkillType.values()) {
if (skill.getTool() != null && skill.getAbility() != null) {
SkillUtils.monitorSkill(mcMMOPlayer, curTime, skill);
}
if (skill.getAbility() == null) {
continue;
}
/*
* COOLDOWN MONITORING
*/
for (AbilityType ability : AbilityType.values()) {
if (ability.getCooldown() > 0) {
SkillUtils.watchCooldown(mcMMOPlayer, ability);
if (skill.getToolType() != null) {
SkillUtils.monitorSkill(mcMMOPlayer, curTime, skill);
}
if (skill.getAbility().getCooldown() > 0) {
SkillUtils.watchCooldown(mcMMOPlayer, skill);
}
}
}

View File

@ -5,17 +5,22 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.Tool;
import com.gmail.nossr50.util.skills.PerksUtils;
public abstract class SkillManager {
protected McMMOPlayer mcMMOPlayer;
protected int activationChance;
protected SkillType skill;
protected boolean abilityMode;
protected boolean abilityInformed = true;
protected Tool tool;
public SkillManager(McMMOPlayer mcMMOPlayer, SkillType skill) {
this.mcMMOPlayer = mcMMOPlayer;
this.activationChance = PerksUtils.handleLuckyPerks(mcMMOPlayer.getPlayer(), skill);
this.skill = skill;
this.tool = Tool.getTool(skill.getToolType());
}
public McMMOPlayer getMcMMOPlayer() {
@ -41,4 +46,24 @@ public abstract class SkillManager {
public void applyXpGain(int xp) {
mcMMOPlayer.beginXpGain(skill, xp);
}
public boolean getAbilityMode() {
return abilityMode;
}
public void setAbilityMode(boolean abilityMode) {
this.abilityMode = abilityMode;
}
public boolean getAbilityInformed() {
return abilityInformed;
}
public void setAbilityInformed(boolean abilityInformed) {
this.abilityInformed = abilityInformed;
}
public Tool getTool() {
return tool;
}
}

View File

@ -6,9 +6,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.ItemUtils;
@ -41,11 +39,11 @@ public class AxesManager extends SkillManager {
}
public boolean canUseSkullSplitter(LivingEntity target) {
return target.isValid() && mcMMOPlayer.getAbilityMode(AbilityType.SKULL_SPLITTER) && Permissions.skullSplitter(getPlayer());
return target.isValid() && abilityMode && Permissions.skullSplitter(getPlayer());
}
public boolean canActivateAbility() {
return mcMMOPlayer.getToolPreparationMode(ToolType.AXE) && Permissions.skullSplitter(getPlayer());
return tool.getPreparationMode() && Permissions.skullSplitter(getPlayer());
}
/**

View File

@ -15,9 +15,7 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.skills.herbalism.GreenTerraTimerTask;
@ -60,15 +58,15 @@ public class HerbalismManager extends SkillManager {
}
public boolean canGreenTerraBlock(BlockState blockState) {
return mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA) && BlockUtils.canMakeMossy(blockState);
return abilityMode && BlockUtils.canMakeMossy(blockState);
}
public boolean canActivateAbility() {
return mcMMOPlayer.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(getPlayer());
return tool.getPreparationMode() && Permissions.greenTerra(getPlayer());
}
public boolean canGreenTerraPlant() {
return mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA);
return abilityMode;
}
/**
@ -286,7 +284,7 @@ public class HerbalismManager extends SkillManager {
return;
}
if (mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA)) {
if (abilityMode) {
playerInventory.removeItem(seed);
player.updateInventory(); // Needed until replacement available

View File

@ -97,7 +97,7 @@ public class MiningManager extends SkillManager{
targetBlock.setType(Material.AIR);
getProfile().setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis());
mcMMOPlayer.setAbilityInformed(AbilityType.BLAST_MINING, false);
abilityInformed = false;
}
/**

View File

@ -4,9 +4,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.skills.SkillManager;
@ -21,7 +19,7 @@ public class SwordsManager extends SkillManager {
}
public boolean canActivateAbility() {
return mcMMOPlayer.getToolPreparationMode(ToolType.SWORD) && Permissions.serratedStrikes(getPlayer());
return tool.getPreparationMode() && Permissions.serratedStrikes(getPlayer());
}
public boolean canUseBleed() {
@ -29,7 +27,7 @@ public class SwordsManager extends SkillManager {
}
public boolean canUseSerratedStrike() {
return mcMMOPlayer.getAbilityMode(AbilityType.SERRATED_STRIKES) && Permissions.serratedStrikes(getPlayer());
return abilityMode && Permissions.serratedStrikes(getPlayer());
}
/**

View File

@ -7,9 +7,7 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.events.skills.unarmed.McMMOPlayerDisarmEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
@ -23,7 +21,7 @@ public class UnarmedManager extends SkillManager {
}
public boolean canActivateAbility() {
return mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && Permissions.berserk(getPlayer());
return tool.getPreparationMode() && Permissions.berserk(getPlayer());
}
public boolean canUseIronArm() {
@ -31,7 +29,7 @@ public class UnarmedManager extends SkillManager {
}
public boolean canUseBerserk() {
return mcMMOPlayer.getAbilityMode(AbilityType.BERSERK) && Permissions.berserk(getPlayer());
return abilityMode && Permissions.berserk(getPlayer());
}
public boolean canDisarm(LivingEntity target) {

View File

@ -25,12 +25,14 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.Tool;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils;
@ -89,17 +91,19 @@ public class SkillUtils {
* Sends a message to the player when the cooldown expires.
*
* @param mcMMOPlayer The player to send a message to
* @param ability The ability to watch cooldowns for
* @param skill The skill type to watch cooldowns for
*/
public static void watchCooldown(McMMOPlayer mcMMOPlayer, AbilityType ability) {
if (mcMMOPlayer == null || ability == null) {
public static void watchCooldown(McMMOPlayer mcMMOPlayer, SkillType skill) {
if (mcMMOPlayer == null) {
return;
}
Player player = mcMMOPlayer.getPlayer();
SkillManager skillManager = mcMMOPlayer.getSkillManager(skill);
AbilityType ability = skill.getAbility();
if (!mcMMOPlayer.getAbilityInformed(ability) && cooldownOver(mcMMOPlayer.getProfile().getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
mcMMOPlayer.setAbilityInformed(ability, true);
if (!skillManager.getAbilityInformed() && cooldownOver(mcMMOPlayer.getProfile().getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
skillManager.setAbilityInformed(true);
player.sendMessage(ability.getAbilityRefresh());
}
}
@ -115,45 +119,48 @@ public class SkillUtils {
return;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
AbilityType ability = skill.getAbility();
ToolType tool = skill.getTool();
ItemStack inHand = player.getItemInHand();
if (ModUtils.isCustomTool(inHand) && !ModUtils.getToolFromItemStack(inHand).isAbilityEnabled()) {
return;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (!mcMMOPlayer.getAbilityUse()) {
return;
}
for (AbilityType abilityType : AbilityType.values()) {
if (mcMMOPlayer.getAbilityMode(abilityType)) {
for (SkillManager skillManager : mcMMOPlayer.getSkillManagers().values()) {
if (skillManager.getAbilityMode()) {
return;
}
}
SkillManager skillManager = mcMMOPlayer.getSkillManager(skill);
Tool tool = skillManager.getTool();
ToolType toolType = skill.getToolType();
AbilityType ability = skill.getAbility();
PlayerProfile playerProfile = mcMMOPlayer.getProfile();
/*
* 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
*/
if (ability.getPermissions(player) && tool.inHand(inHand) && !mcMMOPlayer.getToolPreparationMode(tool)) {
if (ability.getPermissions(player) && toolType.inHand(inHand) && !tool.getPreparationMode()) {
if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) {
if (!mcMMOPlayer.getAbilityMode(ability) && !cooldownOver(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
if (!skillManager.getAbilityMode() && !cooldownOver(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired", calculateTimeLeft(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)));
return;
}
}
if (Config.getInstance().getAbilityMessagesEnabled()) {
player.sendMessage(tool.getRaiseTool());
player.sendMessage(toolType.getRaiseTool());
}
mcMMOPlayer.setToolPreparationATS(tool, System.currentTimeMillis());
mcMMOPlayer.setToolPreparationMode(tool, true);
tool.setPreparationATS(System.currentTimeMillis());
tool.setPreparationMode(true);
}
}
@ -167,13 +174,14 @@ public class SkillUtils {
*/
public static void monitorSkill(McMMOPlayer mcMMOPlayer, long curTime, SkillType skill) {
final int FOUR_SECONDS = 4000;
ToolType tool = skill.getTool();
SkillManager skillManager = mcMMOPlayer.getSkillManager(skill);
Tool tool = skillManager.getTool();
if (mcMMOPlayer.getToolPreparationMode(tool) && curTime - (mcMMOPlayer.getToolPreparationATS(tool) * Misc.TIME_CONVERSION_FACTOR) >= FOUR_SECONDS) {
mcMMOPlayer.setToolPreparationMode(tool, false);
if (tool.getPreparationMode() && curTime - (tool.getPreparationATS() * Misc.TIME_CONVERSION_FACTOR) >= FOUR_SECONDS) {
tool.setPreparationMode(false);
if (Config.getInstance().getAbilityMessagesEnabled()) {
mcMMOPlayer.getPlayer().sendMessage(tool.getLowerTool());
mcMMOPlayer.getPlayer().sendMessage(skill.getToolType().getLowerTool());
}
}
@ -181,7 +189,7 @@ public class SkillUtils {
Player player = mcMMOPlayer.getPlayer();
if (ability.getPermissions(player)) {
if (mcMMOPlayer.getAbilityMode(ability) && (mcMMOPlayer.getProfile().getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR) <= curTime) {
if (skillManager.getAbilityMode() && (mcMMOPlayer.getProfile().getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR) <= curTime) {
if (ability == AbilityType.BERSERK) {
player.setCanPickupItems(true);
}
@ -189,8 +197,8 @@ public class SkillUtils {
handleAbilitySpeedDecrease(player);
}
mcMMOPlayer.setAbilityMode(ability, false);
mcMMOPlayer.setAbilityInformed(ability, false);
skillManager.setAbilityMode(false);
skillManager.setAbilityInformed(false);
ParticleEffectUtils.playAbilityDisabledEffect(player);
@ -365,30 +373,29 @@ public class SkillUtils {
* Check to see if an ability can be activated.
*
* @param mcMMOPlayer The player activating the ability
* @param type The skill the ability is based on
* @param skill The skill the ability is based on
*/
public static void abilityCheck(McMMOPlayer mcMMOPlayer, SkillType type) {
ToolType tool = type.getTool();
AbilityType ability = type.getAbility();
mcMMOPlayer.setToolPreparationMode(tool, false);
public static void abilityCheck(McMMOPlayer mcMMOPlayer, SkillType skill) {
SkillManager skillManager = mcMMOPlayer.getSkillManager(skill);
AbilityType ability = skill.getAbility();
Player player = mcMMOPlayer.getPlayer();
PlayerProfile playerProfile = mcMMOPlayer.getProfile();
skillManager.getTool().setPreparationMode(false);
/*
* 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 (!mcMMOPlayer.getAbilityMode(ability) && !cooldownOver(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
if (skill == SkillType.WOODCUTTING || skill == SkillType.AXES) {
if (!skillManager.getAbilityMode() && !cooldownOver(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired", calculateTimeLeft(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)));
return;
}
}
if (!mcMMOPlayer.getAbilityMode(ability) && cooldownOver(playerProfile.getSkillDATS(ability), ability.getCooldown(), player)) {
int ticks = PerksUtils.handleActivationPerks(player, 2 + (playerProfile.getSkillLevel(type) / AdvancedConfig.getInstance().getAbilityLength()), ability.getMaxTicks());
if (!skillManager.getAbilityMode() && cooldownOver(playerProfile.getSkillDATS(ability), ability.getCooldown(), player)) {
int ticks = PerksUtils.handleActivationPerks(player, 2 + (playerProfile.getSkillLevel(skill) / AdvancedConfig.getInstance().getAbilityLength()), ability.getMaxTicks());
ParticleEffectUtils.playAbilityEnabledEffect(player);
@ -399,7 +406,7 @@ public class SkillUtils {
SkillUtils.sendSkillMessage(player, ability.getAbilityPlayer(player));
playerProfile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
mcMMOPlayer.setAbilityMode(ability, true);
skillManager.setAbilityMode(true);
if (ability == AbilityType.BERSERK) {
player.setCanPickupItems(false);
@ -515,10 +522,10 @@ public class SkillUtils {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
int ticks = 0;
if (mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER)) {
if (mcMMOPlayer.getSkillManager(SkillType.MINING).getAbilityMode()) {
ticks = ((int) (mcMMOPlayer.getProfile().getSkillDATS(AbilityType.SUPER_BREAKER) - System.currentTimeMillis())) / Misc.TIME_CONVERSION_FACTOR;
}
else if (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
else if (mcMMOPlayer.getSkillManager(SkillType.EXCAVATION).getAbilityMode()) {
ticks = ((int) (mcMMOPlayer.getProfile().getSkillDATS(AbilityType.GIGA_DRILL_BREAKER) - System.currentTimeMillis())) / Misc.TIME_CONVERSION_FACTOR;
}