From 12b548bf46595ce1e49b09ca56209b547705256c Mon Sep 17 00:00:00 2001 From: bm01 Date: Sun, 3 Mar 2013 23:27:51 +0100 Subject: [PATCH] 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. --- .../com/gmail/nossr50/api/AbilityAPI.java | 21 ++-- .../nossr50/datatypes/player/McMMOPlayer.java | 115 ++---------------- .../nossr50/datatypes/skills/SkillType.java | 10 +- .../gmail/nossr50/datatypes/skills/Tool.java | 44 +++++++ .../nossr50/listeners/BlockListener.java | 27 ++-- .../nossr50/listeners/PlayerListener.java | 3 +- .../runnables/skills/SkillMonitorTask.java | 18 ++- .../gmail/nossr50/skills/SkillManager.java | 25 ++++ .../nossr50/skills/axes/AxesManager.java | 6 +- .../skills/herbalism/HerbalismManager.java | 10 +- .../nossr50/skills/mining/MiningManager.java | 2 +- .../nossr50/skills/swords/SwordsManager.java | 6 +- .../skills/unarmed/UnarmedManager.java | 6 +- .../gmail/nossr50/util/skills/SkillUtils.java | 79 ++++++------ 14 files changed, 174 insertions(+), 198 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/datatypes/skills/Tool.java diff --git a/src/main/java/com/gmail/nossr50/api/AbilityAPI.java b/src/main/java/com/gmail/nossr50/api/AbilityAPI.java index 52743f42e..c4144ca67 100644 --- a/src/main/java/com/gmail/nossr50/api/AbilityAPI.java +++ b/src/main/java/com/gmail/nossr50/api/AbilityAPI.java @@ -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; } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index f1d4d4c90..bc7de14bc 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -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 abilityMode = new HashMap(); - private Map abilityInformed = new HashMap(); - private Map toolPreparationMode = new HashMap(); - private Map toolATS = new HashMap(); - 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 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 */ diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java b/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java index 565ee66de..b6a1e5770 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java @@ -34,18 +34,18 @@ public enum SkillType { private Class managerClass; private AbilityType ability; - private ToolType tool; + private ToolType toolType; private SkillType(Class managerClass) { this.managerClass = managerClass; ability = null; - tool = null; + toolType = null; } private SkillType(Class managerClass, AbilityType ability, ToolType tool) { this.managerClass = managerClass; this.ability = ability; - this.tool = tool; + this.toolType = tool; } public Class 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() { diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/Tool.java b/src/main/java/com/gmail/nossr50/datatypes/skills/Tool.java new file mode 100644 index 000000000..2a0ab605c --- /dev/null +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/Tool.java @@ -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 tools = new HashMap(); + 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; + } +} diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 5274d8ca0..9e206dcad 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -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)); diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 76760c682..734ba52d2 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -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; } diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/SkillMonitorTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/SkillMonitorTask.java index dffbba9ca..4cd3c5c8e 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/SkillMonitorTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/SkillMonitorTask.java @@ -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) { + if (skill.getAbility() == null) { + continue; + } + + if (skill.getToolType() != null) { SkillUtils.monitorSkill(mcMMOPlayer, curTime, skill); } - } - /* - * COOLDOWN MONITORING - */ - for (AbilityType ability : AbilityType.values()) { - if (ability.getCooldown() > 0) { - SkillUtils.watchCooldown(mcMMOPlayer, ability); + if (skill.getAbility().getCooldown() > 0) { + SkillUtils.watchCooldown(mcMMOPlayer, skill); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/SkillManager.java b/src/main/java/com/gmail/nossr50/skills/SkillManager.java index 8595b0929..1853ef507 100644 --- a/src/main/java/com/gmail/nossr50/skills/SkillManager.java +++ b/src/main/java/com/gmail/nossr50/skills/SkillManager.java @@ -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; + } } diff --git a/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java b/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java index f579307a7..ecf6096e5 100644 --- a/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java +++ b/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java @@ -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()); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 4f6171589..e26d6b85e 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -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 diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index 80b51025f..dbe94add1 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -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; } /** diff --git a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java index f60fb0c3b..f4be621cc 100644 --- a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java @@ -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()); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java index f86fec269..7c161ab5e 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java @@ -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) { diff --git a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java index 251b7574a..fe1d5d4a8 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java @@ -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; }