2012-05-01 19:58:47 +02:00
|
|
|
package com.gmail.nossr50.skills.gathering;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
import java.util.Random;
|
|
|
|
|
2012-03-13 08:00:49 +01:00
|
|
|
import org.bukkit.CropState;
|
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-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-04-26 16:27:57 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
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-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;
|
|
|
|
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 {
|
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
private static Random random = new Random();
|
|
|
|
|
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) {
|
2012-03-26 22:17:35 +02:00
|
|
|
player.sendMessage("You need more seeds to spread Green Terra"); //TODO: Needs more locale.
|
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-04-29 05:22:17 +02:00
|
|
|
greenTerraConvert(player, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void greenTerraConvert(Player player, Block block) {
|
|
|
|
Material type = block.getType();
|
|
|
|
|
|
|
|
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-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
|
|
|
|
*/
|
|
|
|
public static void herbalismProcCheck(final Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
|
|
|
|
final PlayerProfile PP = Users.getProfile(player);
|
2012-03-13 08:31:07 +01:00
|
|
|
final int MAX_BONUS_LEVEL = 1000;
|
|
|
|
|
2012-03-10 19:03:31 +01:00
|
|
|
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
|
|
|
|
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();
|
|
|
|
Location loc = block.getLocation();
|
|
|
|
Material mat = null;
|
|
|
|
int xp = 0;
|
|
|
|
int catciDrops = 0;
|
|
|
|
int caneDrops = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case BROWN_MUSHROOM:
|
|
|
|
case RED_MUSHROOM:
|
2012-05-08 04:38:22 +02: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-05-08 04:38:22 +02:00
|
|
|
if (!mcMMO.placeStore.isTrue(b)) {
|
2012-03-26 17:04:17 +02:00
|
|
|
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
|
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
|
|
|
|
2012-05-01 19:52:44 +02:00
|
|
|
if (Permissions.getInstance().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-05-08 04:38:22 +02: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-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PUMPKIN:
|
|
|
|
case JACK_O_LANTERN:
|
2012-05-08 04:38:22 +02: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-05-08 04:38:22 +02: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-05-08 04:38:22 +02:00
|
|
|
if (!mcMMO.placeStore.isTrue(b)) {
|
2012-03-26 17:04:17 +02:00
|
|
|
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
|
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-05-08 04:38:22 +02: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-05-08 04:38:22 +02: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;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-10 21:43:48 +01:00
|
|
|
if (mat == null) {
|
|
|
|
return;
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Permissions.getInstance().herbalismDoubleDrops(player)) {
|
2012-03-16 18:45:30 +01:00
|
|
|
ItemStack is = new ItemStack(mat);
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) {
|
2012-05-01 07:14:32 +02:00
|
|
|
Config configInstance = Config.getInstance();
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case BROWN_MUSHROOM:
|
|
|
|
if (configInstance.getBrownMushroomsDoubleDropsEnabled()) {
|
|
|
|
Misc.mcDropItem(loc, is);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CACTUS:
|
|
|
|
if (configInstance.getCactiDoubleDropsEnabled()) {
|
|
|
|
Misc.mcDropItems(loc, is, catciDrops);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CROPS:
|
|
|
|
if (configInstance.getWheatDoubleDropsEnabled()) {
|
|
|
|
Misc.mcDropItem(loc, is);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MELON_BLOCK:
|
|
|
|
if (configInstance.getMelonsDoubleDropsEnabled()) {
|
|
|
|
Misc.mcDropItems(loc, is, 3);
|
|
|
|
Misc.mcRandomDropItems(loc, is, 50, 4);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NETHER_WARTS:
|
|
|
|
if (configInstance.getNetherWartsDoubleDropsEnabled()) {
|
|
|
|
Misc.mcDropItems(loc, is, 2);
|
|
|
|
Misc.mcRandomDropItems(loc, is, 50, 3);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PUMPKIN:
|
|
|
|
if (configInstance.getPumpkinsDoubleDropsEnabled()) {
|
|
|
|
Misc.mcDropItem(loc, is);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RED_MUSHROOM:
|
|
|
|
if (configInstance.getRedMushroomsDoubleDropsEnabled()) {
|
|
|
|
Misc.mcDropItem(loc, is);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SUGAR_CANE_BLOCK:
|
|
|
|
if (configInstance.getSugarCaneDoubleDropsEnabled()) {
|
|
|
|
Misc.mcDropItems(loc, is, caneDrops);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VINE:
|
|
|
|
if (configInstance.getVinesDoubleDropsEnabled()) {
|
|
|
|
Misc.mcDropItem(loc, is);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WATER_LILY:
|
|
|
|
if (configInstance.getWaterLiliesDoubleDropsEnabled()) {
|
|
|
|
Misc.mcDropItem(loc, is);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case YELLOW_FLOWER:
|
|
|
|
if (configInstance.getYellowFlowersDoubleDropsEnabled()) {
|
|
|
|
Misc.mcDropItem(loc, is);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
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
|
|
|
|
2012-05-06 09:47:25 +02:00
|
|
|
PP.addXP(player, SkillType.HERBALISM, xp);
|
2012-04-10 17:48:59 +02:00
|
|
|
Skills.XpCheckSkill(SkillType.HERBALISM, player);
|
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-03-11 04:21:53 +01:00
|
|
|
private static void greenThumbWheat(Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
|
2012-03-13 08:31:07 +01:00
|
|
|
final int MAX_BONUS_LEVEL = 1500;
|
|
|
|
|
2012-03-11 04:21:53 +01:00
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
2012-03-10 19:03:31 +01:00
|
|
|
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
|
|
|
|
PlayerInventory inventory = player.getInventory();
|
|
|
|
boolean hasSeeds = inventory.contains(Material.SEEDS);
|
|
|
|
Location loc = block.getLocation();
|
|
|
|
|
2012-03-27 08:33:35 +02:00
|
|
|
if (hasSeeds && PP.getAbilityMode(AbilityType.GREEN_TERRA) || hasSeeds && (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1500) <= herbLevel)) {
|
2012-03-10 19:03:31 +01:00
|
|
|
event.setCancelled(true);
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
Misc.mcDropItem(loc, new ItemStack(Material.WHEAT));
|
|
|
|
Misc.mcRandomDropItems(loc, new ItemStack(Material.SEEDS), 50, 3);
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-04-21 20:05:39 +02:00
|
|
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, PP), 1);
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2012-03-16 18:45:30 +01:00
|
|
|
inventory.removeItem(new ItemStack(Material.SEEDS));
|
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) {
|
2012-03-13 08:31:07 +01:00
|
|
|
final int MAX_BONUS_LEVEL = 1500;
|
|
|
|
|
2012-03-11 04:21:53 +01:00
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
|
|
|
int skillLevel = PP.getSkillLevel(SkillType.HERBALISM);
|
|
|
|
int seeds = is.getAmount();
|
|
|
|
|
|
|
|
player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
|
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
if (skillLevel > MAX_BONUS_LEVEL || random.nextInt(1500) <= skillLevel) {
|
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
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|