2012-05-01 19:58:47 +02:00
|
|
|
package com.gmail.nossr50.skills.gathering;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-03-13 08:00:49 +01:00
|
|
|
import org.bukkit.CropState;
|
2013-01-08 17:31:07 +01:00
|
|
|
import org.bukkit.DyeColor;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.block.BlockBreakEvent;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-02-24 07:02:23 +01:00
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
2012-12-25 07:01:10 +01:00
|
|
|
import org.bukkit.material.MaterialData;
|
2012-02-24 07:02:23 +01:00
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-01-02 01:27:50 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2012-04-26 16:27:57 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2012-05-17 06:24:33 +02:00
|
|
|
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
|
2012-03-27 08:33:35 +02:00
|
|
|
import com.gmail.nossr50.datatypes.AbilityType;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2012-06-25 15:39:02 +02:00
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2012-03-11 04:21:53 +01:00
|
|
|
import com.gmail.nossr50.runnables.GreenThumbTimer;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2012-05-17 06:24:33 +02:00
|
|
|
import com.gmail.nossr50.util.ModChecks;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2012-05-01 19:58:47 +02:00
|
|
|
import com.gmail.nossr50.util.Skills;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-03-10 19:03:31 +01:00
|
|
|
public class Herbalism {
|
2013-01-02 01:27:50 +01:00
|
|
|
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
2012-03-26 17:04:17 +02:00
|
|
|
|
2012-03-10 19:03:31 +01:00
|
|
|
/**
|
|
|
|
* Activate the Green Terra ability.
|
|
|
|
*
|
|
|
|
* @param player The player activating the ability
|
|
|
|
* @param block The block to be changed by Green Terra
|
|
|
|
*/
|
|
|
|
public static void greenTerra(Player player, Block block) {
|
|
|
|
PlayerInventory inventory = player.getInventory();
|
|
|
|
boolean hasSeeds = inventory.contains(Material.SEEDS);
|
|
|
|
|
|
|
|
if (!hasSeeds) {
|
2013-01-17 17:02:55 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
else if (hasSeeds && !block.getType().equals(Material.WHEAT)) {
|
2012-03-16 18:45:30 +01:00
|
|
|
inventory.removeItem(new ItemStack(Material.SEEDS));
|
2012-05-15 06:49:19 +02:00
|
|
|
player.updateInventory(); // Needed until replacement available
|
2012-04-29 05:22:17 +02:00
|
|
|
greenTerraConvert(player, block);
|
|
|
|
}
|
|
|
|
}
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2012-04-29 05:22:17 +02:00
|
|
|
public static void greenTerraConvert(Player player, Block block) {
|
|
|
|
Material type = block.getType();
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2012-04-29 05:22:17 +02:00
|
|
|
if (Misc.blockBreakSimulate(block, player, false)) {
|
2012-05-10 15:54:29 +02:00
|
|
|
if (Config.getInstance().getHerbalismGreenThumbSmoothbrickToMossy() && type == Material.SMOOTH_BRICK && block.getData() == 0) {
|
|
|
|
block.setTypeIdAndData(block.getTypeId(), (byte) 1, false); //Set type of the brick to mossy, force the client update
|
2012-04-29 05:22:17 +02:00
|
|
|
}
|
2012-05-10 15:54:29 +02:00
|
|
|
else if (Config.getInstance().getHerbalismGreenThumbDirtToGrass() && type == Material.DIRT) {
|
2012-04-29 05:22:17 +02:00
|
|
|
block.setType(Material.GRASS);
|
|
|
|
}
|
2012-05-10 15:54:29 +02:00
|
|
|
else if (Config.getInstance().getHerbalismGreenThumbCobbleToMossy() && type == Material.COBBLESTONE) {
|
2012-04-29 05:22:17 +02:00
|
|
|
block.setType(Material.MOSSY_COBBLESTONE);
|
2012-10-29 17:17:52 +01:00
|
|
|
// Don't award double drops to mossified cobblestone
|
2012-12-24 22:17:19 +01:00
|
|
|
mcMMO.placeStore.setTrue(block);
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
2012-11-05 06:47:15 +01:00
|
|
|
else if (Config.getInstance().getHerbalismGreenThumbCobbleWallToMossyWall() && type == Material.COBBLE_WALL) {
|
2012-11-05 01:06:33 +01:00
|
|
|
block.setData((byte) 1);
|
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for extra Herbalism drops.
|
|
|
|
*
|
|
|
|
* @param block The block to check for extra drops
|
|
|
|
* @param player The player getting extra drops
|
|
|
|
* @param event The event to use for Green Thumb
|
|
|
|
* @param plugin mcMMO plugin instance
|
|
|
|
*/
|
2012-06-07 00:02:22 +02:00
|
|
|
public static void herbalismProcCheck(final Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
|
2013-01-10 05:03:17 +01:00
|
|
|
if (player == null)
|
2012-11-08 03:41:18 +01:00
|
|
|
return;
|
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
final PlayerProfile profile = Users.getProfile(player);
|
2013-01-02 01:27:50 +01:00
|
|
|
final double MAX_CHANCE = advancedConfig.getHerbalismDoubleDropsChanceMax();
|
|
|
|
final int MAX_BONUS_LEVEL = advancedConfig.getHerbalismDoubleDropsMaxLevel();
|
2012-03-13 08:31:07 +01:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
2012-03-10 19:03:31 +01:00
|
|
|
int id = block.getTypeId();
|
|
|
|
Material type = block.getType();
|
2012-03-10 21:43:48 +01:00
|
|
|
|
2012-03-10 19:03:31 +01:00
|
|
|
Byte data = block.getData();
|
2012-07-04 21:35:14 +02:00
|
|
|
Location location = block.getLocation();
|
2012-03-10 19:03:31 +01:00
|
|
|
Material mat = null;
|
2012-05-17 06:24:33 +02:00
|
|
|
|
2012-03-10 19:03:31 +01:00
|
|
|
int xp = 0;
|
|
|
|
int catciDrops = 0;
|
|
|
|
int caneDrops = 0;
|
|
|
|
|
2012-05-17 06:24:33 +02:00
|
|
|
boolean customPlant = false;
|
|
|
|
|
2013-01-02 01:27:50 +01:00
|
|
|
int randomChance = 100;
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.luckyHerbalism(player)) {
|
2013-01-17 21:20:20 +01:00
|
|
|
randomChance = 75;
|
2012-07-02 17:09:55 +02:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:27:50 +01:00
|
|
|
float chance = (float) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * herbLevel);
|
|
|
|
if (chance > MAX_CHANCE) chance = (float) MAX_CHANCE;
|
|
|
|
|
2012-03-10 19:03:31 +01:00
|
|
|
switch (type) {
|
|
|
|
case BROWN_MUSHROOM:
|
|
|
|
case RED_MUSHROOM:
|
2012-12-24 22:17:19 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(block)) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = Material.getMaterial(id);
|
2012-04-27 05:58:21 +02:00
|
|
|
xp = Config.getInstance().getHerbalismXPMushrooms();
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CACTUS:
|
|
|
|
for (int y = 0; y <= 2; y++) {
|
|
|
|
Block b = block.getRelative(0, y, 0);
|
|
|
|
if (b.getType().equals(Material.CACTUS)) {
|
|
|
|
mat = Material.CACTUS;
|
2012-12-24 22:17:19 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(b)) {
|
2013-01-10 05:46:35 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(randomChance)) {
|
2012-03-10 19:03:31 +01:00
|
|
|
catciDrops++;
|
|
|
|
}
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getHerbalismXPCactus();
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CROPS:
|
2012-03-13 08:00:49 +01:00
|
|
|
if (data == CropState.RIPE.getData()) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = Material.WHEAT;
|
2012-04-27 05:58:21 +02:00
|
|
|
xp = Config.getInstance().getHerbalismXPWheat();
|
2012-03-15 15:24:42 +01:00
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.greenThumbWheat(player)) {
|
2012-03-15 15:24:42 +01:00
|
|
|
greenThumbWheat(block, player, event, plugin);
|
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MELON_BLOCK:
|
2012-12-24 22:17:19 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(block)) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = Material.MELON;
|
2012-04-27 05:58:21 +02:00
|
|
|
xp = Config.getInstance().getHerbalismXPMelon();
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NETHER_WARTS:
|
|
|
|
if (data == (byte) 0x3) {
|
|
|
|
mat = Material.NETHER_STALK;
|
2012-04-27 05:58:21 +02:00
|
|
|
xp = Config.getInstance().getHerbalismXPNetherWart();
|
2012-11-10 01:37:12 +01:00
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.greenThumbNetherwart(player)) {
|
2012-11-10 01:37:12 +01:00
|
|
|
greenThumbWheat(block, player, event, plugin);
|
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PUMPKIN:
|
|
|
|
case JACK_O_LANTERN:
|
2012-12-24 22:17:19 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(block)) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = Material.getMaterial(id);
|
2012-04-27 05:58:21 +02:00
|
|
|
xp = Config.getInstance().getHerbalismXPPumpkin();
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RED_ROSE:
|
|
|
|
case YELLOW_FLOWER:
|
2012-12-24 22:17:19 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(block)) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = Material.getMaterial(id);
|
2012-04-27 05:58:21 +02:00
|
|
|
xp = Config.getInstance().getHerbalismXPFlowers();
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SUGAR_CANE_BLOCK:
|
|
|
|
for (int y = 0; y <= 2; y++) {
|
|
|
|
Block b = block.getRelative(0, y, 0);
|
|
|
|
if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) {
|
|
|
|
mat = Material.SUGAR_CANE;
|
2012-12-24 22:17:19 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(b)) {
|
2013-01-10 05:46:35 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(randomChance)) {
|
2012-03-10 19:03:31 +01:00
|
|
|
caneDrops++;
|
|
|
|
}
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getHerbalismXPSugarCane();
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VINE:
|
2012-12-24 22:17:19 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(block)) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = type;
|
2012-04-27 05:58:21 +02:00
|
|
|
xp = Config.getInstance().getHerbalismXPVines();
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WATER_LILY:
|
2012-12-24 22:17:19 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(block)) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = type;
|
2012-04-27 05:58:21 +02:00
|
|
|
xp = Config.getInstance().getHerbalismXPLilyPads();
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
break;
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2012-09-05 10:45:43 +02:00
|
|
|
case COCOA:
|
2012-12-24 22:56:25 +01:00
|
|
|
if (((data) & 0x8) == 0x8) {
|
2012-09-05 10:45:43 +02:00
|
|
|
mat = Material.COCOA;
|
|
|
|
xp = Config.getInstance().getHerbalismXPCocoa();
|
2012-11-10 01:37:12 +01:00
|
|
|
|
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.greenThumbCocoa(player)) {
|
2012-11-10 01:37:12 +01:00
|
|
|
greenThumbWheat(block, player, event, plugin);
|
|
|
|
}
|
2012-09-05 10:45:43 +02:00
|
|
|
}
|
|
|
|
break;
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2012-10-29 04:53:03 +01:00
|
|
|
case CARROT:
|
2012-10-29 20:33:13 +01:00
|
|
|
if (data == CropState.RIPE.getData()) {
|
2012-10-29 04:53:03 +01:00
|
|
|
mat = Material.CARROT;
|
|
|
|
xp = Config.getInstance().getHerbalismXPCarrot();
|
2012-11-10 01:37:12 +01:00
|
|
|
|
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.greenThumbCarrots(player)) {
|
2012-11-10 01:37:12 +01:00
|
|
|
greenThumbWheat(block, player, event, plugin);
|
|
|
|
}
|
2012-10-29 04:53:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POTATO:
|
2012-10-29 20:33:13 +01:00
|
|
|
if (data == CropState.RIPE.getData()) {
|
2012-10-29 04:53:03 +01:00
|
|
|
mat = Material.POTATO;
|
|
|
|
xp = Config.getInstance().getHerbalismXPPotato();
|
2012-11-10 01:37:12 +01:00
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.greenThumbPotatoes(player)) {
|
2012-11-10 01:37:12 +01:00
|
|
|
greenThumbWheat(block, player, event, plugin);
|
|
|
|
}
|
2012-10-29 04:53:03 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-03-10 19:03:31 +01:00
|
|
|
default:
|
2012-12-29 21:59:18 +01:00
|
|
|
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
|
|
|
if (Config.getInstance().getBlockModsEnabled() && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(item)) {
|
2012-05-17 06:24:33 +02:00
|
|
|
customPlant = true;
|
|
|
|
xp = ModChecks.getCustomBlock(block).getXpGain();
|
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-05-17 06:24:33 +02:00
|
|
|
if (mat == null && !customPlant) {
|
2012-03-10 21:43:48 +01:00
|
|
|
return;
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.herbalismDoubleDrops(player)) {
|
2012-05-17 06:24:33 +02:00
|
|
|
ItemStack is = null;
|
|
|
|
|
|
|
|
if (customPlant) {
|
|
|
|
is = new ItemStack(ModChecks.getCustomBlock(block).getItemDrop());
|
|
|
|
}
|
|
|
|
else {
|
2012-10-18 06:26:16 +02:00
|
|
|
if (mat == Material.COCOA) {
|
2013-01-09 00:14:12 +01:00
|
|
|
try {
|
2013-01-14 03:23:11 +01:00
|
|
|
is = new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData());
|
2013-01-09 00:14:12 +01:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
is = new ItemStack(Material.INK_SACK, 1, (short) 3);
|
|
|
|
}
|
2013-01-14 02:56:05 +01:00
|
|
|
catch (NoSuchMethodError e) {
|
|
|
|
is = new ItemStack(Material.INK_SACK, 1, (short) 3);
|
|
|
|
}
|
2012-10-18 06:26:16 +02:00
|
|
|
}
|
2012-11-05 00:54:22 +01:00
|
|
|
else if (mat == Material.CARROT) {
|
2013-01-09 00:52:50 +01:00
|
|
|
is = new ItemStack(Material.CARROT_ITEM);
|
2012-10-29 04:53:03 +01:00
|
|
|
}
|
2012-11-05 00:54:22 +01:00
|
|
|
else if (mat == Material.POTATO) {
|
2013-01-09 00:52:50 +01:00
|
|
|
is = new ItemStack(Material.POTATO_ITEM);
|
2012-10-29 04:53:03 +01:00
|
|
|
}
|
2012-10-18 06:26:16 +02:00
|
|
|
else {
|
|
|
|
is = new ItemStack(mat);
|
|
|
|
}
|
2012-05-17 06:24:33 +02:00
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2013-01-10 05:46:35 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(randomChance)) {
|
2012-05-01 07:14:32 +02:00
|
|
|
Config configInstance = Config.getInstance();
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case BROWN_MUSHROOM:
|
|
|
|
if (configInstance.getBrownMushroomsDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, is);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CACTUS:
|
|
|
|
if (configInstance.getCactiDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItems(location, is, catciDrops);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CROPS:
|
|
|
|
if (configInstance.getWheatDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, is);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MELON_BLOCK:
|
|
|
|
if (configInstance.getMelonsDoubleDropsEnabled()) {
|
2012-11-13 04:10:14 +01:00
|
|
|
Misc.dropItem(location, is);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NETHER_WARTS:
|
|
|
|
if (configInstance.getNetherWartsDoubleDropsEnabled()) {
|
2012-11-13 04:10:14 +01:00
|
|
|
Misc.dropItem(location, is);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PUMPKIN:
|
|
|
|
if (configInstance.getPumpkinsDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, is);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RED_MUSHROOM:
|
|
|
|
if (configInstance.getRedMushroomsDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, is);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SUGAR_CANE_BLOCK:
|
|
|
|
if (configInstance.getSugarCaneDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItems(location, is, caneDrops);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VINE:
|
|
|
|
if (configInstance.getVinesDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, is);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WATER_LILY:
|
|
|
|
if (configInstance.getWaterLiliesDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, is);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case YELLOW_FLOWER:
|
|
|
|
if (configInstance.getYellowFlowersDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, is);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2012-09-05 10:45:43 +02:00
|
|
|
case COCOA:
|
|
|
|
if (configInstance.getCocoaDoubleDropsEnabled()) {
|
2012-09-07 23:49:00 +02:00
|
|
|
Misc.dropItem(location, is);
|
2012-09-05 10:45:43 +02:00
|
|
|
}
|
|
|
|
break;
|
2012-05-01 07:14:32 +02:00
|
|
|
|
2012-10-29 04:56:33 +01:00
|
|
|
case CARROT:
|
|
|
|
if (configInstance.getCarrotDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, is);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POTATO:
|
|
|
|
if (configInstance.getPotatoDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, is);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-05-01 07:14:32 +02:00
|
|
|
default:
|
2012-05-17 06:24:33 +02:00
|
|
|
if (customPlant) {
|
2012-06-25 15:39:02 +02:00
|
|
|
CustomBlock customBlock = ModChecks.getCustomBlock(block);
|
|
|
|
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
|
|
|
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
|
|
|
|
|
|
|
is = customBlock.getItemDrop();
|
|
|
|
|
|
|
|
if (minimumDropAmount != maximumDropAmount) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItems(location, is, minimumDropAmount);
|
|
|
|
Misc.randomDropItems(location, is, 50, maximumDropAmount - minimumDropAmount);
|
2012-06-25 15:39:02 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItems(location, is, minimumDropAmount);
|
2012-06-25 15:39:02 +02:00
|
|
|
}
|
2012-05-17 06:24:33 +02:00
|
|
|
}
|
2012-05-01 07:14:32 +02:00
|
|
|
break;
|
2012-03-10 21:43:48 +01:00
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
2012-03-10 21:43:48 +01:00
|
|
|
}
|
2012-05-01 07:14:32 +02:00
|
|
|
|
2013-01-10 05:03:17 +01:00
|
|
|
if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle())
|
2012-11-08 03:41:18 +01:00
|
|
|
return;
|
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
Skills.xpProcessing(player, profile, SkillType.HERBALISM, xp);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
|
|
|
|
/**
|
2012-03-11 04:21:53 +01:00
|
|
|
* Apply the Green Thumb ability to crops.
|
2012-03-10 19:03:31 +01:00
|
|
|
*
|
|
|
|
* @param block The block to apply the ability to
|
|
|
|
* @param player The player using the ability
|
|
|
|
* @param event The event triggering the ability
|
|
|
|
* @param plugin mcMMO plugin instance
|
|
|
|
*/
|
2012-06-07 00:02:22 +02:00
|
|
|
private static void greenThumbWheat(Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
|
2013-01-02 01:27:50 +01:00
|
|
|
final int MAX_CHANCE = advancedConfig.getGreenThumbChanceMax();
|
|
|
|
final int MAX_BONUS_LEVEL = advancedConfig.getGreenThumbMaxLevel();
|
2012-03-13 08:31:07 +01:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
PlayerProfile profile = Users.getProfile(player);
|
|
|
|
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
2012-03-10 19:03:31 +01:00
|
|
|
PlayerInventory inventory = player.getInventory();
|
2012-11-10 01:37:12 +01:00
|
|
|
boolean hasSeeds = false;
|
2012-07-04 21:35:14 +02:00
|
|
|
Location location = block.getLocation();
|
2012-11-10 01:37:12 +01:00
|
|
|
Material type = block.getType();
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case CROPS:
|
|
|
|
hasSeeds = inventory.contains(Material.SEEDS);
|
|
|
|
break;
|
|
|
|
case COCOA:
|
2013-01-09 00:14:12 +01:00
|
|
|
try {
|
2013-01-14 03:24:43 +01:00
|
|
|
hasSeeds = inventory.containsAtLeast(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()), 1);
|
2013-01-09 00:14:12 +01:00
|
|
|
}
|
|
|
|
catch(Exception e) {
|
2013-01-10 18:55:54 +01:00
|
|
|
hasSeeds = inventory.containsAtLeast(new ItemStack(Material.INK_SACK, 1, (short) 3), 1);
|
2013-01-09 00:14:12 +01:00
|
|
|
}
|
2013-01-14 02:56:05 +01:00
|
|
|
catch(NoSuchMethodError e) {
|
|
|
|
hasSeeds = inventory.containsAtLeast(new ItemStack(Material.INK_SACK, 1, (short) 3), 1);
|
|
|
|
}
|
2012-11-10 01:37:12 +01:00
|
|
|
break;
|
|
|
|
case CARROT:
|
|
|
|
hasSeeds = inventory.contains(Material.CARROT_ITEM);
|
|
|
|
break;
|
|
|
|
case POTATO:
|
|
|
|
hasSeeds = inventory.contains(Material.POTATO_ITEM);
|
|
|
|
break;
|
|
|
|
case NETHER_WARTS:
|
|
|
|
hasSeeds = inventory.contains(Material.NETHER_STALK);
|
|
|
|
break;
|
2012-12-24 18:35:17 +01:00
|
|
|
default:
|
|
|
|
break;
|
2012-11-10 01:37:12 +01:00
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2013-01-02 01:27:50 +01:00
|
|
|
int randomChance = 100;
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.luckyHerbalism(player)) {
|
2013-01-17 21:20:20 +01:00
|
|
|
randomChance = 75;
|
2012-07-02 17:09:55 +02:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:27:50 +01:00
|
|
|
float chance = (float) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * herbLevel);
|
|
|
|
if (chance > MAX_CHANCE) chance = (float) MAX_CHANCE;
|
|
|
|
|
2013-01-10 05:46:35 +01:00
|
|
|
if (hasSeeds && profile.getAbilityMode(AbilityType.GREEN_TERRA) || hasSeeds && (chance > Misc.getRandom().nextInt(randomChance))) {
|
2012-03-10 19:03:31 +01:00
|
|
|
event.setCancelled(true);
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-11-10 01:37:12 +01:00
|
|
|
switch(type) {
|
|
|
|
case CROPS:
|
|
|
|
Misc.dropItem(location, new ItemStack(Material.WHEAT));
|
|
|
|
Misc.randomDropItems(location, new ItemStack(Material.SEEDS), 50, 3);
|
|
|
|
inventory.removeItem(new ItemStack(Material.SEEDS));
|
|
|
|
break;
|
|
|
|
case COCOA:
|
2013-01-09 00:14:12 +01:00
|
|
|
try {
|
2013-01-14 03:23:11 +01:00
|
|
|
Misc.dropItems(location, new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()), 3);
|
|
|
|
inventory.removeItem(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()));
|
2013-01-09 00:14:12 +01:00
|
|
|
}
|
|
|
|
catch(Exception e) {
|
2013-01-09 00:52:50 +01:00
|
|
|
Misc.dropItems(location, new ItemStack(Material.INK_SACK, 1, (short) 3), 3);
|
2013-01-09 00:14:12 +01:00
|
|
|
inventory.removeItem(new ItemStack(Material.INK_SACK, 1, (short) 3));
|
|
|
|
}
|
2013-01-14 02:56:05 +01:00
|
|
|
catch(NoSuchMethodError e) {
|
|
|
|
Misc.dropItems(location, new ItemStack(Material.INK_SACK, 1, (short) 3), 3);
|
|
|
|
inventory.removeItem(new ItemStack(Material.INK_SACK, 1, (short) 3));
|
|
|
|
}
|
2012-11-10 01:37:12 +01:00
|
|
|
break;
|
|
|
|
case CARROT:
|
|
|
|
Misc.dropItem(location, new ItemStack(Material.CARROT_ITEM));
|
|
|
|
Misc.randomDropItems(location, new ItemStack(Material.CARROT_ITEM), 50, 3);
|
2012-11-16 01:34:57 +01:00
|
|
|
inventory.removeItem(new ItemStack(Material.CARROT_ITEM));
|
2012-11-10 01:37:12 +01:00
|
|
|
break;
|
|
|
|
case POTATO:
|
|
|
|
Misc.dropItem(location, new ItemStack(Material.POTATO_ITEM));
|
|
|
|
Misc.randomDropItems(location, new ItemStack(Material.POTATO_ITEM), 50, 3);
|
|
|
|
Misc.randomDropItem(location, new ItemStack(Material.POISONOUS_POTATO), 2);
|
|
|
|
inventory.removeItem(new ItemStack(Material.POTATO_ITEM));
|
|
|
|
break;
|
|
|
|
case NETHER_WARTS:
|
2013-01-09 00:52:50 +01:00
|
|
|
Misc.dropItems(location, new ItemStack(Material.NETHER_STALK), 2);
|
2012-11-10 01:37:12 +01:00
|
|
|
Misc.randomDropItems(location, new ItemStack(Material.NETHER_STALK), 50, 2);
|
|
|
|
inventory.removeItem(new ItemStack(Material.NETHER_STALK));
|
|
|
|
break;
|
2012-12-24 18:35:17 +01:00
|
|
|
default:
|
|
|
|
break;
|
2012-11-10 01:37:12 +01:00
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2012-11-10 01:37:12 +01:00
|
|
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, profile, type), 1);
|
2012-05-15 06:49:19 +02:00
|
|
|
player.updateInventory(); // Needed until replacement available
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-11 04:21:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the Green Thumb ability to blocks.
|
|
|
|
*
|
|
|
|
* @param is The item in the player's hand
|
|
|
|
* @param player The player activating the ability
|
|
|
|
* @param block The block being used in the ability
|
|
|
|
*/
|
|
|
|
public static void greenThumbBlocks(ItemStack is, Player player, Block block) {
|
2013-01-09 00:52:50 +01:00
|
|
|
final int MAX_CHANCE = advancedConfig.getGreenThumbChanceMax();
|
|
|
|
final int MAX_BONUS_LEVEL = advancedConfig.getGreenThumbMaxLevel();
|
2012-03-13 08:31:07 +01:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
PlayerProfile profile = Users.getProfile(player);
|
|
|
|
int skillLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
2012-03-11 04:21:53 +01:00
|
|
|
int seeds = is.getAmount();
|
|
|
|
|
|
|
|
player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
|
|
|
|
|
2013-01-02 01:27:50 +01:00
|
|
|
int randomChance = 100;
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.luckyHerbalism(player)) {
|
2013-01-17 21:20:20 +01:00
|
|
|
randomChance = 75;
|
2012-07-02 17:09:55 +02:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:27:50 +01:00
|
|
|
float chance = (float) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * skillLevel);
|
|
|
|
if (chance > MAX_CHANCE) chance = (float) MAX_CHANCE;
|
|
|
|
|
2013-01-10 05:46:35 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(randomChance)) {
|
2012-04-29 05:22:17 +02:00
|
|
|
greenTerraConvert(player, block);
|
2012-03-11 04:21:53 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 09:55:15 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
|
2012-03-11 04:21:53 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-19 18:33:57 +01:00
|
|
|
|
|
|
|
public static void hylianLuck(Block block, Player player, BlockBreakEvent event) {
|
|
|
|
int chance = Users.getProfile(player).getSkillLevel(SkillType.HERBALISM) / 100;
|
|
|
|
|
|
|
|
int randomChance = 100;
|
|
|
|
if (Permissions.luckyHerbalism(player)) {
|
|
|
|
randomChance = 75;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chance > Misc.getRandom().nextInt(randomChance)) {
|
|
|
|
Location location = block.getLocation();
|
|
|
|
int dropNumber = Misc.getRandom().nextInt(3);
|
|
|
|
ItemStack item = null;
|
|
|
|
|
|
|
|
switch (block.getType()) {
|
|
|
|
case DEAD_BUSH:
|
|
|
|
case LONG_GRASS:
|
|
|
|
case SAPLING:
|
|
|
|
if (dropNumber == 0) {
|
|
|
|
item = new ItemStack(Material.MELON_SEEDS);
|
|
|
|
}
|
|
|
|
else if (dropNumber == 1) {
|
|
|
|
item = new ItemStack(Material.PUMPKIN_SEEDS);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
item = (new MaterialData(Material.INK_SACK, DyeColor.BROWN.getDyeData())).toItemStack(1);
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
item = (new MaterialData(Material.INK_SACK, (byte) 0x3)).toItemStack(1);
|
|
|
|
}
|
|
|
|
catch (NoSuchMethodError e) {
|
|
|
|
item = (new MaterialData(Material.INK_SACK, (byte) 0x3)).toItemStack(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RED_ROSE:
|
|
|
|
case YELLOW_FLOWER:
|
|
|
|
if (dropNumber == 0) {
|
|
|
|
item = new ItemStack(Material.POTATO);
|
|
|
|
}
|
|
|
|
else if (dropNumber == 1) {
|
|
|
|
item = new ItemStack(Material.CARROT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item = new ItemStack(Material.APPLE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FLOWER_POT:
|
|
|
|
if (dropNumber == 0) {
|
|
|
|
item = new ItemStack(Material.EMERALD);
|
|
|
|
}
|
|
|
|
else if (dropNumber == 1) {
|
|
|
|
item = new ItemStack(Material.DIAMOND);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item = new ItemStack(Material.GOLD_NUGGET);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setCancelled(true);
|
|
|
|
event.getBlock().setType(Material.AIR);
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
|
|
|
|
}
|
|
|
|
}
|
2012-10-31 04:12:43 +01:00
|
|
|
}
|