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;
|
2013-01-22 02:14:50 +01:00
|
|
|
import java.util.List;
|
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;
|
2013-01-22 02:14:50 +01:00
|
|
|
import org.bukkit.World;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.block.Block;
|
2013-01-22 02:14:50 +01:00
|
|
|
import org.bukkit.block.BlockFace;
|
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.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 {
|
2013-01-22 02:14:50 +01:00
|
|
|
private static final AdvancedConfig ADVANCED_CONFIG = AdvancedConfig.getInstance();
|
|
|
|
private static boolean treeFellerReachedThreshold = false;
|
2012-03-26 17:04:17 +02:00
|
|
|
|
2012-03-15 22:29:27 +01:00
|
|
|
/**
|
|
|
|
* Handle the Tree Feller ability.
|
|
|
|
*
|
2013-01-22 02:14:50 +01:00
|
|
|
* @param event Event to process
|
2012-03-15 22:29:27 +01:00
|
|
|
*/
|
|
|
|
public static void treeFeller(BlockBreakEvent event) {
|
2013-01-22 02:14:50 +01:00
|
|
|
List<Block> toBeFelled = processTreeFeller(event);
|
|
|
|
|
|
|
|
if (toBeFelled != null && !toBeFelled.isEmpty()) {
|
|
|
|
removeBlocks(toBeFelled, event.getPlayer());
|
|
|
|
}
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles removing & dropping the blocks from Tree Feller.
|
|
|
|
*
|
2013-01-22 02:14:50 +01:00
|
|
|
* @param toBeFelled List of blocks to be removed
|
|
|
|
* @param player Player using the ability
|
2012-03-16 16:30:23 +01:00
|
|
|
*/
|
2013-01-22 02:14:50 +01:00
|
|
|
private static void removeBlocks(List<Block> toBeFelled, Player player) {
|
2012-03-16 16:30:23 +01:00
|
|
|
ItemStack inHand = player.getItemInHand();
|
2013-01-22 02:14:50 +01:00
|
|
|
Material inHandMaterial = inHand.getType();
|
|
|
|
short finalDurability = (short) (inHand.getDurability() + calulateDurabilityLossFromTreeFeller(toBeFelled));
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
// Prevent the tree to be cut down if the tool doesn't have enough durability
|
|
|
|
if (inHandMaterial != Material.AIR) {
|
|
|
|
short maxDurability = ModChecks.isCustomTool(inHand) ? ModChecks.getToolFromItemStack(inHand).getDurability() : inHandMaterial.getMaxDurability();
|
|
|
|
|
|
|
|
if (finalDurability >= maxDurability) {
|
2012-05-27 20:31:37 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));
|
|
|
|
|
|
|
|
int health = player.getHealth();
|
|
|
|
|
|
|
|
if (health >= 2) {
|
2013-01-22 02:14:50 +01:00
|
|
|
Combat.dealDamage(player, Misc.getRandom().nextInt(health - 1)); // Why not base the damage on the number of elements in toBeFelled?
|
2012-05-27 20:31:37 +02:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
inHand.setDurability(maxDurability);
|
|
|
|
return;
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2012-03-02 20:01:09 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
inHand.setDurability(finalDurability);
|
2012-05-30 16:48:25 +02:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
int xp = 0;
|
2012-03-16 16:30:23 +01:00
|
|
|
ItemStack item = null;
|
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
for (Block block : toBeFelled) {
|
|
|
|
if (!Misc.blockBreakSimulate(block, player, true)) {
|
|
|
|
break;
|
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
if (block.getType() == Material.LOG) {
|
|
|
|
WoodCutting.woodCuttingProcCheck(player, block);
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
TreeSpecies species = ((Tree) block.getState().getData()).getSpecies();
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
switch (species) {
|
|
|
|
case GENERIC:
|
|
|
|
item = new MaterialData(Material.LOG, TreeSpecies.GENERIC.getData()).toItemStack(1);
|
|
|
|
xp += Config.getInstance().getWoodcuttingXPOak();
|
|
|
|
break;
|
|
|
|
case REDWOOD:
|
|
|
|
item = new MaterialData(Material.LOG, TreeSpecies.REDWOOD.getData()).toItemStack(1);
|
|
|
|
xp += Config.getInstance().getWoodcuttingXPSpruce();
|
|
|
|
break;
|
|
|
|
case BIRCH:
|
|
|
|
item = new MaterialData(Material.LOG, TreeSpecies.BIRCH.getData()).toItemStack(1);
|
|
|
|
xp += Config.getInstance().getWoodcuttingXPBirch();
|
|
|
|
break;
|
|
|
|
case JUNGLE:
|
|
|
|
item = new MaterialData(Material.LOG, TreeSpecies.JUNGLE.getData()).toItemStack(1);
|
|
|
|
xp += Config.getInstance().getWoodcuttingXPJungle() / 2; // Nerf XP from Jungle Trees when using Tree Feller
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
Misc.dropItem(block.getLocation(), item);
|
|
|
|
}
|
|
|
|
else if (block.getType() == Material.LEAVES) {
|
|
|
|
item = new MaterialData(Material.SAPLING, (byte) (block.getData() & 3)).toItemStack(1);
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
Misc.randomDropItem(block.getLocation(), item, 10);
|
|
|
|
}
|
|
|
|
else if (Config.getInstance().getBlockModsEnabled()) {
|
|
|
|
if (ModChecks.isCustomLogBlock(block)) {
|
|
|
|
CustomBlock customBlock = ModChecks.getCustomBlock(block);
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
WoodCutting.woodCuttingProcCheck(player, block);
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
xp = customBlock.getXpGain();
|
|
|
|
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
|
|
|
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
|
|
|
Location location = block.getLocation();
|
|
|
|
item = customBlock.getItemDrop();
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
Misc.dropItems(location, item, minimumDropAmount);
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
if (minimumDropAmount < maximumDropAmount) {
|
|
|
|
Misc.randomDropItems(location, item, 50, maximumDropAmount - minimumDropAmount);
|
2012-02-23 10:34:34 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2013-01-22 02:14:50 +01:00
|
|
|
else if (ModChecks.isCustomLeafBlock(block)) {
|
|
|
|
CustomBlock customBlock = ModChecks.getCustomBlock(block);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
Misc.randomDropItem(block.getLocation(), customBlock.getItemDrop(), 10);
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-22 02:14:50 +01:00
|
|
|
|
|
|
|
block.setData((byte) 0);
|
|
|
|
block.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)) {
|
2013-01-22 02:14:50 +01:00
|
|
|
Skills.xpProcessing(player, Users.getProfile(player), 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
|
|
|
|
|
|
|
/**
|
2013-01-22 02:14:50 +01:00
|
|
|
* Process Tree Feller around a block.
|
2012-03-16 16:30:23 +01:00
|
|
|
*
|
2013-01-22 02:14:50 +01:00
|
|
|
* @param block Point of origin of the layer
|
|
|
|
* @param toBeFelled List of blocks to be removed
|
2012-03-16 16:30:23 +01:00
|
|
|
*/
|
2013-01-22 02:14:50 +01:00
|
|
|
private static void processTreeFellerAroundBlock(Block block, List<Block> toBeFelled) {
|
|
|
|
// TODO: too much duplicate code here
|
|
|
|
List<Block> futureCenterBlocks = new ArrayList<Block>();
|
|
|
|
boolean centerIsLog = (block.getType() == Material.LOG); //TODO: custom blocks?
|
|
|
|
|
|
|
|
// Handle the block above 'block'
|
|
|
|
Block nextBlock = block.getRelative(BlockFace.UP);;
|
|
|
|
|
|
|
|
if (BlockChecks.treeFellerCompatible(nextBlock) && !toBeFelled.contains(nextBlock) && !mcMMO.placeStore.isTrue(nextBlock)) {
|
|
|
|
toBeFelled.add(nextBlock);
|
|
|
|
|
|
|
|
if (centerIsLog) {
|
|
|
|
futureCenterBlocks.add(nextBlock);
|
2013-01-15 19:13:20 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
if (toBeFelled.size() >= Config.getInstance().getTreeFellerThreshold()) {
|
|
|
|
treeFellerReachedThreshold = true;
|
|
|
|
return;
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2012-03-28 20:37:17 +02:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
World world = block.getWorld();
|
2012-10-31 04:05:37 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
// Handle the blocks around 'block'
|
|
|
|
for (int x = -1 ; x <= 1 ; x++) {
|
|
|
|
for (int z = -1 ; z <= 1 ; z++) {
|
|
|
|
nextBlock = world.getBlockAt(block.getLocation().add(x, 0, z));
|
2012-10-31 04:05:37 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
if (BlockChecks.treeFellerCompatible(nextBlock) && !toBeFelled.contains(nextBlock) && !mcMMO.placeStore.isTrue(nextBlock)) {
|
|
|
|
toBeFelled.add(nextBlock);
|
2012-10-31 04:05:37 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
if (centerIsLog) {
|
|
|
|
futureCenterBlocks.add(nextBlock);
|
|
|
|
}
|
2012-10-31 04:05:37 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
if (toBeFelled.size() >= Config.getInstance().getTreeFellerThreshold()) {
|
|
|
|
treeFellerReachedThreshold = true;
|
|
|
|
return;
|
|
|
|
}
|
2012-10-31 04:05:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
// Recursive call for each log found
|
|
|
|
for (Block futurCenterBlock : futureCenterBlocks) {
|
|
|
|
if (treeFellerReachedThreshold) {
|
|
|
|
return;
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
2013-01-22 02:14:50 +01:00
|
|
|
|
|
|
|
processTreeFellerAroundBlock(futurCenterBlock, toBeFelled);
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/**
|
2013-01-22 02:14:50 +01:00
|
|
|
* Process Tree Feller.
|
2012-03-16 16:30:23 +01:00
|
|
|
*
|
2013-01-22 02:14:50 +01:00
|
|
|
* @param event Event to process
|
|
|
|
* @return List of blocks to be removed
|
2012-03-16 16:30:23 +01:00
|
|
|
*/
|
2013-01-22 02:14:50 +01:00
|
|
|
private static List<Block> processTreeFeller(BlockBreakEvent event) {
|
|
|
|
List<Block> toBeFelled = new ArrayList<Block>();
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
processTreeFellerAroundBlock(event.getBlock(), toBeFelled);
|
|
|
|
|
|
|
|
if (treeFellerReachedThreshold) {
|
|
|
|
treeFellerReachedThreshold = false;
|
|
|
|
|
|
|
|
event.getPlayer().sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
|
|
|
|
return null;
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
return toBeFelled;
|
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
|
2013-01-22 02:14:50 +01:00
|
|
|
* @param block Block being broken
|
2012-03-16 16:30:23 +01:00
|
|
|
*/
|
|
|
|
private static void woodCuttingProcCheck(Player player, Block block) {
|
2013-01-22 02:14:50 +01:00
|
|
|
final int MAX_CHANCE = ADVANCED_CONFIG.getMiningDoubleDropChance();
|
|
|
|
final int MAX_BONUS_LEVEL = ADVANCED_CONFIG.getMiningDoubleDropMaxLevel();
|
2012-03-16 16:30:23 +01:00
|
|
|
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;
|
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
Material blockMaterial = block.getType();
|
|
|
|
int chance = (int) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * Users.getProfile(player).getSkillLevel(SkillType.WOODCUTTING));
|
|
|
|
|
|
|
|
if (chance > MAX_CHANCE) {
|
|
|
|
chance = MAX_CHANCE;
|
|
|
|
}
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-01-22 02:01:33 +01:00
|
|
|
int activationChance = Misc.calculateActivationChance(Permissions.luckyWoodcutting(player));
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-01-22 02:01:33 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(activationChance) && Permissions.woodcuttingDoubleDrops(player)) {
|
2012-05-01 07:14:32 +02:00
|
|
|
Config configInstance = Config.getInstance();
|
2013-01-22 02:14:50 +01:00
|
|
|
ItemStack item = null;
|
|
|
|
Location location = null;
|
2012-05-17 23:03:56 +02:00
|
|
|
|
|
|
|
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 {
|
2013-01-22 02:14:50 +01:00
|
|
|
item = (new MaterialData(blockMaterial, type)).toItemStack(1);
|
2012-05-17 23:03:56 +02:00
|
|
|
location = block.getLocation();
|
2012-05-01 07:14:32 +02:00
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
switch (TreeSpecies.getByData(type)) {
|
2012-07-09 15:26:22 +02:00
|
|
|
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.
|
|
|
|
*
|
2013-01-22 02:14:50 +01:00
|
|
|
* @param player Player breaking the block
|
|
|
|
* @param block Block being broken
|
2012-03-16 16:30:23 +01:00
|
|
|
*/
|
|
|
|
public static void woodcuttingBlockCheck(Player player, Block block) {
|
2012-12-24 22:17:19 +01:00
|
|
|
if (mcMMO.placeStore.isTrue(block)) {
|
2012-03-16 16:30:23 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
int xp = 0;
|
|
|
|
|
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
|
|
|
|
2013-01-22 02:14:50 +01: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);
|
2013-01-22 02:14:50 +01:00
|
|
|
Skills.xpProcessing(player, Users.getProfile(player), 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) {
|
2013-01-22 02:14:50 +01:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));
|
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
|
|
|
|
2013-01-22 02:14:50 +01:00
|
|
|
/**
|
|
|
|
* Calculate the durability loss from Tree Feller
|
|
|
|
*
|
|
|
|
* @param List<Block> Blocks to be felled
|
|
|
|
* @return Durability loss
|
|
|
|
*/
|
|
|
|
private static short calulateDurabilityLossFromTreeFeller(List<Block> toBeFelled) {
|
|
|
|
short durabilityLoss = 0;
|
|
|
|
boolean blockModsEnabled = Config.getInstance().getBlockModsEnabled();
|
|
|
|
|
|
|
|
for (Block block : toBeFelled) {
|
|
|
|
if (block.getType() == Material.LOG || (blockModsEnabled && ModChecks.isCustomLogBlock(block))) {
|
2013-01-19 20:44:51 +01:00
|
|
|
durabilityLoss += Misc.toolDurabilityLoss;
|
2012-03-28 20:37:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return durabilityLoss;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|