2013-01-22 18:43:25 +01:00
|
|
|
package com.gmail.nossr50.skills.woodcutting;
|
2012-01-09 20:00:13 +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;
|
2013-01-30 00:36:16 +01:00
|
|
|
import org.bukkit.Sound;
|
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;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
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;
|
2013-02-01 06:38:25 +01:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2012-03-27 05:01:51 +02:00
|
|
|
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
2013-01-30 17:35:33 +01:00
|
|
|
import com.gmail.nossr50.mods.ModChecks;
|
|
|
|
import com.gmail.nossr50.mods.datatypes.CustomBlock;
|
2013-01-30 17:53:51 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-02-23 08:12:24 +01:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
public final class Woodcutting {
|
2013-01-30 00:21:34 +01:00
|
|
|
static final AdvancedConfig ADVANCED_CONFIG = AdvancedConfig.getInstance();
|
|
|
|
static final Config CONFIG = Config.getInstance();
|
|
|
|
|
2013-01-27 04:19:26 +01:00
|
|
|
protected enum ExperienceGainMethod {
|
|
|
|
DEFAULT,
|
|
|
|
TREE_FELLER,
|
|
|
|
};
|
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
private Woodcutting() {}
|
|
|
|
|
2012-03-15 22:29:27 +01:00
|
|
|
/**
|
2013-01-23 19:37:30 +01:00
|
|
|
* Begins the Tree Feller ability
|
2012-03-15 22:29:27 +01:00
|
|
|
*
|
2013-02-01 06:38:25 +01:00
|
|
|
* @param mcMMOPlayer Player using the ability
|
|
|
|
* @param block Block being broken
|
2012-03-15 22:29:27 +01:00
|
|
|
*/
|
2013-02-01 06:38:25 +01:00
|
|
|
public static void beginTreeFeller(McMMOPlayer mcMMOPlayer, Block block) {
|
|
|
|
TreeFeller.process(mcMMOPlayer, block);
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/**
|
2013-01-23 19:37:30 +01:00
|
|
|
* Begins the Leaf Blower ability
|
2012-03-16 16:30:23 +01:00
|
|
|
*
|
2013-01-22 02:14:50 +01:00
|
|
|
* @param player Player using the ability
|
2013-01-22 21:51:07 +01:00
|
|
|
* @param block Block being broken
|
2012-03-16 16:30:23 +01:00
|
|
|
*/
|
2013-01-22 21:51:07 +01:00
|
|
|
public static void beginLeafBlower(Player player, Block block) {
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-30 00:36:16 +01:00
|
|
|
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/**
|
2013-01-23 19:37:30 +01:00
|
|
|
* Begins Woodcutting
|
2012-03-16 16:30:23 +01:00
|
|
|
*
|
2013-02-01 06:38:25 +01:00
|
|
|
* @param mcMMOPlayer Player breaking the block
|
2013-01-22 21:51:07 +01:00
|
|
|
* @param block Block being broken
|
2012-03-16 16:30:23 +01:00
|
|
|
*/
|
2013-02-01 06:38:25 +01:00
|
|
|
public static void beginWoodcutting(McMMOPlayer mcMMOPlayer, Block block) {
|
2013-01-22 21:51:07 +01:00
|
|
|
int xp = 0;
|
2012-03-16 16:30:23 +01:00
|
|
|
|
2013-01-22 21:51:07 +01:00
|
|
|
if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) {
|
|
|
|
xp = ModChecks.getCustomBlock(block).getXpGain();
|
2012-03-28 20:37:17 +02:00
|
|
|
}
|
2013-01-22 21:51:07 +01:00
|
|
|
else {
|
|
|
|
try {
|
2013-01-27 04:19:26 +01:00
|
|
|
xp = getExperienceFromLog(block, ExperienceGainMethod.DEFAULT);
|
2012-10-31 04:05:37 +01:00
|
|
|
}
|
2013-01-22 21:51:07 +01:00
|
|
|
catch (IllegalArgumentException exception) {
|
2013-01-22 02:14:50 +01:00
|
|
|
return;
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-22 21:51:07 +01:00
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
if (Permissions.woodcuttingDoubleDrops(player)) {
|
2013-02-01 06:38:25 +01:00
|
|
|
checkForDoubleDrop(mcMMOPlayer, block);
|
2013-01-30 00:12:55 +01:00
|
|
|
}
|
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
mcMMOPlayer.addXp(SkillType.WOODCUTTING, xp);
|
2012-02-23 05:23:42 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/**
|
2013-01-23 19:37:30 +01:00
|
|
|
* Retrieves the experience reward from a log
|
2012-03-16 16:30:23 +01:00
|
|
|
*
|
2013-01-22 21:51:07 +01:00
|
|
|
* @param log Log being broken
|
2013-01-27 04:19:26 +01:00
|
|
|
* @param experienceGainMethod How the log is being broken
|
2013-01-22 21:51:07 +01:00
|
|
|
* @return Amount of experience
|
|
|
|
* @throws IllegalArgumentException if 'log' is invalid
|
2012-03-16 16:30:23 +01:00
|
|
|
*/
|
2013-01-27 04:19:26 +01:00
|
|
|
protected static int getExperienceFromLog(Block log, ExperienceGainMethod experienceGainMethod) {
|
2013-01-23 19:30:23 +01:00
|
|
|
TreeSpecies logType = TreeSpecies.getByData(extractLogItemData(log.getData()));
|
2013-01-22 02:14:50 +01:00
|
|
|
|
2013-01-22 21:51:07 +01:00
|
|
|
// Apparently species can be null in certain cases (custom server mods?)
|
|
|
|
// https://github.com/mcMMO-Dev/mcMMO/issues/229
|
|
|
|
if (logType == null) {
|
|
|
|
throw new IllegalArgumentException();
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
2013-01-22 21:51:07 +01:00
|
|
|
switch (logType) {
|
|
|
|
case GENERIC:
|
|
|
|
return Config.getInstance().getWoodcuttingXPOak();
|
|
|
|
case REDWOOD:
|
|
|
|
return Config.getInstance().getWoodcuttingXPSpruce();
|
|
|
|
case BIRCH:
|
|
|
|
return Config.getInstance().getWoodcuttingXPBirch();
|
|
|
|
case JUNGLE:
|
2013-01-27 04:19:26 +01:00
|
|
|
int xp = Config.getInstance().getWoodcuttingXPJungle();
|
|
|
|
|
|
|
|
switch (experienceGainMethod) {
|
|
|
|
case TREE_FELLER:
|
|
|
|
return (int) (xp * 0.5);
|
|
|
|
default:
|
|
|
|
return xp;
|
|
|
|
}
|
2013-01-22 21:51:07 +01:00
|
|
|
default:
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
2012-02-23 05:53:20 +01:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
|
|
|
|
/**
|
2013-01-23 19:37:30 +01:00
|
|
|
* Checks for double drops
|
2012-03-16 16:30:23 +01:00
|
|
|
*
|
2013-02-01 06:38:25 +01:00
|
|
|
* @param mcMMOPlayer 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
|
|
|
*/
|
2013-02-01 06:38:25 +01:00
|
|
|
protected static void checkForDoubleDrop(McMMOPlayer mcMMOPlayer, Block block) {
|
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
2013-01-30 00:21:34 +01:00
|
|
|
double configDoubleDropChance = ADVANCED_CONFIG.getWoodcuttingDoubleDropChance();
|
|
|
|
int configDoubleDropMaxLevel = ADVANCED_CONFIG.getWoodcuttingDoubleDropMaxLevel();
|
|
|
|
int probability = (int) ((configDoubleDropChance / configDoubleDropMaxLevel) * Users.getProfile(player).getSkillLevel(SkillType.WOODCUTTING));
|
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-30 00:21:34 +01:00
|
|
|
if (probability > configDoubleDropChance) {
|
|
|
|
probability = (int) configDoubleDropChance;
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
|
|
|
|
2013-01-30 00:21:34 +01:00
|
|
|
if (probability <= Misc.getRandom().nextInt(activationChance)) {
|
2012-03-16 16:30:23 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) {
|
2013-01-22 21:51:07 +01:00
|
|
|
CustomBlock customBlock = ModChecks.getCustomBlock(block);
|
|
|
|
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
|
|
|
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
|
|
|
Location location = block.getLocation();
|
|
|
|
ItemStack item = customBlock.getItemDrop();
|
2012-11-10 21:43:08 +01:00
|
|
|
|
2013-01-22 21:51:07 +01:00
|
|
|
Misc.dropItems(location, item, minimumDropAmount);
|
2012-11-10 21:43:08 +01:00
|
|
|
|
2013-01-22 21:51:07 +01:00
|
|
|
if (minimumDropAmount != maximumDropAmount) {
|
|
|
|
Misc.randomDropItems(location, item, 50, maximumDropAmount - minimumDropAmount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-01-24 15:37:02 +01:00
|
|
|
byte itemData = extractLogItemData(block.getData());
|
2013-01-22 21:51:07 +01:00
|
|
|
Location location = block.getLocation();
|
2013-01-24 16:14:15 +01:00
|
|
|
ItemStack item = new ItemStack(Material.LOG, 1, itemData);
|
2012-07-09 15:26:22 +02:00
|
|
|
|
2013-01-24 15:37:02 +01:00
|
|
|
switch (TreeSpecies.getByData(itemData)) {
|
2012-05-17 23:03:56 +02:00
|
|
|
case GENERIC:
|
2013-01-22 21:51:07 +01:00
|
|
|
if (Config.getInstance().getOakDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
2012-05-17 23:03:56 +02:00
|
|
|
break;
|
|
|
|
case REDWOOD:
|
2013-01-22 21:51:07 +01:00
|
|
|
if (Config.getInstance().getSpruceDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
2012-05-17 23:03:56 +02:00
|
|
|
break;
|
|
|
|
case BIRCH:
|
2013-01-22 21:51:07 +01:00
|
|
|
if (Config.getInstance().getBirchDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
2012-05-17 23:03:56 +02:00
|
|
|
break;
|
|
|
|
case JUNGLE:
|
2013-01-22 21:51:07 +01:00
|
|
|
if (Config.getInstance().getJungleDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
2012-05-17 23:03:56 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2012-03-28 20:37:17 +02:00
|
|
|
}
|
2013-01-23 19:30:23 +01:00
|
|
|
|
|
|
|
/**
|
2013-01-23 19:37:30 +01:00
|
|
|
* Extracts the log type from the block data (i.e. removes rotation)
|
2013-01-23 19:30:23 +01:00
|
|
|
*
|
|
|
|
* @param data Original block data
|
|
|
|
* @return Extracted log type
|
|
|
|
*/
|
|
|
|
protected static byte extractLogItemData(byte data) {
|
|
|
|
return (byte) (data & 0x3);
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|