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;
|
2013-01-30 00:36:16 +01:00
|
|
|
import org.bukkit.Sound;
|
2013-02-22 17:23:46 +01:00
|
|
|
import org.bukkit.block.BlockState;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2013-02-22 17:23:46 +01:00
|
|
|
import org.bukkit.material.Tree;
|
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-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-02-22 17:23:46 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillTools;
|
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-02-22 17:23:46 +01:00
|
|
|
public static double doubleDropsMaxChance = AdvancedConfig.getInstance().getWoodcuttingDoubleDropChance();
|
|
|
|
public static int doubleDropsMaxLevel = AdvancedConfig.getInstance().getWoodcuttingDoubleDropMaxLevel();
|
2013-01-30 00:21:34 +01:00
|
|
|
|
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-22 17:23:46 +01:00
|
|
|
public static void beginTreeFeller(BlockState blockState, Player player) {
|
|
|
|
TreeFeller.process(blockState, player);
|
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-02-22 17:23:46 +01:00
|
|
|
public static void beginLeafBlower(Player player, BlockState blockState) {
|
2013-01-22 21:51:07 +01:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));
|
2013-02-22 17:23:46 +01:00
|
|
|
player.playSound(blockState.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-22 17:23:46 +01:00
|
|
|
public static void beginWoodcutting(Player player, BlockState blockState) {
|
|
|
|
int xp = getExperienceFromLog(blockState, ExperienceGainMethod.DEFAULT);
|
2013-02-01 06:38:25 +01:00
|
|
|
|
2013-02-19 06:56:25 +01:00
|
|
|
if (Permissions.doubleDrops(player, SkillType.WOODCUTTING)) {
|
2013-02-22 17:23:46 +01:00
|
|
|
checkForDoubleDrop(player, blockState);
|
2013-01-30 00:12:55 +01:00
|
|
|
}
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
Users.getPlayer(player).beginXpGain(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-02-22 17:23:46 +01:00
|
|
|
* @param blockState 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
|
2012-03-16 16:30:23 +01:00
|
|
|
*/
|
2013-02-22 17:23:46 +01:00
|
|
|
protected static int getExperienceFromLog(BlockState blockState, ExperienceGainMethod experienceGainMethod) {
|
2013-02-16 21:22:41 +01:00
|
|
|
// Mushrooms aren't trees so we could never get species data from them
|
2013-02-22 17:23:46 +01:00
|
|
|
switch (blockState.getType()) {
|
2013-02-16 21:25:31 +01:00
|
|
|
case HUGE_MUSHROOM_1:
|
|
|
|
return Config.getInstance().getWoodcuttingXPHugeBrownMushroom();
|
2013-02-22 17:23:46 +01:00
|
|
|
|
2013-02-16 21:25:31 +01:00
|
|
|
case HUGE_MUSHROOM_2:
|
|
|
|
return Config.getInstance().getWoodcuttingXPHugeRedMushroom();
|
2013-02-22 17:23:46 +01:00
|
|
|
|
2013-02-16 21:25:31 +01:00
|
|
|
default:
|
|
|
|
break;
|
2013-02-16 21:22:41 +01:00
|
|
|
}
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
if (ModChecks.isCustomLogBlock(blockState)) {
|
|
|
|
return ModChecks.getCustomBlock(blockState).getXpGain();
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
switch (((Tree) blockState.getData()).getSpecies()) {
|
2013-01-22 21:51:07 +01:00
|
|
|
case GENERIC:
|
|
|
|
return Config.getInstance().getWoodcuttingXPOak();
|
2013-02-22 17:23:46 +01:00
|
|
|
|
2013-01-22 21:51:07 +01:00
|
|
|
case REDWOOD:
|
|
|
|
return Config.getInstance().getWoodcuttingXPSpruce();
|
2013-02-22 17:23:46 +01:00
|
|
|
|
2013-01-22 21:51:07 +01:00
|
|
|
case BIRCH:
|
|
|
|
return Config.getInstance().getWoodcuttingXPBirch();
|
2013-02-22 17:23:46 +01:00
|
|
|
|
2013-01-22 21:51:07 +01:00
|
|
|
case JUNGLE:
|
2013-01-27 04:19:26 +01:00
|
|
|
int xp = Config.getInstance().getWoodcuttingXPJungle();
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
if (experienceGainMethod == ExperienceGainMethod.TREE_FELLER) {
|
|
|
|
xp *= 0.5;
|
2013-01-27 04:19:26 +01:00
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
|
|
|
|
return xp;
|
|
|
|
|
2013-01-22 21:51:07 +01:00
|
|
|
default:
|
2013-02-22 17:23:46 +01:00
|
|
|
return 0;
|
2013-01-22 21:51:07 +01:00
|
|
|
}
|
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-02-22 17:23:46 +01:00
|
|
|
* @param blockState Block being broken
|
2012-03-16 16:30:23 +01:00
|
|
|
*/
|
2013-02-22 17:23:46 +01:00
|
|
|
protected static void checkForDoubleDrop(Player player, BlockState blockState) {
|
|
|
|
if (!SkillTools.activationSuccessful(player, SkillType.WOODCUTTING, doubleDropsMaxChance, doubleDropsMaxLevel)) {
|
2012-03-16 16:30:23 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
if (ModChecks.isCustomLogBlock(blockState)) {
|
|
|
|
CustomBlock customBlock = ModChecks.getCustomBlock(blockState);
|
2013-01-22 21:51:07 +01:00
|
|
|
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
|
|
|
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
2013-02-22 17:23:46 +01:00
|
|
|
Location location = blockState.getLocation();
|
2013-01-22 21:51:07 +01:00
|
|
|
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) {
|
2013-02-17 07:26:47 +01:00
|
|
|
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount);
|
2013-01-22 21:51:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-02-22 17:23:46 +01:00
|
|
|
Location location = blockState.getLocation();
|
|
|
|
ItemStack item = blockState.getData().toItemStack();
|
2012-07-09 15:26:22 +02:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
switch (((Tree) blockState.getData()).getSpecies()) {
|
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);
|
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
return;
|
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
case REDWOOD:
|
2013-01-22 21:51:07 +01:00
|
|
|
if (Config.getInstance().getSpruceDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
return;
|
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
case BIRCH:
|
2013-01-22 21:51:07 +01:00
|
|
|
if (Config.getInstance().getBirchDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
return;
|
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
case JUNGLE:
|
2013-01-22 21:51:07 +01:00
|
|
|
if (Config.getInstance().getJungleDoubleDropsEnabled()) {
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
return;
|
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
default:
|
2013-02-22 17:23:46 +01:00
|
|
|
return;
|
2012-05-17 23:03:56 +02:00
|
|
|
}
|
2012-03-16 16:30:23 +01:00
|
|
|
}
|
2012-03-28 20:37:17 +02:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|