From f388948f04982a016faebd933da05e6fe3d739fc Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 26 Feb 2013 18:06:30 -0500 Subject: [PATCH] Hire an Excavation manager. --- .../nossr50/listeners/BlockListener.java | 8 ++- .../nossr50/skills/SkillManagerStore.java | 10 +++ .../nossr50/skills/excavation/Excavation.java | 64 ++++--------------- .../skills/excavation/ExcavationManager.java | 59 +++++++++++++++++ .../nossr50/skills/utilities/CombatTools.java | 7 +- 5 files changed, 86 insertions(+), 62 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 0224ded51..74dc1dfd5 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -29,7 +29,8 @@ 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.runnables.StickyPistonTracker; -import com.gmail.nossr50.skills.excavation.Excavation; +import com.gmail.nossr50.skills.SkillManagerStore; +import com.gmail.nossr50.skills.excavation.ExcavationManager; import com.gmail.nossr50.skills.herbalism.Herbalism; import com.gmail.nossr50.skills.mining.Mining; import com.gmail.nossr50.skills.repair.Repair; @@ -202,10 +203,11 @@ public class BlockListener implements Listener { /* EXCAVATION */ else if (BlockChecks.affectedByGigaDrillBreaker(blockState) && ItemChecks.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(blockState)) { - Excavation.excavationBlockCheck(blockState, player); + ExcavationManager excavationManager = SkillManagerStore.getInstance().getExcavationManager(player.getName()); + excavationManager.excavationBlockCheck(blockState); if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) { - Excavation.gigaDrillBreaker(blockState, player); + excavationManager.gigaDrillBreaker(blockState); } } diff --git a/src/main/java/com/gmail/nossr50/skills/SkillManagerStore.java b/src/main/java/com/gmail/nossr50/skills/SkillManagerStore.java index 64d391e69..c03b0a483 100644 --- a/src/main/java/com/gmail/nossr50/skills/SkillManagerStore.java +++ b/src/main/java/com/gmail/nossr50/skills/SkillManagerStore.java @@ -5,6 +5,7 @@ import java.util.HashMap; import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; import com.gmail.nossr50.skills.archery.ArcheryManager; import com.gmail.nossr50.skills.axes.AxeManager; +import com.gmail.nossr50.skills.excavation.ExcavationManager; import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.smelting.SmeltingManager; import com.gmail.nossr50.skills.swords.SwordsManager; @@ -18,6 +19,7 @@ public class SkillManagerStore { private HashMap acrobaticsManagers = new HashMap(); private HashMap archeryManagers = new HashMap(); private HashMap axeManagers = new HashMap(); + private HashMap excavationManagers = new HashMap(); private HashMap miningManagers = new HashMap(); private HashMap smeltingManagers = new HashMap(); private HashMap swordsManagers = new HashMap(); @@ -56,6 +58,14 @@ public class SkillManagerStore { return axeManagers.get(playerName); } + public ExcavationManager getExcavationManager(String playerName) { + if (!excavationManagers.containsKey(playerName)) { + excavationManagers.put(playerName, new ExcavationManager(Users.getPlayer(playerName))); + } + + return excavationManagers.get(playerName); + } + public MiningManager getMiningManager(String playerName) { if (!miningManagers.containsKey(playerName)) { miningManagers.put(playerName, new MiningManager(Users.getPlayer(playerName))); diff --git a/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java b/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java index 6d935ca45..5fcfb2556 100644 --- a/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java @@ -3,75 +3,23 @@ package com.gmail.nossr50.skills.excavation; import java.util.ArrayList; import java.util.List; -import org.bukkit.Location; import org.bukkit.block.BlockState; -import org.bukkit.entity.Player; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.TreasuresConfig; -import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; import com.gmail.nossr50.mods.ModChecks; -import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.skills.utilities.SkillType; -import com.gmail.nossr50.util.Misc; -import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.Users; public class Excavation { - /** - * Process treasure drops & XP gain for Excavation. - * - * @param blockState The {@link BlockState} to check ability activation for - * @param player The {@link Player} using this ability - */ - public static void excavationBlockCheck(BlockState blockState, Player player) { - McMMOPlayer mcMMOPlayer = Users.getPlayer(player); - int xp = Config.getInstance().getXp(SkillType.EXCAVATION, blockState.getType()); - - if (xp == 0 && ModChecks.isCustomExcavationBlock(blockState)) { - xp = ModChecks.getCustomBlock(blockState).getXpGain(); - } - - if (Permissions.excavationTreasureHunter(player)) { - List treasures = getTreasures(blockState); - - if (!treasures.isEmpty()) { - int skillLevel = mcMMOPlayer.getProfile().getSkillLevel(SkillType.EXCAVATION); - int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.EXCAVATION); - Location location = blockState.getLocation(); - - for (ExcavationTreasure treasure : treasures) { - if (skillLevel >= treasure.getDropLevel() && Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) { - xp += treasure.getXp(); - Misc.dropItem(location, treasure.getDrop()); - } - } - } - } - - mcMMOPlayer.beginXpGain(SkillType.EXCAVATION, xp); - } - - /** - * Process the Giga Drill Breaker ability. - * - * @param blockState The {@link BlockState} to check ability activation for - * @param player The {@link Player} using this ability - */ - public static void gigaDrillBreaker(BlockState blockState, Player player) { - Excavation.excavationBlockCheck(blockState, player); - Excavation.excavationBlockCheck(blockState, player); - } - /** * Get the list of possible {@link ExcavationTreasure|ExcavationTreasures} obtained from a given block. * * @param blockState The {@link BlockState} of the block to check. * @return the list of treasures that could be found */ - private static List getTreasures(BlockState blockState) { + protected static List getTreasures(BlockState blockState) { switch (blockState.getType()) { case DIRT: return TreasuresConfig.getInstance().excavationFromDirt; @@ -98,4 +46,14 @@ public class Excavation { return new ArrayList(); } } + + protected static int getBlockXP(BlockState blockState) { + int xp = Config.getInstance().getXp(SkillType.EXCAVATION, blockState.getType()); + + if (xp == 0 && ModChecks.isCustomExcavationBlock(blockState)) { + xp = ModChecks.getCustomBlock(blockState).getXpGain(); + } + + return xp; + } } diff --git a/src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java b/src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java new file mode 100644 index 000000000..d47fdc4fc --- /dev/null +++ b/src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java @@ -0,0 +1,59 @@ +package com.gmail.nossr50.skills.excavation; + +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Player; + +import com.gmail.nossr50.datatypes.McMMOPlayer; +import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; +import com.gmail.nossr50.skills.SkillManager; +import com.gmail.nossr50.skills.utilities.SkillType; +import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.Permissions; + +public class ExcavationManager extends SkillManager { + public ExcavationManager(McMMOPlayer mcMMOPlayer) { + super(mcMMOPlayer, SkillType.EXCAVATION); + } + + /** + * Process treasure drops & XP gain for Excavation. + * + * @param blockState The {@link BlockState} to check ability activation for + * @param player The {@link Player} using this ability + */ + public void excavationBlockCheck(BlockState blockState) { + int xp = Excavation.getBlockXP(blockState); + + if (Permissions.excavationTreasureHunter(getPlayer())) { + List treasures = Excavation.getTreasures(blockState); + + if (!treasures.isEmpty()) { + int skillLevel = getSkillLevel(); + Location location = blockState.getLocation(); + + for (ExcavationTreasure treasure : treasures) { + if (skillLevel >= treasure.getDropLevel() && Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) { + xp += treasure.getXp(); + Misc.dropItem(location, treasure.getDrop()); + } + } + } + } + + applyXpGain(xp); + } + + /** + * Process the Giga Drill Breaker ability. + * + * @param blockState The {@link BlockState} to check ability activation for + * @param player The {@link Player} using this ability + */ + public void gigaDrillBreaker(BlockState blockState) { + excavationBlockCheck(blockState); + excavationBlockCheck(blockState); + } +} diff --git a/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java b/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java index 566859c6c..de07ffdf6 100644 --- a/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java +++ b/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java @@ -97,12 +97,7 @@ public final class CombatTools { } } else if (ItemChecks.isAxe(heldItem)) { - if (targetIsPlayer || targetIsTamedPet) { - if (!SkillType.AXES.getPVPEnabled()) { - return; - } - } - else if (!SkillType.AXES.getPVEEnabled()) { + if (((targetIsPlayer || targetIsTamedPet) && !SkillType.AXES.getPVPEnabled()) || (!targetIsPlayer && !targetIsTamedPet && !SkillType.AXES.getPVEEnabled())) { return; }