Browse Source

Hire another manager in charge of Herbalism.

GJ 12 years ago
parent
commit
bbcc8f918e

+ 14 - 10
src/main/java/com/gmail/nossr50/listeners/BlockListener.java

@@ -31,7 +31,7 @@ import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
 import com.gmail.nossr50.runnables.StickyPistonTracker;
 import com.gmail.nossr50.runnables.StickyPistonTracker;
 import com.gmail.nossr50.skills.SkillManagerStore;
 import com.gmail.nossr50.skills.SkillManagerStore;
 import com.gmail.nossr50.skills.excavation.ExcavationManager;
 import com.gmail.nossr50.skills.excavation.ExcavationManager;
-import com.gmail.nossr50.skills.herbalism.Herbalism;
+import com.gmail.nossr50.skills.herbalism.HerbalismManager;
 import com.gmail.nossr50.skills.mining.Mining;
 import com.gmail.nossr50.skills.mining.Mining;
 import com.gmail.nossr50.skills.repair.Repair;
 import com.gmail.nossr50.skills.repair.Repair;
 import com.gmail.nossr50.skills.repair.Salvage;
 import com.gmail.nossr50.skills.repair.Salvage;
@@ -154,8 +154,10 @@ public class BlockListener implements Listener {
 
 
         /* HERBALISM */
         /* HERBALISM */
         if (BlockChecks.affectedByGreenTerra(blockState)) {
         if (BlockChecks.affectedByGreenTerra(blockState)) {
+            HerbalismManager herbalismManager = SkillManagerStore.getInstance().getHerbalismManager(player.getName());
+
             /* Green Terra */
             /* Green Terra */
-            if (profile.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(player)) {
+            if (herbalismManager.canActivateAbility()) {
                 SkillTools.abilityCheck(player, SkillType.HERBALISM);
                 SkillTools.abilityCheck(player, SkillType.HERBALISM);
             }
             }
 
 
@@ -166,11 +168,11 @@ public class BlockListener implements Listener {
             if (Permissions.skillEnabled(player, SkillType.HERBALISM)) {
             if (Permissions.skillEnabled(player, SkillType.HERBALISM)) {
 
 
                 //Double drops
                 //Double drops
-                Herbalism.herbalismBlockCheck(blockState, player);
+                herbalismManager.herbalismBlockCheck(blockState);
 
 
                 //Triple drops
                 //Triple drops
-                if (profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
-                    Herbalism.herbalismBlockCheck(blockState, player);
+                if (herbalismManager.canGreenTerraPlant()) {
+                    herbalismManager.herbalismBlockCheck(blockState);
                 }
                 }
             }
             }
         }
         }
@@ -234,11 +236,12 @@ public class BlockListener implements Listener {
             return;
             return;
         }
         }
 
 
+        String playerName = player.getName();
         BlockState blockState = event.getBlock().getState();
         BlockState blockState = event.getBlock().getState();
         ItemStack heldItem = player.getItemInHand();
         ItemStack heldItem = player.getItemInHand();
 
 
-        if (Permissions.hylianLuck(player) && ItemChecks.isSword(heldItem)) {
-            if (Herbalism.processHylianLuck(blockState, player)) {
+        if (SkillManagerStore.getInstance().getHerbalismManager(playerName).canUseHylianLuck()) {
+            if (SkillManagerStore.getInstance().getHerbalismManager(playerName).processHylianLuck(blockState)) {
                 blockState.update(true);
                 blockState.update(true);
                 event.setCancelled(true);
                 event.setCancelled(true);
             }
             }
@@ -334,6 +337,7 @@ public class BlockListener implements Listener {
             return;
             return;
         }
         }
 
 
+        String playerName = player.getName();
         McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
         McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
         PlayerProfile profile = mcMMOPlayer.getProfile();
         PlayerProfile profile = mcMMOPlayer.getProfile();
         ItemStack heldItem = player.getItemInHand();
         ItemStack heldItem = player.getItemInHand();
@@ -345,9 +349,9 @@ 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.
          * We don't need to check permissions here because they've already been checked for the ability to even activate.
          */
          */
-        if (profile.getAbilityMode(AbilityType.GREEN_TERRA) && BlockChecks.canMakeMossy(blockState)) {
-            if (Herbalism.processGreenTerra(blockState, player)) {
-                blockState.update();
+        if (SkillManagerStore.getInstance().getHerbalismManager(playerName).canGreenTerraBlock(blockState)) {
+            if (SkillManagerStore.getInstance().getHerbalismManager(playerName).processGreenTerra(blockState)) {
+                blockState.update(true);
             }
             }
         }
         }
         else if (profile.getAbilityMode(AbilityType.BERSERK)) {
         else if (profile.getAbilityMode(AbilityType.BERSERK)) {

+ 2 - 2
src/main/java/com/gmail/nossr50/listeners/EntityListener.java

@@ -389,7 +389,7 @@ public class EntityListener implements Listener {
                 case MUSHROOM_SOUP: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
                 case MUSHROOM_SOUP: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
                 case PUMPKIN_PIE:   /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
                 case PUMPKIN_PIE:   /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
                     if (Permissions.farmersDiet(player)) {
                     if (Permissions.farmersDiet(player)) {
-                        event.setFoodLevel(Herbalism.farmersDiet(player, Herbalism.farmersDietRankLevel1, newFoodLevel));
+                        event.setFoodLevel(SkillManagerStore.getInstance().getHerbalismManager(player.getName()).farmersDiet(Herbalism.farmersDietRankLevel1, newFoodLevel));
                     }
                     }
                     return;
                     return;
 
 
@@ -398,7 +398,7 @@ public class EntityListener implements Listener {
                 case POISONOUS_POTATO:  /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
                 case POISONOUS_POTATO:  /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
                 case POTATO_ITEM:       /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
                 case POTATO_ITEM:       /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
                     if (Permissions.farmersDiet(player)) {
                     if (Permissions.farmersDiet(player)) {
-                        event.setFoodLevel(Herbalism.farmersDiet(player, Herbalism.farmersDietRankLevel2, newFoodLevel));
+                        event.setFoodLevel(SkillManagerStore.getInstance().getHerbalismManager(player.getName()).farmersDiet(Herbalism.farmersDietRankLevel2, newFoodLevel));
                     }
                     }
                     return;
                     return;
 
 

+ 7 - 5
src/main/java/com/gmail/nossr50/listeners/PlayerListener.java

@@ -35,7 +35,7 @@ import com.gmail.nossr50.party.Party;
 import com.gmail.nossr50.party.ShareHandler;
 import com.gmail.nossr50.party.ShareHandler;
 import com.gmail.nossr50.skills.SkillManagerStore;
 import com.gmail.nossr50.skills.SkillManagerStore;
 import com.gmail.nossr50.skills.fishing.FishingManager;
 import com.gmail.nossr50.skills.fishing.FishingManager;
-import com.gmail.nossr50.skills.herbalism.Herbalism;
+import com.gmail.nossr50.skills.herbalism.HerbalismManager;
 import com.gmail.nossr50.skills.mining.BlastMining;
 import com.gmail.nossr50.skills.mining.BlastMining;
 import com.gmail.nossr50.skills.repair.Repair;
 import com.gmail.nossr50.skills.repair.Repair;
 import com.gmail.nossr50.skills.repair.Salvage;
 import com.gmail.nossr50.skills.repair.Salvage;
@@ -354,17 +354,19 @@ public class PlayerListener implements Listener {
             }
             }
 
 
             /* GREEN THUMB CHECK */
             /* GREEN THUMB CHECK */
-            if (heldItem.getType() == Material.SEEDS && BlockChecks.canMakeMossy(blockState)) {
+            HerbalismManager herbalismManager = SkillManagerStore.getInstance().getHerbalismManager(player.getName());
+
+            if (herbalismManager.canGreenThumbBlock(blockState)) {
                 player.setItemInHand(new ItemStack(Material.SEEDS, heldItem.getAmount() - 1));
                 player.setItemInHand(new ItemStack(Material.SEEDS, heldItem.getAmount() - 1));
 
 
-                if (Herbalism.processGreenThumbBlocks(blockState, player) && SkillTools.blockBreakSimulate(block, player, false)) {
+                if (herbalismManager.processGreenThumbBlocks(blockState) && SkillTools.blockBreakSimulate(block, player, false)) {
                     blockState.update(true);
                     blockState.update(true);
                 }
                 }
             }
             }
 
 
             /* SHROOM THUMB CHECK */
             /* SHROOM THUMB CHECK */
-            else if ((heldItem.getType() == Material.RED_MUSHROOM || heldItem.getType() == Material.BROWN_MUSHROOM) && BlockChecks.canMakeShroomy(blockState)) {
-                if (Herbalism.processShroomThumb(blockState, player) && SkillTools.blockBreakSimulate(block, player, false)) {
+            else if (herbalismManager.canUseShroomThumb(blockState)) {
+                if (herbalismManager.processShroomThumb(blockState) && SkillTools.blockBreakSimulate(block, player, false)) {
                     blockState.update(true);
                     blockState.update(true);
                 }
                 }
             }
             }

+ 10 - 0
src/main/java/com/gmail/nossr50/skills/SkillManagerStore.java

@@ -7,6 +7,7 @@ import com.gmail.nossr50.skills.archery.ArcheryManager;
 import com.gmail.nossr50.skills.axes.AxeManager;
 import com.gmail.nossr50.skills.axes.AxeManager;
 import com.gmail.nossr50.skills.excavation.ExcavationManager;
 import com.gmail.nossr50.skills.excavation.ExcavationManager;
 import com.gmail.nossr50.skills.fishing.FishingManager;
 import com.gmail.nossr50.skills.fishing.FishingManager;
+import com.gmail.nossr50.skills.herbalism.HerbalismManager;
 import com.gmail.nossr50.skills.mining.MiningManager;
 import com.gmail.nossr50.skills.mining.MiningManager;
 import com.gmail.nossr50.skills.smelting.SmeltingManager;
 import com.gmail.nossr50.skills.smelting.SmeltingManager;
 import com.gmail.nossr50.skills.swords.SwordsManager;
 import com.gmail.nossr50.skills.swords.SwordsManager;
@@ -22,6 +23,7 @@ public class SkillManagerStore {
     private HashMap<String, AxeManager> axeManagers = new HashMap<String, AxeManager>();
     private HashMap<String, AxeManager> axeManagers = new HashMap<String, AxeManager>();
     private HashMap<String, ExcavationManager> excavationManagers = new HashMap<String, ExcavationManager>();
     private HashMap<String, ExcavationManager> excavationManagers = new HashMap<String, ExcavationManager>();
     private HashMap<String, FishingManager> fishingManagers = new HashMap<String, FishingManager>();
     private HashMap<String, FishingManager> fishingManagers = new HashMap<String, FishingManager>();
+    private HashMap<String, HerbalismManager> herbalismManagers = new HashMap<String, HerbalismManager>();
     private HashMap<String, MiningManager> miningManagers = new HashMap<String, MiningManager>();
     private HashMap<String, MiningManager> miningManagers = new HashMap<String, MiningManager>();
     private HashMap<String, SmeltingManager> smeltingManagers = new HashMap<String, SmeltingManager>();
     private HashMap<String, SmeltingManager> smeltingManagers = new HashMap<String, SmeltingManager>();
     private HashMap<String, SwordsManager> swordsManagers = new HashMap<String, SwordsManager>();
     private HashMap<String, SwordsManager> swordsManagers = new HashMap<String, SwordsManager>();
@@ -76,6 +78,14 @@ public class SkillManagerStore {
         return fishingManagers.get(playerName);
         return fishingManagers.get(playerName);
     }
     }
 
 
+    public HerbalismManager getHerbalismManager(String playerName) {
+        if (!herbalismManagers.containsKey(playerName)) {
+            herbalismManagers.put(playerName, new HerbalismManager(Users.getPlayer(playerName)));
+        }
+ 
+        return herbalismManagers.get(playerName);
+    }
+
     public MiningManager getMiningManager(String playerName) {
     public MiningManager getMiningManager(String playerName) {
         if (!miningManagers.containsKey(playerName)) {
         if (!miningManagers.containsKey(playerName)) {
             miningManagers.put(playerName, new MiningManager(Users.getPlayer(playerName)));
             miningManagers.put(playerName, new MiningManager(Users.getPlayer(playerName)));

+ 4 - 267
src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java

@@ -1,33 +1,12 @@
 package com.gmail.nossr50.skills.herbalism;
 package com.gmail.nossr50.skills.herbalism;
 
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.bukkit.Location;
 import org.bukkit.Material;
 import org.bukkit.Material;
 import org.bukkit.block.Block;
 import org.bukkit.block.Block;
 import org.bukkit.block.BlockFace;
 import org.bukkit.block.BlockFace;
 import org.bukkit.block.BlockState;
 import org.bukkit.block.BlockState;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.PlayerInventory;
 
 
 import com.gmail.nossr50.mcMMO;
 import com.gmail.nossr50.mcMMO;
 import com.gmail.nossr50.config.AdvancedConfig;
 import com.gmail.nossr50.config.AdvancedConfig;
-import com.gmail.nossr50.config.Config;
-import com.gmail.nossr50.config.TreasuresConfig;
-import com.gmail.nossr50.datatypes.PlayerProfile;
-import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
-import com.gmail.nossr50.locale.LocaleLoader;
-import com.gmail.nossr50.mods.ModChecks;
-import com.gmail.nossr50.mods.datatypes.CustomBlock;
-import com.gmail.nossr50.skills.utilities.AbilityType;
-import com.gmail.nossr50.skills.utilities.SkillTools;
-import com.gmail.nossr50.skills.utilities.SkillType;
-import com.gmail.nossr50.util.Misc;
-import com.gmail.nossr50.util.Permissions;
-import com.gmail.nossr50.util.StringUtils;
-import com.gmail.nossr50.util.Users;
 
 
 public class Herbalism {
 public class Herbalism {
     public static int farmersDietRankLevel1 = AdvancedConfig.getInstance().getFarmerDietRankChange();
     public static int farmersDietRankLevel1 = AdvancedConfig.getInstance().getFarmerDietRankChange();
@@ -49,54 +28,14 @@ public class Herbalism {
     public static double shroomThumbMaxChance = AdvancedConfig.getInstance().getShroomThumbChanceMax();
     public static double shroomThumbMaxChance = AdvancedConfig.getInstance().getShroomThumbChanceMax();
     public static int shroomThumbMaxLevel = AdvancedConfig.getInstance().getShroomThumbMaxLevel();
     public static int shroomThumbMaxLevel = AdvancedConfig.getInstance().getShroomThumbMaxLevel();
 
 
-    /**
-     * Handle the farmers diet skill.
-     *
-     * @param player The player to activate the skill for
-     * @param rankChange The # of levels to change rank for the food
-     * @param event The actual FoodLevelChange event
-     */
-    public static int farmersDiet(Player player, int rankChange, int eventFoodLevel) {
-        return SkillTools.handleFoodSkills(player, SkillType.HERBALISM, eventFoodLevel, farmersDietRankLevel1, farmersDietMaxLevel, rankChange);
-    }
-
-    /**
-     * Process the Green Terra ability.
-     *
-     * @param blockState The {@link BlockState} to check ability activation for
-     * @param player The {@link Player} using this ability
-     * @return true if the ability was successful, false otherwise
-     */
-    public static boolean processGreenTerra(BlockState blockState, Player player) {
-        PlayerInventory playerInventory = player.getInventory();
-        ItemStack seed = new ItemStack(Material.SEEDS);
-
-        if (!playerInventory.containsAtLeast(seed, 1)) {
-            player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
-            return false;
-        }
-
-        playerInventory.removeItem(seed);
-        player.updateInventory(); // Needed until replacement available
-
-        return convertGreenTerraBlocks(blockState, player);
-    }
-
     /**
     /**
      * Convert blocks affected by the Green Thumb & Green Terra abilities.
      * Convert blocks affected by the Green Thumb & Green Terra abilities.
      *
      *
      * @param blockState The {@link BlockState} to check ability activation for
      * @param blockState The {@link BlockState} to check ability activation for
-     * @param player The {@link Player} using this ability
      * @return true if the ability was successful, false otherwise
      * @return true if the ability was successful, false otherwise
      */
      */
-    private static boolean convertGreenTerraBlocks(BlockState blockState, Player player) {
-        Material blockType = blockState.getType();
-
-        if (!Permissions.greenThumbBlock(player, blockType)) {
-            return false;
-        }
-
-        switch (blockType) {
+    protected static boolean convertGreenTerraBlocks(BlockState blockState) {
+        switch (blockState.getType()) {
         case COBBLE_WALL:
         case COBBLE_WALL:
         case SMOOTH_BRICK:
         case SMOOTH_BRICK:
             blockState.setRawData((byte) 0x1);
             blockState.setRawData((byte) 0x1);
@@ -121,7 +60,7 @@ public class Herbalism {
      * @param blockState The {@link BlockState} of the bottom block of the plant
      * @param blockState The {@link BlockState} of the bottom block of the plant
      * @return the number of bonus drops to award from the blocks in this plant
      * @return the number of bonus drops to award from the blocks in this plant
      */
      */
-    private static int calculateCatciAndSugarDrops(BlockState blockState) {
+    protected static int calculateCatciAndSugarDrops(BlockState blockState) {
         Block block = blockState.getBlock();
         Block block = blockState.getBlock();
         Material blockType = blockState.getType();
         Material blockType = blockState.getType();
         int dropAmount = 0;
         int dropAmount = 0;
@@ -149,215 +88,13 @@ public class Herbalism {
         return dropAmount;
         return dropAmount;
     }
     }
 
 
-    /**
-     * Process double drops & XP gain for Herbalism.
-     *
-     * @param blockState The {@link BlockState} to check ability activation for
-     * @param player The {@link Player} using this ability
-     * @return true if the ability was successful, false otherwise
-     */
-    public static void herbalismBlockCheck(BlockState blockState, Player player) {
-        if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle()) {
-            return;
-        }
-
-        Material blockType = blockState.getType();
-
-        HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(blockType);
-        CustomBlock customBlock = null;
-
-        int xp = 0;
-        int dropAmount = 1;
-        ItemStack dropItem = null;
-
-        if (herbalismBlock != null) {
-            if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) {
-                dropItem = herbalismBlock.getDropItem();
-                dropAmount = calculateCatciAndSugarDrops(blockState);
-                xp = herbalismBlock.getXpGain() * dropAmount;
-            }
-            else if (herbalismBlock.hasGreenThumbPermission(player)){
-                dropItem = herbalismBlock.getDropItem();
-                xp = herbalismBlock.getXpGain();
-                processGreenThumbPlants(blockState, player);
-            }
-            else {
-                if (!mcMMO.placeStore.isTrue(blockState)) {
-                    dropItem = herbalismBlock.getDropItem();
-                    xp = herbalismBlock.getXpGain();
-                }
-            }
-        }
-        else {
-            customBlock = ModChecks.getCustomBlock(blockState);
-            dropItem = customBlock.getItemDrop();
-            xp = customBlock.getXpGain();
-        }
-
-        if (Permissions.doubleDrops(player, SkillType.HERBALISM) && SkillTools.activationSuccessful(player, SkillType.HERBALISM, doubleDropsMaxChance, doubleDropsMaxLevel)) {
-            Location location = blockState.getLocation();
-
-            if (dropItem != null && herbalismBlock != null && herbalismBlock.canDoubleDrop()) {
-                Misc.dropItems(location, dropItem, dropAmount);
-            }
-            else if (customBlock != null){
-                int minimumDropAmount = customBlock.getMinimumDropAmount();
-                int maximumDropAmount = customBlock.getMaximumDropAmount();
-
-                if (minimumDropAmount != maximumDropAmount) {
-                    Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
-                }
-
-                Misc.dropItems(location, dropItem, minimumDropAmount);
-            }
-        }
-
-        Users.getPlayer(player).beginXpGain(SkillType.HERBALISM, xp);
-    }
-
-    /**
-     * Process the Green Thumb ability for blocks.
-     *
-     * @param blockState The {@link BlockState} to check ability activation for
-     * @param player The {@link Player} using this ability
-     * @return true if the ability was successful, false otherwise
-     */
-    public static boolean processGreenThumbBlocks(BlockState blockState, Player player) {
-        if (!SkillTools.activationSuccessful(player, SkillType.HERBALISM, greenThumbMaxChance, greenThumbMaxLevel)) {
-            player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
-            return false;
-        }
-
-        return convertGreenTerraBlocks(blockState, player);
-    }
-
-    /**
-     * Process the Green Thumb ability for plants.
-     *
-     * @param blockState The {@link BlockState} to check ability activation for
-     * @param player The {@link Player} using this ability
-     */
-    private static void processGreenThumbPlants(BlockState blockState, Player player) {
-        PlayerInventory playerInventory = player.getInventory();
-        ItemStack seed = HerbalismBlock.getHerbalismBlock(blockState.getType()).getDropItem();
-
-        if (!playerInventory.containsAtLeast(seed, 1)) {
-            return;
-        }
-
-        PlayerProfile playerProfile = Users.getPlayer(player).getProfile();
-
-        if (playerProfile.getAbilityMode(AbilityType.GREEN_TERRA)) {
-            playerInventory.removeItem(seed);
-            player.updateInventory(); // Needed until replacement available
-
-            mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GreenTerraTimer(blockState), 0);
-            return;
-        }
-        else if (SkillTools.activationSuccessful(player, SkillType.HERBALISM, greenThumbMaxChance, greenThumbMaxLevel)) {
-            playerInventory.removeItem(seed);
-            player.updateInventory(); // Needed until replacement available
-
-            mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GreenThumbTimer(blockState, playerProfile.getSkillLevel(SkillType.HERBALISM)), 0);
-            return;
-        }
-    }
-
-    /**
-     * Process the Hylian Luck ability.
-     *
-     * @param blockState The {@link BlockState} to check ability activation for
-     * @param player The {@link Player} using this ability
-     * @return true if the ability was successful, false otherwise
-     */
-    public static boolean processHylianLuck(BlockState blockState, Player player) {
-        if (!SkillTools.activationSuccessful(player, SkillType.HERBALISM, hylianLuckMaxChance, hylianLuckMaxLevel)) {
-            return false;
-        }
-
-        List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
-
-        switch (blockState.getType()) {
-        case DEAD_BUSH:
-        case LONG_GRASS:
-        case SAPLING:
-            treasures = TreasuresConfig.getInstance().hylianFromBushes;
-            break;
-
-        case RED_ROSE:
-        case YELLOW_FLOWER:
-            if (mcMMO.placeStore.isTrue(blockState)) {
-                mcMMO.placeStore.setFalse(blockState);
-                return false;
-            }
-
-            treasures = TreasuresConfig.getInstance().hylianFromFlowers;
-            break;
-
-        case FLOWER_POT:
-            treasures = TreasuresConfig.getInstance().hylianFromPots;
-            break;
-
-        default:
-            return false;
-        }
-
-        if (treasures.isEmpty()) {
-            return false;
-        }
-
-        blockState.setRawData((byte) 0x0);
-        blockState.setType(Material.AIR);
-
-        Misc.dropItem(blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
-        player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
-        return true;
-    }
-
-    /**
-     * Process the Shroom Thumb ability.
-     *
-     * @param blockState The {@link BlockState} to check ability activation for
-     * @param player The {@link Player} using this ability
-     * @return true if the ability was successful, false otherwise
-     */
-    public static boolean processShroomThumb(BlockState blockState, Player player) {
-        PlayerInventory playerInventory = player.getInventory();
-
-        if (!playerInventory.contains(Material.BROWN_MUSHROOM)) {
-            player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.BROWN_MUSHROOM)));
-            return false;
-        }
-
-        if (!playerInventory.contains(Material.RED_MUSHROOM)) {
-            player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.RED_MUSHROOM)));
-            return false;
-        }
-
-        playerInventory.removeItem(new ItemStack(Material.BROWN_MUSHROOM));
-        playerInventory.removeItem(new ItemStack(Material.RED_MUSHROOM));
-        player.updateInventory();
-
-        if (!SkillTools.activationSuccessful(player, SkillType.HERBALISM, shroomThumbMaxChance, shroomThumbMaxLevel)) {
-            player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Fail"));
-            return false;
-        }
-
-        return convertShroomThumb(blockState, player);
-    }
-
     /**
     /**
      * Convert blocks affected by the Green Thumb & Green Terra abilities.
      * Convert blocks affected by the Green Thumb & Green Terra abilities.
      *
      *
      * @param blockState The {@link BlockState} to check ability activation for
      * @param blockState The {@link BlockState} to check ability activation for
-     * @param player The {@link Player} using this ability
      * @return true if the ability was successful, false otherwise
      * @return true if the ability was successful, false otherwise
      */
      */
-    private static boolean convertShroomThumb(BlockState blockState, Player player) {
-        if (!Permissions.shroomThumb(player)) {
-            return false;
-        }
-
+    protected static boolean convertShroomThumb(BlockState blockState) {
         switch (blockState.getType()){
         switch (blockState.getType()){
         case DIRT:
         case DIRT:
         case GRASS:
         case GRASS:

+ 306 - 0
src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java

@@ -0,0 +1,306 @@
+package com.gmail.nossr50.skills.herbalism;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.BlockState;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.PlayerInventory;
+
+import com.gmail.nossr50.mcMMO;
+import com.gmail.nossr50.config.Config;
+import com.gmail.nossr50.config.TreasuresConfig;
+import com.gmail.nossr50.datatypes.McMMOPlayer;
+import com.gmail.nossr50.datatypes.PlayerProfile;
+import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
+import com.gmail.nossr50.locale.LocaleLoader;
+import com.gmail.nossr50.mods.ModChecks;
+import com.gmail.nossr50.mods.datatypes.CustomBlock;
+import com.gmail.nossr50.skills.SkillManager;
+import com.gmail.nossr50.skills.utilities.AbilityType;
+import com.gmail.nossr50.skills.utilities.SkillTools;
+import com.gmail.nossr50.skills.utilities.SkillType;
+import com.gmail.nossr50.skills.utilities.ToolType;
+import com.gmail.nossr50.util.BlockChecks;
+import com.gmail.nossr50.util.ItemChecks;
+import com.gmail.nossr50.util.Misc;
+import com.gmail.nossr50.util.Permissions;
+import com.gmail.nossr50.util.StringUtils;
+import com.gmail.nossr50.util.Users;
+
+public class HerbalismManager extends SkillManager {
+    public HerbalismManager(McMMOPlayer mcMMOPlayer) {
+        super(mcMMOPlayer, SkillType.HERBALISM);
+    }
+
+    public boolean canBlockCheck() {
+        return !(Config.getInstance().getHerbalismAFKDisabled() && getPlayer().isInsideVehicle());
+    }
+
+    public boolean canGreenThumbBlock(BlockState blockState) {
+        Player player = getPlayer();
+
+        return player.getItemInHand().getType() == Material.SEEDS && BlockChecks.canMakeMossy(blockState) && Permissions.greenThumbBlock(player, blockState.getType());
+    }
+
+    public boolean canUseShroomThumb(BlockState blockState) {
+        Player player = getPlayer();
+        Material itemType = player.getItemInHand().getType();
+
+        return (itemType == Material.RED_MUSHROOM || itemType == Material.BROWN_MUSHROOM) && BlockChecks.canMakeShroomy(blockState) && Permissions.shroomThumb(player);
+    }
+
+    public boolean canUseHylianLuck() {
+        Player player = getPlayer();
+
+        return ItemChecks.isSword(player.getItemInHand()) && Permissions.hylianLuck(player);
+    }
+
+    public boolean canGreenTerraBlock(BlockState blockState) {
+        return getProfile().getAbilityMode(AbilityType.GREEN_TERRA) && BlockChecks.canMakeMossy(blockState);
+    }
+
+    public boolean canActivateAbility() {
+        return getProfile().getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(getPlayer());
+    }
+
+    public boolean canGreenTerraPlant() {
+        return getProfile().getAbilityMode(AbilityType.GREEN_TERRA);
+    }
+
+    /**
+     * Handle the Farmer's Diet ability
+     *
+     * @param rankChange The # of levels to change rank for the food
+     * @param eventFoodLevel The initial change in hunger from the event
+     * @return the modified change in hunger for the event
+     */
+    public int farmersDiet(int rankChange, int eventFoodLevel) {
+        return SkillTools.handleFoodSkills(getPlayer(), SkillType.HERBALISM, eventFoodLevel, Herbalism.farmersDietRankLevel1, Herbalism.farmersDietMaxLevel, rankChange);
+    }
+
+    /**
+     * Process the Green Terra ability.
+     *
+     * @param blockState The {@link BlockState} to check ability activation for
+     * @return true if the ability was successful, false otherwise
+     */
+    public boolean processGreenTerra(BlockState blockState) {
+        Player player = getPlayer();
+
+        if (!Permissions.greenThumbBlock(player, blockState.getType())) {
+            return false;
+        }
+
+        PlayerInventory playerInventory = player.getInventory();
+        ItemStack seed = new ItemStack(Material.SEEDS);
+
+        if (!playerInventory.containsAtLeast(seed, 1)) {
+            player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
+            return false;
+        }
+
+        playerInventory.removeItem(seed);
+        player.updateInventory(); // Needed until replacement available
+
+        return Herbalism.convertGreenTerraBlocks(blockState);
+    }
+
+    /**
+     * Process double drops & XP gain for Herbalism.
+     *
+     * @param blockState The {@link BlockState} to check ability activation for
+     * @return true if the ability was successful, false otherwise
+     */
+    public void herbalismBlockCheck(BlockState blockState) {
+        Player player = getPlayer();
+        Material blockType = blockState.getType();
+
+        HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(blockType);
+        CustomBlock customBlock = null;
+
+        int xp = 0;
+        int dropAmount = 1;
+        ItemStack dropItem = null;
+
+        if (herbalismBlock != null) {
+            if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) {
+                dropItem = herbalismBlock.getDropItem();
+                dropAmount = Herbalism.calculateCatciAndSugarDrops(blockState);
+                xp = herbalismBlock.getXpGain() * dropAmount;
+            }
+            else if (herbalismBlock.hasGreenThumbPermission(player)){
+                dropItem = herbalismBlock.getDropItem();
+                xp = herbalismBlock.getXpGain();
+                processGreenThumbPlants(blockState);
+            }
+            else {
+                if (!mcMMO.placeStore.isTrue(blockState)) {
+                    dropItem = herbalismBlock.getDropItem();
+                    xp = herbalismBlock.getXpGain();
+                }
+            }
+        }
+        else {
+            customBlock = ModChecks.getCustomBlock(blockState);
+            dropItem = customBlock.getItemDrop();
+            xp = customBlock.getXpGain();
+        }
+
+        if (Permissions.doubleDrops(player, skill) && SkillTools.activationSuccessful(player, skill, Herbalism.doubleDropsMaxChance, Herbalism.doubleDropsMaxLevel)) {
+            Location location = blockState.getLocation();
+
+            if (dropItem != null && herbalismBlock != null && herbalismBlock.canDoubleDrop()) {
+                Misc.dropItems(location, dropItem, dropAmount);
+            }
+            else if (customBlock != null){
+                int minimumDropAmount = customBlock.getMinimumDropAmount();
+                int maximumDropAmount = customBlock.getMaximumDropAmount();
+
+                if (minimumDropAmount != maximumDropAmount) {
+                    Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
+                }
+
+                Misc.dropItems(location, dropItem, minimumDropAmount);
+            }
+        }
+
+        applyXpGain(xp);
+    }
+
+    /**
+     * Process the Green Thumb ability for blocks.
+     *
+     * @param blockState The {@link BlockState} to check ability activation for
+     * @return true if the ability was successful, false otherwise
+     */
+    public boolean processGreenThumbBlocks(BlockState blockState) {
+        Player player = getPlayer();
+
+        if (!SkillTools.activationSuccessful(player, skill, Herbalism.greenThumbMaxChance, Herbalism.greenThumbMaxLevel)) {
+            player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
+            return false;
+        }
+
+        return Herbalism.convertGreenTerraBlocks(blockState);
+    }
+
+    /**
+     * Process the Hylian Luck ability.
+     *
+     * @param blockState The {@link BlockState} to check ability activation for
+     * @return true if the ability was successful, false otherwise
+     */
+    public boolean processHylianLuck(BlockState blockState) {
+        Player player = getPlayer();
+
+        if (!SkillTools.activationSuccessful(player, skill, Herbalism.hylianLuckMaxChance, Herbalism.hylianLuckMaxLevel)) {
+            return false;
+        }
+
+        List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
+
+        switch (blockState.getType()) {
+        case DEAD_BUSH:
+        case LONG_GRASS:
+        case SAPLING:
+            treasures = TreasuresConfig.getInstance().hylianFromBushes;
+            break;
+
+        case RED_ROSE:
+        case YELLOW_FLOWER:
+            if (mcMMO.placeStore.isTrue(blockState)) {
+                mcMMO.placeStore.setFalse(blockState);
+                return false;
+            }
+
+            treasures = TreasuresConfig.getInstance().hylianFromFlowers;
+            break;
+
+        case FLOWER_POT:
+            treasures = TreasuresConfig.getInstance().hylianFromPots;
+            break;
+
+        default:
+            return false;
+        }
+
+        if (treasures.isEmpty()) {
+            return false;
+        }
+
+        blockState.setRawData((byte) 0x0);
+        blockState.setType(Material.AIR);
+
+        Misc.dropItem(blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
+        player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
+        return true;
+    }
+
+    /**
+     * Process the Shroom Thumb ability.
+     *
+     * @param blockState The {@link BlockState} to check ability activation for
+     * @return true if the ability was successful, false otherwise
+     */
+    public boolean processShroomThumb(BlockState blockState) {
+        Player player = getPlayer();
+        PlayerInventory playerInventory = player.getInventory();
+
+        if (!playerInventory.contains(Material.BROWN_MUSHROOM)) {
+            player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.BROWN_MUSHROOM)));
+            return false;
+        }
+
+        if (!playerInventory.contains(Material.RED_MUSHROOM)) {
+            player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.RED_MUSHROOM)));
+            return false;
+        }
+
+        playerInventory.removeItem(new ItemStack(Material.BROWN_MUSHROOM));
+        playerInventory.removeItem(new ItemStack(Material.RED_MUSHROOM));
+        player.updateInventory();
+
+        if (!SkillTools.activationSuccessful(player, skill, Herbalism.shroomThumbMaxChance, Herbalism.shroomThumbMaxLevel)) {
+            player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Fail"));
+            return false;
+        }
+
+        return Herbalism.convertShroomThumb(blockState);
+    }
+
+    /**
+     * Process the Green Thumb ability for plants.
+     *
+     * @param blockState The {@link BlockState} to check ability activation for
+     */
+    private void processGreenThumbPlants(BlockState blockState) {
+        Player player = getPlayer();
+        PlayerInventory playerInventory = player.getInventory();
+        ItemStack seed = HerbalismBlock.getHerbalismBlock(blockState.getType()).getDropItem();
+
+        if (!playerInventory.containsAtLeast(seed, 1)) {
+            return;
+        }
+
+        PlayerProfile playerProfile = Users.getPlayer(player).getProfile();
+
+        if (playerProfile.getAbilityMode(AbilityType.GREEN_TERRA)) {
+            playerInventory.removeItem(seed);
+            player.updateInventory(); // Needed until replacement available
+
+            mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GreenTerraTimer(blockState), 0);
+            return;
+        }
+        else if (SkillTools.activationSuccessful(player, skill, Herbalism.greenThumbMaxChance, Herbalism.greenThumbMaxLevel)) {
+            playerInventory.removeItem(seed);
+            player.updateInventory(); // Needed until replacement available
+
+            mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GreenThumbTimer(blockState, getSkillLevel()), 0);
+            return;
+        }
+    }
+}