mcMMO/src/main/java/com/gmail/nossr50/skills/Herbalism.java

297 lines
9.7 KiB
Java
Raw Normal View History

2012-01-09 20:00:13 +01:00
package com.gmail.nossr50.skills;
import org.bukkit.Bukkit;
2012-01-09 20:00:13 +01:00
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
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;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
public class Herbalism
{
2012-01-09 20:00:13 +01:00
public static void greenTerra(Player player, Block block){
2012-02-24 07:02:23 +01:00
PlayerInventory inventory = player.getInventory();
boolean hasSeeds = inventory.contains(Material.SEEDS);
2012-01-09 20:00:13 +01:00
if(block.getType() == Material.COBBLESTONE || block.getType() == Material.DIRT){
2012-02-24 07:02:23 +01:00
if(!hasSeeds)
2012-01-09 20:00:13 +01:00
player.sendMessage("You need more seeds to spread Green Terra");
2012-02-24 07:02:23 +01:00
if(hasSeeds && block.getType() != Material.WHEAT)
2012-01-09 20:00:13 +01:00
{
2012-02-24 07:02:23 +01:00
inventory.removeItem(new ItemStack(Material.SEEDS, 1));
player.updateInventory();
if(LoadProperties.enableSmoothToMossy && block.getType() == Material.SMOOTH_BRICK)
block.setData((byte)1);
if(LoadProperties.enableDirtToGrass && block.getType() == Material.DIRT)
block.setType(Material.GRASS);
if(LoadProperties.enableCobbleToMossy && block.getType() == Material.COBBLESTONE)
block.setType(Material.MOSSY_COBBLESTONE);
2012-01-09 20:00:13 +01:00
}
}
}
public static Boolean canBeGreenTerra(Block block){
2012-02-25 08:49:53 +01:00
switch(block.getType()){
case BROWN_MUSHROOM:
case CACTUS:
case COBBLESTONE:
case CROPS:
case DIRT:
case JACK_O_LANTERN:
case MELON_BLOCK:
case PUMPKIN:
case RED_MUSHROOM:
case RED_ROSE:
case SMOOTH_BRICK:
case SUGAR_CANE_BLOCK:
case VINE:
case WATER_LILY:
case YELLOW_FLOWER:
return true;
}
return false;
2012-01-09 20:00:13 +01:00
}
public static void herbalismProcCheck(final Block block, Player player, BlockBreakEvent event, mcMMO plugin)
2012-01-09 20:00:13 +01:00
{
final PlayerProfile PP = Users.getProfile(player);
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
2012-01-09 20:00:13 +01:00
int type = block.getTypeId();
Location loc = block.getLocation();
ItemStack is = null;
Material mat = null;
2012-02-24 07:02:23 +01:00
PlayerInventory inventory = player.getInventory();
boolean hasSeeds = inventory.contains(Material.SEEDS);
2012-01-09 20:00:13 +01:00
if(plugin.misc.blockWatchList.contains(block))
{
return;
}
//Wheat
2012-01-09 20:00:13 +01:00
if(type == 59 && block.getData() == (byte) 0x7)
{
2012-02-25 08:49:53 +01:00
is = new ItemStack(Material.WHEAT, 1);
2012-01-09 20:00:13 +01:00
PP.addXP(SkillType.HERBALISM, LoadProperties.mwheat, player);
2012-02-23 10:59:00 +01:00
2012-01-09 20:00:13 +01:00
if(player != null)
{
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
m.mcDropItem(loc, is);
2012-01-09 20:00:13 +01:00
}
2012-01-09 20:00:13 +01:00
//GREEN THUMB
2012-02-24 07:02:23 +01:00
if(hasSeeds && PP.getGreenTerraMode() || hasSeeds && (herbLevel >= 1500 || (Math.random() * 1500 <= herbLevel)))
2012-01-09 20:00:13 +01:00
{
event.setCancelled(true);
m.mcDropItem(loc, is);
2012-01-09 20:00:13 +01:00
//DROP SOME SEEDS
2012-02-25 08:49:53 +01:00
is = new ItemStack(Material.SEEDS, 1);
m.mcDropItem(loc, is);
2012-01-09 20:00:13 +01:00
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
block.setType(Material.CROPS);
//This replants the wheat at a certain stage in development based on Herbalism Skill
if(!PP.getGreenTerraMode())
{
if (PP.getSkillLevel(SkillType.HERBALISM) >= 600)
block.setData((byte) 0x4);
else if (PP.getSkillLevel(SkillType.HERBALISM) >= 400)
block.setData((byte) 0x3);
else if (PP.getSkillLevel(SkillType.HERBALISM) >= 200)
block.setData((byte) 0x2);
else
block.setData((byte) 0x1);
} else
block.setData((byte) 0x4);
}
}, 1);
2012-02-24 07:02:23 +01:00
inventory.removeItem(new ItemStack(Material.SEEDS, 1));
player.updateInventory();
2012-01-09 20:00:13 +01:00
}
}
//Nether Wart
if(type == 115 && block.getData() == (byte) 0x3)
{
2012-02-25 08:49:53 +01:00
is = new ItemStack(Material.NETHER_STALK, 1);
PP.addXP(SkillType.HERBALISM, LoadProperties.mnetherwart, player);
if(player != null)
{
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
{
2012-02-24 04:26:20 +01:00
m.mcDropItems(loc, is, 2);
m.mcRandomDropItems(loc, is, 50, 3);
}
}
}
2012-01-09 20:00:13 +01:00
/*
* We need to check not-wheat and not-netherwart stuff for if it was placed by the player or not
2012-01-09 20:00:13 +01:00
*/
if(block.getData() != (byte) 5)
{
//Cactus
if(type == 81){
//Setup the loop
World world = block.getWorld();
Block[] blockArray = new Block[3];
blockArray[0] = block;
blockArray[1] = world.getBlockAt(block.getX(), block.getY()+1, block.getZ());
blockArray[2] = world.getBlockAt(block.getX(), block.getY()+2, block.getZ());
Material[] materialArray = new Material[3];
materialArray[0] = blockArray[0].getType();
materialArray[1] = blockArray[1].getType();
materialArray[2] = blockArray[2].getType();
byte[] byteArray = new byte[3];
byteArray[0] = blockArray[0].getData();
byteArray[1] = blockArray[0].getData();
byteArray[2] = blockArray[0].getData();
int x = 0;
for(Block target : blockArray)
{
if(materialArray[x] == Material.CACTUS)
{
2012-02-25 08:49:53 +01:00
is = new ItemStack(Material.CACTUS, 1);
2012-01-09 20:00:13 +01:00
if(byteArray[x] != (byte) 5)
{
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
2012-01-09 20:00:13 +01:00
{
m.mcDropItem(target.getLocation(), is);
2012-01-09 20:00:13 +01:00
}
PP.addXP(SkillType.HERBALISM, LoadProperties.mcactus, player);
}
}
x++;
}
}
//Sugar Canes
if(type == 83)
{
//Setup the loop
World world = block.getWorld();
Block[] blockArray = new Block[3];
blockArray[0] = block;
blockArray[1] = world.getBlockAt(block.getX(), block.getY()+1, block.getZ());
blockArray[2] = world.getBlockAt(block.getX(), block.getY()+2, block.getZ());
Material[] materialArray = new Material[3];
materialArray[0] = blockArray[0].getType();
materialArray[1] = blockArray[1].getType();
materialArray[2] = blockArray[2].getType();
byte[] byteArray = new byte[3];
byteArray[0] = blockArray[0].getData();
byteArray[1] = blockArray[0].getData();
byteArray[2] = blockArray[0].getData();
int x = 0;
for(Block target : blockArray)
{
if(materialArray[x] == Material.SUGAR_CANE_BLOCK)
{
2012-02-25 08:49:53 +01:00
is = new ItemStack(Material.SUGAR_CANE, 1);
2012-01-09 20:00:13 +01:00
//Check for being placed by the player
if(byteArray[x] != (byte) 5)
{
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
2012-01-09 20:00:13 +01:00
{
m.mcDropItem(target.getLocation(), is);
2012-01-09 20:00:13 +01:00
}
PP.addXP(SkillType.HERBALISM, LoadProperties.msugar, player);
}
}
x++;
}
}
//Pumpkins
if((type == 91 || type == 86))
{
mat = Material.getMaterial(block.getTypeId());
2012-02-25 08:49:53 +01:00
is = new ItemStack(mat, 1);
2012-01-09 20:00:13 +01:00
if(player != null)
{
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
2012-01-09 20:00:13 +01:00
{
m.mcDropItem(loc, is);
2012-01-09 20:00:13 +01:00
}
}
PP.addXP(SkillType.HERBALISM, LoadProperties.mpumpkin, player);
}
//Melon
if(type == 103)
{
2012-02-25 08:49:53 +01:00
is = new ItemStack(Material.MELON, 1);
2012-02-01 09:45:46 +01:00
if(player != null)
2012-01-09 20:00:13 +01:00
{
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
2012-02-01 09:45:46 +01:00
{
2012-02-24 04:26:20 +01:00
m.mcDropItems(loc, is, 3);
m.mcRandomDropItems(loc, is, 50, 4);
2012-02-01 09:45:46 +01:00
}
2012-01-09 20:00:13 +01:00
}
PP.addXP(SkillType.HERBALISM, LoadProperties.mmelon, player);
}
//Mushroom
if(type == 39 || type == 40)
{
mat = Material.getMaterial(block.getTypeId());
2012-02-25 08:49:53 +01:00
is = new ItemStack(mat, 1);
2012-01-09 20:00:13 +01:00
if(player != null)
{
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
2012-01-09 20:00:13 +01:00
{
m.mcDropItem(loc, is);
2012-01-09 20:00:13 +01:00
}
}
PP.addXP(SkillType.HERBALISM, LoadProperties.mmushroom, player);
}
//Flower
if(type == 37 || type == 38){
mat = Material.getMaterial(block.getTypeId());
2012-02-25 08:49:53 +01:00
is = new ItemStack(mat, 1);
2012-01-09 20:00:13 +01:00
if(player != null){
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
m.mcDropItem(loc, is);
2012-01-09 20:00:13 +01:00
}
PP.addXP(SkillType.HERBALISM, LoadProperties.mflower, player);
}
//Lily Pads
if(type == 111)
{
2012-02-25 08:49:53 +01:00
is = new ItemStack(Material.WATER_LILY, 1);
if(player != null){
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
m.mcDropItem(loc, is);
}
PP.addXP(SkillType.HERBALISM, LoadProperties.mlilypad, player);
}
//Vines
if(type == 106){
2012-02-25 08:49:53 +01:00
is = new ItemStack(Material.VINE, 1, (byte)0, (byte)0);
if(player != null){
if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
m.mcDropItem(loc, is);
}
PP.addXP(SkillType.HERBALISM, LoadProperties.mvines, player);
}
2012-01-09 20:00:13 +01:00
}
Skills.XpCheckSkill(SkillType.HERBALISM, player);
}
}