2012-05-01 19:58:47 +02:00
|
|
|
package com.gmail.nossr50.skills.gathering;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2012-03-02 20:22:29 +01:00
|
|
|
|
2012-05-01 07:14:32 +02:00
|
|
|
import org.bukkit.Location;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.Material;
|
2012-03-16 16:30:23 +01:00
|
|
|
import org.bukkit.TreeSpecies;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.block.Block;
|
2012-12-29 22:38:57 +01:00
|
|
|
import org.bukkit.enchantments.Enchantment;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2012-06-05 16:13:10 +02:00
|
|
|
import org.bukkit.event.block.BlockBreakEvent;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-12-25 07:01:10 +01:00
|
|
|
import org.bukkit.material.MaterialData;
|
2012-03-16 18:33:03 +01:00
|
|
|
import org.bukkit.material.Tree;
|
2012-06-05 16:13:10 +02:00
|
|
|
import org.getspout.spoutapi.sound.SoundEffect;
|
2012-03-02 20:01:09 +01:00
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-11-21 21:49:54 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2012-04-26 16:27:57 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2012-05-17 23:03:56 +02:00
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
2012-03-27 05:01:51 +02:00
|
|
|
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2012-03-21 03:33:58 +01:00
|
|
|
import com.gmail.nossr50.spout.SpoutSounds;
|
2012-05-01 07:14:32 +02:00
|
|
|
import com.gmail.nossr50.util.BlockChecks;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Combat;
|
|
|
|
import com.gmail.nossr50.util.Misc;
|
2012-05-17 23:03:56 +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-02-23 08:12:24 +01:00
|
|
|
|
2012-03-15 22:29:27 +01:00
|
|
|
public class WoodCutting {
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-11-26 01:40:42 +01:00
|
|
|
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
2012-03-26 17:04:17 +02:00
|
|
|
|
2012-03-15 22:29:27 +01:00
|
|
|
/**
|
|
|
|
* Handle the Tree Feller ability.
|
|
|
|
*
|
|
|
|
* @param event Event to modify
|
|
|
|
*/
|
|
|
|
public static void treeFeller(BlockBreakEvent event) {
|
2012-02-23 05:23:42 +01:00
|
|
|
Player player = event.getPlayer();
|
|
|
|
Block firstBlock = event.getBlock();
|
2012-07-03 16:04:04 +02:00
|
|
|
PlayerProfile profile = Users.getProfile(player);
|
2012-02-23 05:23:42 +01:00
|
|
|
ArrayList<Block> toBeFelled = new ArrayList<Block>();
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/* NOTE: Tree Feller will cut upwards like how you actually fell trees */
|
2012-03-15 22:29:27 +01:00
|
|
|
processTreeFelling(firstBlock, toBeFelled);
|
2012-07-03 16:04:04 +02:00
|
|
|
removeBlocks(toBeFelled, player, profile);
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles removing & dropping the blocks from Tree Feller.
|
|
|
|
*
|
|
|
|
* @param toBeFelled List of Blocks to be removed from the tree
|
|
|
|
* @param player The player using the ability
|
2012-07-03 16:04:04 +02:00
|
|
|
* @param profile The PlayerProfile of the player
|
2012-03-16 16:30:23 +01:00
|
|
|
*/
|
2012-07-03 16:04:04 +02:00
|
|
|
private static void removeBlocks(ArrayList<Block> toBeFelled, Player player, PlayerProfile profile) {
|
2012-04-27 05:58:21 +02:00
|
|
|
if (toBeFelled.size() >= Config.getInstance().getTreeFellerThreshold()) {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
|
2012-02-24 10:46:34 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
int xp = 0;
|
|
|
|
ItemStack inHand = player.getItemInHand();
|
2012-12-29 22:38:57 +01:00
|
|
|
int level = 0;
|
|
|
|
if (inHand.containsEnchantment(Enchantment.DURABILITY)) {
|
|
|
|
level = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
|
|
|
|
}
|
|
|
|
int durabilityLoss = durabilityLossCalulate(toBeFelled, level);
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/* This is to prevent using wood axes everytime you tree fell */
|
2012-05-27 20:31:37 +02:00
|
|
|
if (ModChecks.isCustomTool(inHand)) {
|
|
|
|
if (inHand.getDurability() + durabilityLoss >= ModChecks.getToolFromItemStack(inHand).getDurability()) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));
|
|
|
|
|
|
|
|
int health = player.getHealth();
|
|
|
|
|
|
|
|
if (health >= 2) {
|
2013-01-10 05:46:35 +01:00
|
|
|
Combat.dealDamage(player, Misc.getRandom().nextInt(health - 1));
|
2012-05-27 20:31:37 +02:00
|
|
|
}
|
2013-01-07 23:08:53 +01:00
|
|
|
inHand.setDurability(inHand.getType().getMaxDurability());
|
2012-12-31 11:04:01 +01:00
|
|
|
return;
|
2012-05-27 20:31:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((inHand.getDurability() + durabilityLoss >= inHand.getType().getMaxDurability()) || inHand.getType().equals(Material.AIR)) {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
int health = player.getHealth();
|
|
|
|
|
|
|
|
if (health >= 2) {
|
2013-01-10 05:46:35 +01:00
|
|
|
Combat.dealDamage(player, Misc.getRandom().nextInt(health - 1));
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2013-01-07 23:08:53 +01:00
|
|
|
inHand.setDurability(inHand.getType().getMaxDurability());
|
2012-12-31 11:04:01 +01:00
|
|
|
return;
|
2012-03-02 20:01:09 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-05-30 16:48:25 +02:00
|
|
|
/* Damage the tool */
|
|
|
|
inHand.setDurability((short) (inHand.getDurability() + durabilityLoss));
|
|
|
|
|
2012-02-24 10:46:34 +01:00
|
|
|
//Prepare ItemStacks
|
2012-03-16 16:30:23 +01:00
|
|
|
ItemStack item = null;
|
2012-12-29 21:59:18 +01:00
|
|
|
ItemStack oak = (new MaterialData(Material.LOG, TreeSpecies.GENERIC.getData())).toItemStack(1);
|
|
|
|
ItemStack spruce = (new MaterialData(Material.LOG, TreeSpecies.REDWOOD.getData())).toItemStack(1);
|
|
|
|
ItemStack birch = (new MaterialData(Material.LOG, TreeSpecies.BIRCH.getData())).toItemStack(1);
|
|
|
|
ItemStack jungle = (new MaterialData(Material.LOG, TreeSpecies.JUNGLE.getData())).toItemStack(1);
|
|
|
|
|
2012-03-16 16:30:23 +01:00
|
|
|
for (Block x : toBeFelled) {
|
2012-04-27 11:47:11 +02:00
|
|
|
if (Misc.blockBreakSimulate(x, player, true)) {
|
2012-12-29 21:59:18 +01:00
|
|
|
if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(x)) {
|
2012-05-17 23:03:56 +02:00
|
|
|
if (ModChecks.isCustomLogBlock(x)) {
|
2012-05-27 20:40:35 +02:00
|
|
|
CustomBlock block = ModChecks.getCustomBlock(x);
|
|
|
|
item = block.getItemDrop();
|
|
|
|
|
2012-12-24 22:17:19 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(x)) {
|
2012-05-17 23:03:56 +02:00
|
|
|
WoodCutting.woodCuttingProcCheck(player, x);
|
|
|
|
xp = block.getXpGain();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the block */
|
|
|
|
x.setData((byte) 0x0);
|
|
|
|
x.setType(Material.AIR);
|
|
|
|
|
2012-06-25 15:39:02 +02:00
|
|
|
int minimumDropAmount = block.getMinimumDropAmount();
|
|
|
|
int maximumDropAmount = block.getMaximumDropAmount();
|
|
|
|
|
|
|
|
item = block.getItemDrop();
|
|
|
|
|
|
|
|
if (minimumDropAmount != maximumDropAmount) {
|
|
|
|
Misc.dropItems(x.getLocation(), item, minimumDropAmount);
|
|
|
|
Misc.randomDropItems(x.getLocation(), item, 50, maximumDropAmount - minimumDropAmount);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Misc.dropItems(x.getLocation(), item, minimumDropAmount);
|
|
|
|
}
|
2012-05-17 23:03:56 +02:00
|
|
|
}
|
|
|
|
else if (ModChecks.isCustomLeafBlock(x)) {
|
2012-05-27 20:40:35 +02:00
|
|
|
CustomBlock block = ModChecks.getCustomBlock(x);
|
|
|
|
item = block.getItemDrop();
|
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
final int SAPLING_DROP_CHANCE = 10;
|
|
|
|
|
|
|
|
/* Remove the block */
|
|
|
|
x.setData((byte) 0x0);
|
|
|
|
x.setType(Material.AIR);
|
|
|
|
|
2012-05-18 19:40:21 +02:00
|
|
|
Misc.randomDropItem(x.getLocation(), item, SAPLING_DROP_CHANCE);
|
2012-05-17 23:03:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (x.getType() == Material.LOG) {
|
2012-03-16 18:33:03 +01:00
|
|
|
Tree tree = (Tree) x.getState().getData();
|
|
|
|
TreeSpecies species = tree.getSpecies();
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
switch (species) {
|
|
|
|
case GENERIC:
|
2012-02-24 10:46:34 +01:00
|
|
|
item = oak;
|
|
|
|
break;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
case REDWOOD:
|
2012-02-24 10:46:34 +01:00
|
|
|
item = spruce;
|
|
|
|
break;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
case BIRCH:
|
2012-02-24 10:46:34 +01:00
|
|
|
item = birch;
|
|
|
|
break;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
case JUNGLE:
|
2012-02-24 10:46:34 +01:00
|
|
|
item = jungle;
|
|
|
|
break;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-02-24 10:46:34 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-12-24 22:17:19 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(x)) {
|
2012-02-23 10:34:34 +01:00
|
|
|
WoodCutting.woodCuttingProcCheck(player, x);
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
switch (species) {
|
2012-12-24 22:56:25 +01:00
|
|
|
case GENERIC:
|
|
|
|
xp += Config.getInstance().getWoodcuttingXPOak();
|
|
|
|
break;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-12-24 22:56:25 +01:00
|
|
|
case REDWOOD:
|
|
|
|
xp += Config.getInstance().getWoodcuttingXPSpruce();
|
|
|
|
break;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-12-24 22:56:25 +01:00
|
|
|
case BIRCH:
|
|
|
|
xp += Config.getInstance().getWoodcuttingXPBirch();
|
|
|
|
break;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-12-24 22:56:25 +01:00
|
|
|
case JUNGLE:
|
|
|
|
xp += Config.getInstance().getWoodcuttingXPJungle() / 2; //Nerf XP from Jungle Trees when using Tree Feller
|
|
|
|
break;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-12-24 22:56:25 +01:00
|
|
|
default:
|
|
|
|
break;
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
2012-02-23 10:34:34 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/* Remove the block */
|
|
|
|
x.setData((byte) 0x0);
|
2012-02-23 10:34:34 +01:00
|
|
|
x.setType(Material.AIR);
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/* Drop the block */
|
2012-05-18 19:40:21 +02:00
|
|
|
Misc.dropItem(x.getLocation(), item);
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
|
|
|
else if (x.getType() == Material.LEAVES) {
|
2012-03-22 21:36:54 +01:00
|
|
|
final int SAPLING_DROP_CHANCE = 10;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-12-29 21:59:18 +01:00
|
|
|
//Drop the right type of sapling
|
|
|
|
item = (new MaterialData(Material.SAPLING, (byte) (x.getData() & 3))).toItemStack(1);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
2012-05-18 19:40:21 +02:00
|
|
|
Misc.randomDropItem(x.getLocation(), item, SAPLING_DROP_CHANCE);
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-02-23 10:34:34 +01:00
|
|
|
//Remove the block
|
|
|
|
x.setData((byte) 0);
|
|
|
|
x.setType(Material.AIR);
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.woodcutting(player)) {
|
2012-07-03 16:04:04 +02:00
|
|
|
Skills.xpProcessing(player, profile, SkillType.WOODCUTTING, xp);
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the calculations from Tree Feller.
|
|
|
|
*
|
|
|
|
* @param currentBlock The current block to be removed
|
|
|
|
* @param toBeFelled The list of blocks left to be removed
|
|
|
|
*/
|
|
|
|
private static void processTreeFelling(Block currentBlock, ArrayList<Block> toBeFelled) {
|
|
|
|
Material type = currentBlock.getType();
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
if (toBeFelled.size() >= Config.getInstance().getTreeFellerThreshold()) {
|
2012-04-18 21:53:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
if (type.equals(Material.LOG) || type.equals(Material.LEAVES)) {
|
2012-02-24 10:46:34 +01:00
|
|
|
toBeFelled.add(currentBlock);
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2012-05-17 23:03:56 +02:00
|
|
|
else if (Config.getInstance().getBlockModsEnabled() && (ModChecks.isCustomLogBlock(currentBlock) || ModChecks.isCustomLeafBlock(currentBlock))) {
|
|
|
|
toBeFelled.add(currentBlock);
|
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-03-15 05:52:37 +01:00
|
|
|
Block xPositive = currentBlock.getRelative(1, 0, 0);
|
|
|
|
Block xNegative = currentBlock.getRelative(-1, 0, 0);
|
|
|
|
Block zPositive = currentBlock.getRelative(0, 0, 1);
|
|
|
|
Block zNegative = currentBlock.getRelative(0, 0, -1);
|
|
|
|
Block yPositive = currentBlock.getRelative(0, 1, 0);
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-12-24 22:17:19 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(currentBlock)) {
|
2012-05-10 15:54:29 +02:00
|
|
|
if (!isTooAggressive(currentBlock, xPositive) && BlockChecks.treeFellerCompatible(xPositive) && !toBeFelled.contains(xPositive)) {
|
2012-03-16 16:30:23 +01:00
|
|
|
processTreeFelling(xPositive, toBeFelled);
|
|
|
|
}
|
|
|
|
|
2012-05-10 15:54:29 +02:00
|
|
|
if (!isTooAggressive(currentBlock, xNegative) && BlockChecks.treeFellerCompatible(xNegative) && !toBeFelled.contains(xNegative)) {
|
2012-03-16 16:30:23 +01:00
|
|
|
processTreeFelling(xNegative, toBeFelled);
|
|
|
|
}
|
|
|
|
|
2012-05-10 15:54:29 +02:00
|
|
|
if (!isTooAggressive(currentBlock, zPositive) && BlockChecks.treeFellerCompatible(zPositive) && !toBeFelled.contains(zPositive)) {
|
2012-03-16 16:30:23 +01:00
|
|
|
processTreeFelling(zPositive, toBeFelled);
|
|
|
|
}
|
|
|
|
|
2012-05-10 15:54:29 +02:00
|
|
|
if (!isTooAggressive(currentBlock, zNegative) && BlockChecks.treeFellerCompatible(zNegative) && !toBeFelled.contains(zNegative)) {
|
2012-03-16 16:30:23 +01:00
|
|
|
processTreeFelling(zNegative, toBeFelled);
|
|
|
|
}
|
2012-03-28 20:37:17 +02:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-10-31 04:05:37 +01:00
|
|
|
byte data = currentBlock.getData();
|
|
|
|
|
2013-01-10 05:03:17 +01:00
|
|
|
if ((data & 0x4) == 0x4)
|
2012-10-31 04:05:37 +01:00
|
|
|
data ^= 0x4;
|
|
|
|
|
2013-01-10 05:03:17 +01:00
|
|
|
if ((data & 0x8) == 0x8)
|
2012-10-31 04:05:37 +01:00
|
|
|
data ^= 0x8;
|
|
|
|
|
2013-01-10 05:03:17 +01:00
|
|
|
if (TreeSpecies.getByData(data) == TreeSpecies.JUNGLE) {
|
2012-10-31 04:05:37 +01:00
|
|
|
Block corner1 = currentBlock.getRelative(1, 0, 1);
|
|
|
|
Block corner2 = currentBlock.getRelative(1, 0, -1);
|
|
|
|
Block corner3 = currentBlock.getRelative(-1, 0, 1);
|
|
|
|
Block corner4 = currentBlock.getRelative(-1, 0, -1);
|
|
|
|
|
2012-12-24 22:17:19 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(currentBlock)) {
|
2012-10-31 04:05:37 +01:00
|
|
|
if (!isTooAggressive(currentBlock, corner1) && BlockChecks.treeFellerCompatible(corner1) && !toBeFelled.contains(corner1)) {
|
|
|
|
processTreeFelling(corner1, toBeFelled);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isTooAggressive(currentBlock, corner2) && BlockChecks.treeFellerCompatible(corner2) && !toBeFelled.contains(corner2)) {
|
|
|
|
processTreeFelling(corner2, toBeFelled);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isTooAggressive(currentBlock, corner3) && BlockChecks.treeFellerCompatible(corner3) && !toBeFelled.contains(corner3)) {
|
|
|
|
processTreeFelling(corner3, toBeFelled);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isTooAggressive(currentBlock, corner4) && BlockChecks.treeFellerCompatible(corner4) && !toBeFelled.contains(corner4)) {
|
|
|
|
processTreeFelling(corner4, toBeFelled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-10 15:54:29 +02:00
|
|
|
if (BlockChecks.treeFellerCompatible(yPositive)) {
|
2013-01-10 05:03:17 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(currentBlock) && !toBeFelled.contains(yPositive)) {
|
2012-03-15 22:29:27 +01:00
|
|
|
processTreeFelling(yPositive, toBeFelled);
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if Tree Feller is being too aggressive.
|
|
|
|
*
|
|
|
|
* @param currentBlock The current block being felled
|
|
|
|
* @param newBlock The next block to be felled
|
|
|
|
* @return true if Tree Feller is too aggressive, false otherwise
|
|
|
|
*/
|
|
|
|
private static boolean isTooAggressive(Block currentBlock, Block newBlock) {
|
|
|
|
Material currentType = currentBlock.getType();
|
2012-05-17 23:03:56 +02:00
|
|
|
Material newType = newBlock.getType();
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
if ((currentType.equals(Material.LEAVES) || currentType.equals(Material.AIR) || (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLeafBlock(currentBlock))) && (newType.equals(Material.LEAVES) || newType.equals(Material.AIR) || (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLeafBlock(currentBlock)))) {
|
2012-03-16 16:30:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-02-23 05:53:20 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for double drops.
|
|
|
|
*
|
|
|
|
* @param player Player breaking the block
|
|
|
|
* @param block The block being broken
|
|
|
|
*/
|
|
|
|
private static void woodCuttingProcCheck(Player player, Block block) {
|
2012-11-21 21:49:54 +01:00
|
|
|
|
2012-11-26 01:40:42 +01:00
|
|
|
final int MAX_CHANCE = advancedConfig.getMiningDoubleDropChance();
|
2012-11-21 21:49:54 +01:00
|
|
|
final int MAX_BONUS_LEVEL = advancedConfig.getMiningDoubleDropMaxLevel();
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.WOODCUTTING);
|
|
|
|
byte type = block.getData();
|
2012-10-31 03:24:20 +01:00
|
|
|
|
2013-01-10 05:03:17 +01:00
|
|
|
if ((type & 0x4) == 0x4)
|
2012-10-31 03:24:20 +01:00
|
|
|
type ^= 0x4;
|
|
|
|
|
2013-01-10 05:03:17 +01:00
|
|
|
if ((type & 0x8) == 0x8)
|
2012-10-31 03:24:20 +01:00
|
|
|
type ^= 0x8;
|
|
|
|
|
2012-03-16 16:30:23 +01:00
|
|
|
Material mat = Material.getMaterial(block.getTypeId());
|
|
|
|
|
2012-11-21 21:49:54 +01:00
|
|
|
int randomChance = 100;
|
2012-12-24 22:56:25 +01:00
|
|
|
int chance = (int) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * skillLevel);
|
2013-01-02 01:27:50 +01:00
|
|
|
if (chance > MAX_CHANCE) chance = MAX_CHANCE;
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.luckyWoodcutting(player)) {
|
2012-07-02 17:09:55 +02:00
|
|
|
randomChance = (int) (randomChance * 0.75);
|
|
|
|
}
|
|
|
|
|
2013-01-10 05:46:35 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(randomChance) && Permissions.woodcuttingDoubleDrops(player)) {
|
2012-05-01 07:14:32 +02:00
|
|
|
Config configInstance = Config.getInstance();
|
2012-05-17 23:03:56 +02:00
|
|
|
ItemStack item;
|
|
|
|
Location location;
|
|
|
|
|
|
|
|
if (configInstance.getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) {
|
2012-06-25 15:39:02 +02:00
|
|
|
CustomBlock customBlock = ModChecks.getCustomBlock(block);
|
|
|
|
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
|
|
|
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
|
|
|
|
|
|
|
item = customBlock.getItemDrop();
|
2012-05-17 23:03:56 +02:00
|
|
|
location = block.getLocation();
|
2012-06-25 15:39:02 +02:00
|
|
|
|
|
|
|
if (minimumDropAmount != maximumDropAmount) {
|
|
|
|
Misc.dropItems(location, item, minimumDropAmount);
|
|
|
|
Misc.randomDropItems(location, item, 50, maximumDropAmount - minimumDropAmount);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Misc.dropItems(location, item, minimumDropAmount);
|
|
|
|
}
|
2012-05-17 23:03:56 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-12-29 21:59:18 +01:00
|
|
|
item = (new MaterialData(mat, type)).toItemStack(1);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
location = block.getLocation();
|
2012-05-01 07:14:32 +02:00
|
|
|
|
2012-07-09 15:26:22 +02:00
|
|
|
TreeSpecies species = TreeSpecies.getByData(type);
|
2012-05-01 07:14:32 +02:00
|
|
|
|
2012-07-09 15:26:22 +02:00
|
|
|
/* Drop the block */
|
|
|
|
switch (species) {
|
|
|
|
case GENERIC:
|
|
|
|
if (configInstance.getOakDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
|
|
|
break;
|
2012-05-01 07:14:32 +02:00
|
|
|
|
2012-07-09 15:26:22 +02:00
|
|
|
case REDWOOD:
|
|
|
|
if (configInstance.getSpruceDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
|
|
|
break;
|
2012-05-01 07:14:32 +02:00
|
|
|
|
2012-07-09 15:26:22 +02:00
|
|
|
case BIRCH:
|
|
|
|
if (configInstance.getBirchDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
|
|
|
break;
|
2012-05-01 07:14:32 +02:00
|
|
|
|
2012-07-09 15:26:22 +02:00
|
|
|
case JUNGLE:
|
|
|
|
if (configInstance.getJungleDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check XP gain for woodcutting.
|
|
|
|
*
|
|
|
|
* @param player The player breaking the block
|
|
|
|
* @param block The block being broken
|
|
|
|
*/
|
|
|
|
public static void woodcuttingBlockCheck(Player player, Block block) {
|
2012-07-03 16:04:04 +02:00
|
|
|
PlayerProfile profile = Users.getProfile(player);
|
2012-03-16 16:30:23 +01:00
|
|
|
int xp = 0;
|
|
|
|
|
2012-12-24 22:17:19 +01:00
|
|
|
if (mcMMO.placeStore.isTrue(block)) {
|
2012-03-16 16:30:23 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) {
|
|
|
|
xp = ModChecks.getCustomBlock(block).getXpGain();
|
|
|
|
}
|
|
|
|
else {
|
2012-11-10 21:43:08 +01:00
|
|
|
byte type = block.getData();
|
|
|
|
|
2013-01-10 05:03:17 +01:00
|
|
|
if ((type & 0x4) == 0x4)
|
2012-11-10 21:43:08 +01:00
|
|
|
type ^= 0x4;
|
|
|
|
|
2013-01-10 05:03:17 +01:00
|
|
|
if ((type & 0x8) == 0x8)
|
2012-11-10 21:43:08 +01:00
|
|
|
type ^= 0x8;
|
|
|
|
|
|
|
|
TreeSpecies species = TreeSpecies.getByData(type);
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2012-08-14 23:09:49 +02:00
|
|
|
//Apparently species can be null in certain cases (custom server mods?)
|
|
|
|
//https://github.com/mcMMO-Dev/mcMMO/issues/229
|
2013-01-10 05:03:17 +01:00
|
|
|
if (species == null)
|
2012-08-14 23:09:49 +02:00
|
|
|
return;
|
2012-07-09 15:26:22 +02:00
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
switch (species) {
|
|
|
|
case GENERIC:
|
|
|
|
xp += Config.getInstance().getWoodcuttingXPOak();
|
|
|
|
break;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
case REDWOOD:
|
|
|
|
xp += Config.getInstance().getWoodcuttingXPSpruce();
|
|
|
|
break;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
case BIRCH:
|
|
|
|
xp += Config.getInstance().getWoodcuttingXPBirch();
|
|
|
|
break;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
case JUNGLE:
|
|
|
|
xp += Config.getInstance().getWoodcuttingXPJungle();
|
|
|
|
break;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
WoodCutting.woodCuttingProcCheck(player, block);
|
2012-07-03 16:04:04 +02:00
|
|
|
Skills.xpProcessing(player, profile, SkillType.WOODCUTTING, xp);
|
2012-02-04 06:22:10 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the Leaf Blower ability.
|
|
|
|
*
|
|
|
|
* @param player Player using the ability
|
|
|
|
* @param block Block being broken
|
|
|
|
*/
|
|
|
|
public static void leafBlower(Player player, Block block) {
|
2012-03-27 05:01:51 +02:00
|
|
|
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
|
2012-06-07 00:02:22 +02:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2012-04-27 05:58:21 +02:00
|
|
|
if (Config.getInstance().getWoodcuttingRequiresTool()) {
|
|
|
|
Skills.abilityDurabilityLoss(player.getItemInHand(), Config.getInstance().getAbilityToolDamage());
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
if (mcMMO.spoutEnabled) {
|
2012-03-21 03:33:58 +01:00
|
|
|
SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2012-02-04 07:36:03 +01:00
|
|
|
}
|
2012-03-28 20:37:17 +02:00
|
|
|
|
2012-12-29 22:38:57 +01:00
|
|
|
private static int durabilityLossCalulate(ArrayList<Block> toBeFelled, int level) {
|
2012-03-28 20:37:17 +02:00
|
|
|
int durabilityLoss = 0;
|
|
|
|
for (Block x : toBeFelled) {
|
2013-01-10 05:46:35 +01:00
|
|
|
if (Misc.getRandom().nextInt(level + 1) > 0) {}//Don't add durabilityLoss, because Unbreaking enchantment does it's work.
|
2012-12-29 22:38:57 +01:00
|
|
|
else if (x.getType().equals(Material.LOG) || (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(x))) {
|
2012-04-27 05:58:21 +02:00
|
|
|
durabilityLoss = durabilityLoss + Config.getInstance().getAbilityToolDamage();
|
2012-03-28 20:37:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return durabilityLoss;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|