2012-01-09 20:00:13 +01:00
|
|
|
package com.gmail.nossr50.skills;
|
|
|
|
|
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.Users;
|
|
|
|
import com.gmail.nossr50.m;
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-03-20 03:05:17 +01:00
|
|
|
import com.gmail.nossr50.mcPermissions;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.config.LoadProperties;
|
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-03-11 04:21:53 +01:00
|
|
|
import com.gmail.nossr50.locale.mcLocale;
|
|
|
|
import com.gmail.nossr50.runnables.GreenThumbTimer;
|
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);
|
|
|
|
Material type = block.getType();
|
|
|
|
|
|
|
|
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-03-10 19:03:31 +01:00
|
|
|
player.updateInventory();
|
|
|
|
|
2012-03-11 04:21:53 +01:00
|
|
|
if (m.blockBreakSimulate(block, player, false)) {
|
|
|
|
if (LoadProperties.enableSmoothToMossy && type.equals(Material.SMOOTH_BRICK)) {
|
2012-03-13 08:31:07 +01:00
|
|
|
block.setData((byte) 0x1); //Set type of the brick to mossy
|
2012-03-11 04:21:53 +01:00
|
|
|
}
|
|
|
|
else if (LoadProperties.enableDirtToGrass && type.equals(Material.DIRT)) {
|
|
|
|
block.setType(Material.GRASS);
|
|
|
|
}
|
|
|
|
else if (LoadProperties.enableCobbleToMossy && type.equals(Material.COBBLESTONE)) {
|
|
|
|
block.setType(Material.MOSSY_COBBLESTONE);
|
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a block can be made mossy.
|
|
|
|
*
|
|
|
|
* @param material The type of Block to check
|
|
|
|
* @return true if the block can be made mossy, false otherwise
|
|
|
|
*/
|
|
|
|
public static Boolean makeMossy(Material type) {
|
|
|
|
switch (type) {
|
|
|
|
case COBBLESTONE:
|
|
|
|
case DIRT:
|
|
|
|
case SMOOTH_BRICK:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a block is affected by Herbalism abilities.
|
|
|
|
*
|
|
|
|
* @param type The type of Block to check
|
|
|
|
* @return true if the block is affected, false otherwise
|
|
|
|
*/
|
|
|
|
public static Boolean canBeGreenTerra(Material type){
|
|
|
|
switch (type) {
|
|
|
|
case BROWN_MUSHROOM:
|
|
|
|
case CACTUS:
|
|
|
|
case CROPS:
|
|
|
|
case JACK_O_LANTERN:
|
|
|
|
case MELON_BLOCK:
|
2012-04-17 16:42:22 +02:00
|
|
|
case NETHER_WARTS:
|
2012-03-10 19:03:31 +01:00
|
|
|
case PUMPKIN:
|
|
|
|
case RED_MUSHROOM:
|
|
|
|
case RED_ROSE:
|
|
|
|
case SUGAR_CANE_BLOCK:
|
|
|
|
case VINE:
|
|
|
|
case WATER_LILY:
|
|
|
|
case YELLOW_FLOWER:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-03-16 18:45:30 +01:00
|
|
|
if (!block.hasMetadata("mcmmoPlacedBlock")) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = Material.getMaterial(id);
|
|
|
|
xp = LoadProperties.mmushroom;
|
|
|
|
}
|
|
|
|
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-03-15 05:52:37 +01:00
|
|
|
if (!b.hasMetadata("mcmmoPlacedBlock")) {
|
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++;
|
|
|
|
}
|
|
|
|
xp += LoadProperties.mcactus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
xp = LoadProperties.mwheat;
|
2012-03-15 15:24:42 +01:00
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
if (LoadProperties.wheatRegrowth && mcPermissions.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-03-15 05:52:37 +01:00
|
|
|
if (!block.hasMetadata("mcmmoPlacedBlock")) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = Material.MELON;
|
|
|
|
xp = LoadProperties.mmelon;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NETHER_WARTS:
|
|
|
|
if (data == (byte) 0x3) {
|
|
|
|
mat = Material.NETHER_STALK;
|
|
|
|
xp = LoadProperties.mnetherwart;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PUMPKIN:
|
|
|
|
case JACK_O_LANTERN:
|
2012-03-15 05:52:37 +01:00
|
|
|
if (!block.hasMetadata("mcmmoPlacedBlock")) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = Material.getMaterial(id);
|
|
|
|
xp = LoadProperties.mpumpkin;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RED_ROSE:
|
|
|
|
case YELLOW_FLOWER:
|
2012-03-15 05:52:37 +01:00
|
|
|
if (!block.hasMetadata("mcmmoPlacedBlock")) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = Material.getMaterial(id);
|
|
|
|
xp = LoadProperties.mflower;
|
|
|
|
}
|
|
|
|
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-03-15 05:52:37 +01:00
|
|
|
if (!b.hasMetadata("mcmmoPlacedBlock")) {
|
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++;
|
|
|
|
}
|
|
|
|
xp += LoadProperties.msugar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VINE:
|
2012-03-15 05:52:37 +01:00
|
|
|
if (!block.hasMetadata("mcmmoPlacedBlock")) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = type;
|
|
|
|
xp = LoadProperties.mvines;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WATER_LILY:
|
2012-03-15 05:52:37 +01:00
|
|
|
if (!block.hasMetadata("mcmmoPlacedBlock")) {
|
2012-03-10 19:03:31 +01:00
|
|
|
mat = type;
|
|
|
|
xp = LoadProperties.mlilypad;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-10 21:43:48 +01:00
|
|
|
if (mat == null) {
|
|
|
|
return;
|
2012-04-10 17:48:59 +02:00
|
|
|
} else if (mcPermissions.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-03-10 21:43:48 +01:00
|
|
|
if (type.equals(Material.CACTUS)) {
|
|
|
|
m.mcDropItems(loc, is, catciDrops);
|
|
|
|
}
|
|
|
|
else if (type.equals(Material.MELON_BLOCK)) {
|
|
|
|
m.mcDropItems(loc, is, 3);
|
|
|
|
m.mcRandomDropItems(loc, is, 50, 4);
|
|
|
|
}
|
|
|
|
else if (type.equals(Material.NETHER_WARTS)) {
|
|
|
|
m.mcDropItems(loc, is, 2);
|
|
|
|
m.mcRandomDropItems(loc, is, 50, 3);
|
|
|
|
}
|
|
|
|
else if (type.equals(Material.SUGAR_CANE_BLOCK)) {
|
|
|
|
m.mcDropItems(loc, is, caneDrops);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m.mcDropItem(loc, is);
|
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
2012-03-10 21:43:48 +01:00
|
|
|
}
|
2012-04-10 17:48:59 +02:00
|
|
|
|
|
|
|
PP.addXP(SkillType.HERBALISM, xp);
|
|
|
|
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-03-16 18:45:30 +01:00
|
|
|
m.mcDropItem(loc, new ItemStack(Material.WHEAT));
|
|
|
|
m.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
|
|
|
player.updateInventory();
|
|
|
|
}
|
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-03-11 04:21:53 +01:00
|
|
|
greenTerra(player, block);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage(mcLocale.getString("mcPlayerListener.GreenThumbFail"));
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|