Squashed commit of the following:

commit cb3e057dee1f2b29838ab654a526baac1baab7d6
Author: NuclearW <incongruency@gmail.com>
Date:   Fri Mar 1 00:43:57 2013 -0500

    1.4.00 release

commit 4f9628d2e4cde31c8946e9a911ee6f10e1fb6b35
Author: NuclearW <incongruency@gmail.com>
Date:   Fri Mar 1 00:07:30 2013 -0500

    \r -> \n

commit b2ca22e0477c747143b0f08a28a096967ee6ffd7
Author: GJ <gjmcferrin@gmail.com>
Date:   Thu Feb 28 23:53:56 2013 -0500

    Commented-out code shouldn't be done like that.

commit 92f131712cc671e3e616c14a22e22769ef6d6d0b
Author: GJ <gjmcferrin@gmail.com>
Date:   Thu Feb 28 23:45:36 2013 -0500

    More things we missed.

commit 408b03766f6261a03a862a1ab7f5835772feda4a
Author: NuclearW <incongruency@gmail.com>
Date:   Thu Feb 28 23:20:13 2013 -0500

    Format: util through spout and backup lib

commit d6bd2c29bbb51bee3607247468cfe145d4f38c9e
Author: GJ <gjmcferrin@gmail.com>
Date:   Thu Feb 28 22:50:08 2013 -0500

    The things we missed the first time through...

commit 393f0b889aa1b7011ee81ee7b15413d8824b8cfb
Author: GJ <gjmcferrin@gmail.com>
Date:   Thu Feb 28 22:05:29 2013 -0500

    Formatting: Skills

commit c097a6e188a7b760dd1b4389ed81dca417146b16
Author: GJ <gjmcferrin@gmail.com>
Date:   Thu Feb 28 19:30:12 2013 -0500

    Organize imports.

commit 34c3e74be7eb5f983f21d969e30155c5d82c01c1
Author: GJ <gjmcferrin@gmail.com>
Date:   Thu Feb 28 19:09:45 2013 -0500

    Fixed a missing fallthrough comment from ChatCommand

commit b4a76c9f022a2fd98bdd8f083accfea03becfd71
Author: GJ <gjmcferrin@gmail.com>
Date:   Thu Feb 28 19:09:36 2013 -0500

    Formatting: datatypes.* through events.*

commit 3e57dd41d3265a7c8106c7eb026df926770a4d15
Author: NuclearW <incongruency@gmail.com>
Date:   Thu Feb 28 17:56:15 2013 -0500

    Fix issue with bad rebase

commit e8c8e06b2971555b7334e49128257e3af6f36892
Author: GJ <gjmcferrin@gmail.com>
Date:   Thu Feb 28 17:35:32 2013 -0500

    Formatting: DatabaseManager, LeaderboardManager, DatabaseUpdateType, and
    PlayerStat

commit 13ecf1cc41f377a12991e357ac10abdcda24d6de
Author: NuclearW <incongruency@gmail.com>
Date:   Thu Feb 28 17:31:43 2013 -0500

    Format: listeners.* through runnables.*

commit 71686e3c0d96c2dcf25442b91703fadda1ea3bb0
Author: NuclearW <incongruency@gmail.com>
Date:   Thu Feb 28 17:13:57 2013 -0500

    Format PartyLockCommand

commit d50abed10bf94e1a88df3dc5cc07c259aea920ea
Author: NuclearW <incongruency@gmail.com>
Date:   Thu Feb 28 16:54:08 2013 -0500

    Format: base through config.*

commit 7004823eeebbae5be7728bf9cafc3b04e57b64cf
Author: NuclearW <incongruency@gmail.com>
Date:   Thu Feb 28 15:21:40 2013 -0500

    Example of using spaces to align like things

commit 534190cfe2481e466fe459d65628550458cc2993
Author: NuclearW <incongruency@gmail.com>
Date:   Thu Feb 28 15:12:19 2013 -0500

    Capitalization

commit 5b61d3ba4c8d81e6f358b0cf4f460abfe9798414
Author: NuclearW <incongruency@gmail.com>
Date:   Thu Feb 28 15:07:43 2013 -0500

    Updated readme, added standards.md

commit 5ec0df70fb82c527420a2f437f27f31bd758f884
Author: NuclearW <incongruency@gmail.com>
Date:   Thu Feb 28 14:42:16 2013 -0500

    Markdown was here, Creole is a loser

commit 70d557c59d086b6a5fb5e0e63c0c1d8eb4c8d19c
Author: NuclearW <incongruency@gmail.com>
Date:   Thu Feb 28 13:46:24 2013 -0500

    Move MCStats shading to .metrics.mcstats

commit eb9d67e66b1659d6abd2397ecf403343cfeffdda
Author: GJ <gjmcferrin@gmail.com>
Date:   Thu Feb 28 13:37:37 2013 -0500

    Move ALL the packages!

commit 8ffa9e7b75417b6c7f158613d4b4ffb783dcf2d0
Author: NuclearW <incongruency@gmail.com>
Date:   Thu Feb 28 12:37:12 2013 -0500

    /r/n -> /n
This commit is contained in:
NuclearW
2013-03-01 00:52:01 -05:00
parent 13111a8d1b
commit a542d6cf3e
263 changed files with 24364 additions and 23982 deletions

View File

@ -1,275 +1,276 @@
package com.gmail.nossr50.skills.woodcutting;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Tree;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.skills.woodcutting.Woodcutting.ExperienceGainMethod;
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Users;
public final class TreeFeller {
private static boolean treeFellerReachedThreshold = false;
private TreeFeller() {}
/**
* Begins Tree Feller
*
* @param mcMMOPlayer Player using Tree Feller
* @param blockState Block being broken
*/
protected static void processTreeFeller(BlockState blockState, Player player) {
List<BlockState> treeFellerBlocks = new ArrayList<BlockState>();
if(blockState.getTypeId() == 17 || blockState.getTypeId() == 99)
processRegularTrees(blockState, treeFellerBlocks);
else
processRedMushroomTrees(blockState, treeFellerBlocks);
// If the player is trying to break too many blocks
if (treeFellerReachedThreshold) {
treeFellerReachedThreshold = false;
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
return;
}
// If the tool can't sustain the durability loss
if (!handleDurabilityLoss(treeFellerBlocks, player.getItemInHand())) {
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));
int health = player.getHealth();
if (health > 1) {
CombatTools.dealDamage(player, Misc.getRandom().nextInt(health - 1));
}
return;
}
dropBlocks(treeFellerBlocks, player);
}
/**
* Processes Tree Feller for generic Trees
*
* @param blockState Block being checked
* @param treeFellerBlocks List of blocks to be removed
*/
private static void processRegularTrees(BlockState blockState, List<BlockState> treeFellerBlocks) {
if (!BlockChecks.isLog(blockState)) {
return;
}
List<BlockState> futureCenterBlocks = new ArrayList<BlockState>();
World world = blockState.getWorld();
// Handle the blocks around 'block'
for (int y = 0; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
BlockState nextBlock = world.getBlockAt(blockState.getLocation().add(x, y, z)).getState();
handleBlock(nextBlock, futureCenterBlocks, treeFellerBlocks);
if (treeFellerReachedThreshold) {
return;
}
}
}
}
// Recursive call for each log found
for (BlockState futureCenterBlock : futureCenterBlocks) {
if (treeFellerReachedThreshold) {
return;
}
processRegularTrees(futureCenterBlock, treeFellerBlocks);
}
}
/**
* Processes Tree Feller for Red Mushrooms (Dome Shaped)
*
* @param blockState Block being checked
* @param treeFellerBlocks List of blocks to be removed
*/
private static void processRedMushroomTrees(BlockState blockState, List<BlockState> treeFellerBlocks) {
if (!BlockChecks.isLog(blockState)) {
return;
}
List<BlockState> futureCenterBlocks = new ArrayList<BlockState>();
World world = blockState.getWorld();
// Handle the blocks around 'block'
for (int y = 0; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
BlockState nextBlock = world.getBlockAt(blockState.getLocation().add(x, y, z)).getState();
BlockState otherNextBlock = world.getBlockAt(blockState.getLocation().add(x, y-(y*2), z)).getState();
handleBlock(nextBlock, futureCenterBlocks, treeFellerBlocks);
handleBlock(otherNextBlock, futureCenterBlocks, treeFellerBlocks);
if (treeFellerReachedThreshold) {
return;
}
}
}
}
// Recursive call for each log found
for (BlockState futureCenterBlock : futureCenterBlocks) {
if (treeFellerReachedThreshold) {
return;
}
processRedMushroomTrees(futureCenterBlock, treeFellerBlocks);
}
}
/**
* Handle a block addition to the list of blocks to be removed
* and to the list of blocks used for future recursive calls of 'processRecursively()'
*
* @param blockState Block to be added
* @param futureCenterBlocks List of blocks that will be used to call 'processRecursively()'
* @param treeFellerBlocks List of blocks to be removed
*/
private static void handleBlock(BlockState blockState, List<BlockState> futureCenterBlocks, List<BlockState> treeFellerBlocks) {
if (!BlockChecks.affectedByTreeFeller(blockState) || mcMMO.placeStore.isTrue(blockState) || treeFellerBlocks.contains(blockState)) {
return;
}
treeFellerBlocks.add(blockState);
if (treeFellerBlocks.size() > Config.getInstance().getTreeFellerThreshold()) {
treeFellerReachedThreshold = true;
return;
}
futureCenterBlocks.add(blockState);
}
/**
* Handles the durability loss
*
* @param treeFellerBlocks List of blocks to be removed
* @param inHand tool being used
* @return True if the tool can sustain the durability loss
*/
private static boolean handleDurabilityLoss(List<BlockState> treeFellerBlocks, ItemStack inHand) {
Material inHandMaterial = inHand.getType();
if (inHandMaterial != Material.AIR) {
short durabilityLoss = 0;
int unbreakingLevel = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
for (BlockState blockState : treeFellerBlocks) {
if (BlockChecks.isLog(blockState) && Misc.getRandom().nextInt(unbreakingLevel + 1) == 0) {
durabilityLoss += Config.getInstance().getAbilityToolDamage();
}
}
short finalDurability = (short) (inHand.getDurability() + durabilityLoss);
short maxDurability = ModChecks.isCustomTool(inHand) ? ModChecks.getToolFromItemStack(inHand).getDurability() : inHandMaterial.getMaxDurability();
if (finalDurability >= maxDurability) {
inHand.setDurability(maxDurability);
return false;
}
inHand.setDurability(finalDurability);
}
return true;
}
/**
* Handles the dropping of blocks
*
* @param treeFellerBlocks List of blocks to be dropped
* @param player Player using the ability
*/
private static void dropBlocks(List<BlockState> treeFellerBlocks, Player player) {
int xp = 0;
for (BlockState blockState : treeFellerBlocks) {
if (!SkillTools.blockBreakSimulate(blockState.getBlock(), player, true)) {
break; // TODO: Shouldn't we use continue instead?
}
Material material = blockState.getType();
if (material == Material.HUGE_MUSHROOM_1 || material == Material.HUGE_MUSHROOM_2) {
xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER);
for (ItemStack drop : blockState.getBlock().getDrops()) {
Misc.dropItem(blockState.getLocation(), drop);
}
}
else if (ModChecks.isCustomLogBlock(blockState)) {
Woodcutting.checkForDoubleDrop(player, blockState);
CustomBlock customBlock = ModChecks.getCustomBlock(blockState);
xp = customBlock.getXpGain();
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
Location location = blockState.getLocation();
ItemStack item = customBlock.getItemDrop();;
Misc.dropItems(location, item, minimumDropAmount);
if (minimumDropAmount < maximumDropAmount) {
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount);
}
}
else if (ModChecks.isCustomLeafBlock(blockState)) {
Misc.randomDropItem(blockState.getLocation(), ModChecks.getCustomBlock(blockState).getItemDrop(), 10);
}
else {
Tree tree = (Tree) blockState.getData();
switch (material) {
case LOG:
Woodcutting.checkForDoubleDrop(player, blockState);
xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER);
Misc.dropItem(blockState.getLocation(), new ItemStack(Material.LOG, 1, tree.getSpecies().getData()));
break;
case LEAVES:
Misc.randomDropItem(blockState.getLocation(), new ItemStack(Material.SAPLING, 1, tree.getSpecies().getData()), 10);
break;
default:
break;
}
}
blockState.setRawData((byte) 0x0);
blockState.setType(Material.AIR);
blockState.update(true);
}
Users.getPlayer(player).beginXpGain(SkillType.WOODCUTTING, xp);
}
}
package com.gmail.nossr50.skills.woodcutting;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Tree;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.woodcutting.Woodcutting.ExperienceGainMethod;
import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public final class TreeFeller {
private static boolean treeFellerReachedThreshold = false;
private TreeFeller() {}
/**
* Begins Tree Feller
*
* @param mcMMOPlayer Player using Tree Feller
* @param blockState Block being broken
*/
protected static void processTreeFeller(BlockState blockState, Player player) {
List<BlockState> treeFellerBlocks = new ArrayList<BlockState>();
if (blockState.getTypeId() == 17 || blockState.getTypeId() == 99) {
processRegularTrees(blockState, treeFellerBlocks);
}
else {
processRedMushroomTrees(blockState, treeFellerBlocks);
}
// If the player is trying to break too many blocks
if (treeFellerReachedThreshold) {
treeFellerReachedThreshold = false;
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
return;
}
// If the tool can't sustain the durability loss
if (!handleDurabilityLoss(treeFellerBlocks, player.getItemInHand())) {
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));
int health = player.getHealth();
if (health > 1) {
CombatUtils.dealDamage(player, Misc.getRandom().nextInt(health - 1));
}
return;
}
dropBlocks(treeFellerBlocks, player);
}
/**
* Processes Tree Feller for generic Trees
*
* @param blockState Block being checked
* @param treeFellerBlocks List of blocks to be removed
*/
private static void processRegularTrees(BlockState blockState, List<BlockState> treeFellerBlocks) {
if (!BlockUtils.isLog(blockState)) {
return;
}
List<BlockState> futureCenterBlocks = new ArrayList<BlockState>();
World world = blockState.getWorld();
// Handle the blocks around 'block'
for (int y = 0; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
BlockState nextBlock = world.getBlockAt(blockState.getLocation().add(x, y, z)).getState();
handleBlock(nextBlock, futureCenterBlocks, treeFellerBlocks);
if (treeFellerReachedThreshold) {
return;
}
}
}
}
// Recursive call for each log found
for (BlockState futureCenterBlock : futureCenterBlocks) {
if (treeFellerReachedThreshold) {
return;
}
processRegularTrees(futureCenterBlock, treeFellerBlocks);
}
}
/**
* Processes Tree Feller for Red Mushrooms (Dome Shaped)
*
* @param blockState Block being checked
* @param treeFellerBlocks List of blocks to be removed
*/
private static void processRedMushroomTrees(BlockState blockState, List<BlockState> treeFellerBlocks) {
if (!BlockUtils.isLog(blockState)) {
return;
}
List<BlockState> futureCenterBlocks = new ArrayList<BlockState>();
World world = blockState.getWorld();
// Handle the blocks around 'block'
for (int y = 0; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
BlockState nextBlock = world.getBlockAt(blockState.getLocation().add(x, y, z)).getState();
BlockState otherNextBlock = world.getBlockAt(blockState.getLocation().add(x, y - (y * 2), z)).getState();
handleBlock(nextBlock, futureCenterBlocks, treeFellerBlocks);
handleBlock(otherNextBlock, futureCenterBlocks, treeFellerBlocks);
if (treeFellerReachedThreshold) {
return;
}
}
}
}
// Recursive call for each log found
for (BlockState futureCenterBlock : futureCenterBlocks) {
if (treeFellerReachedThreshold) {
return;
}
processRedMushroomTrees(futureCenterBlock, treeFellerBlocks);
}
}
/**
* Handle a block addition to the list of blocks to be removed and to the list of blocks used for future recursive calls of 'processRecursively()'
*
* @param blockState Block to be added
* @param futureCenterBlocks List of blocks that will be used to call 'processRecursively()'
* @param treeFellerBlocks List of blocks to be removed
*/
private static void handleBlock(BlockState blockState, List<BlockState> futureCenterBlocks, List<BlockState> treeFellerBlocks) {
if (!BlockUtils.affectedByTreeFeller(blockState) || mcMMO.placeStore.isTrue(blockState) || treeFellerBlocks.contains(blockState)) {
return;
}
treeFellerBlocks.add(blockState);
if (treeFellerBlocks.size() > Config.getInstance().getTreeFellerThreshold()) {
treeFellerReachedThreshold = true;
return;
}
futureCenterBlocks.add(blockState);
}
/**
* Handles the durability loss
*
* @param treeFellerBlocks List of blocks to be removed
* @param inHand tool being used
* @return True if the tool can sustain the durability loss
*/
private static boolean handleDurabilityLoss(List<BlockState> treeFellerBlocks, ItemStack inHand) {
Material inHandMaterial = inHand.getType();
if (inHandMaterial != Material.AIR) {
short durabilityLoss = 0;
int unbreakingLevel = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
for (BlockState blockState : treeFellerBlocks) {
if (BlockUtils.isLog(blockState) && Misc.getRandom().nextInt(unbreakingLevel + 1) == 0) {
durabilityLoss += Config.getInstance().getAbilityToolDamage();
}
}
short finalDurability = (short) (inHand.getDurability() + durabilityLoss);
short maxDurability = ModUtils.isCustomTool(inHand) ? ModUtils.getToolFromItemStack(inHand).getDurability() : inHandMaterial.getMaxDurability();
if (finalDurability >= maxDurability) {
inHand.setDurability(maxDurability);
return false;
}
inHand.setDurability(finalDurability);
}
return true;
}
/**
* Handles the dropping of blocks
*
* @param treeFellerBlocks List of blocks to be dropped
* @param player Player using the ability
*/
private static void dropBlocks(List<BlockState> treeFellerBlocks, Player player) {
int xp = 0;
for (BlockState blockState : treeFellerBlocks) {
if (!SkillUtils.blockBreakSimulate(blockState.getBlock(), player, true)) {
break; // TODO: Shouldn't we use continue instead?
}
Material material = blockState.getType();
if (material == Material.HUGE_MUSHROOM_1 || material == Material.HUGE_MUSHROOM_2) {
xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER);
for (ItemStack drop : blockState.getBlock().getDrops()) {
Misc.dropItem(blockState.getLocation(), drop);
}
}
else if (ModUtils.isCustomLogBlock(blockState)) {
Woodcutting.checkForDoubleDrop(player, blockState);
CustomBlock customBlock = ModUtils.getCustomBlock(blockState);
xp = customBlock.getXpGain();
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
Location location = blockState.getLocation();
ItemStack item = customBlock.getItemDrop();;
Misc.dropItems(location, item, minimumDropAmount);
if (minimumDropAmount < maximumDropAmount) {
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount);
}
}
else if (ModUtils.isCustomLeafBlock(blockState)) {
Misc.randomDropItem(blockState.getLocation(), ModUtils.getCustomBlock(blockState).getItemDrop(), 10);
}
else {
Tree tree = (Tree) blockState.getData();
switch (material) {
case LOG:
Woodcutting.checkForDoubleDrop(player, blockState);
xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER);
Misc.dropItem(blockState.getLocation(), new ItemStack(Material.LOG, 1, tree.getSpecies().getData()));
break;
case LEAVES:
Misc.randomDropItem(blockState.getLocation(), new ItemStack(Material.SAPLING, 1, tree.getSpecies().getData()), 10);
break;
default:
break;
}
}
blockState.setRawData((byte) 0x0);
blockState.setType(Material.AIR);
blockState.update(true);
}
UserManager.getPlayer(player).beginXpGain(SkillType.WOODCUTTING, xp);
}
}

View File

@ -1,182 +1,182 @@
package com.gmail.nossr50.skills.woodcutting;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Tree;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public final class Woodcutting {
public static double doubleDropsMaxChance = AdvancedConfig.getInstance().getWoodcuttingDoubleDropChance();
public static int doubleDropsMaxLevel = AdvancedConfig.getInstance().getWoodcuttingDoubleDropMaxLevel();
protected enum ExperienceGainMethod {
DEFAULT,
TREE_FELLER,
};
private Woodcutting() {}
/**
* Begins the Tree Feller ability
*
* @param mcMMOPlayer Player using the ability
* @param block Block being broken
*/
public static void beginTreeFeller(BlockState blockState, Player player) {
TreeFeller.processTreeFeller(blockState, player);
}
/**
* Begins the Leaf Blower ability
*
* @param player Player using the ability
* @param block Block being broken
*/
public static void beginLeafBlower(Player player, BlockState blockState) {
mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));
player.playSound(blockState.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
}
/**
* Begins Woodcutting
*
* @param mcMMOPlayer Player breaking the block
* @param block Block being broken
*/
public static void beginWoodcutting(Player player, BlockState blockState) {
int xp = getExperienceFromLog(blockState, ExperienceGainMethod.DEFAULT);
if (Permissions.doubleDrops(player, SkillType.WOODCUTTING)) {
Material blockType = blockState.getType();
if (blockType != Material.HUGE_MUSHROOM_1 && blockType != Material.HUGE_MUSHROOM_2) {
checkForDoubleDrop(player, blockState);
}
}
Users.getPlayer(player).beginXpGain(SkillType.WOODCUTTING, xp);
}
/**
* Retrieves the experience reward from a log
*
* @param blockState Log being broken
* @param experienceGainMethod How the log is being broken
* @return Amount of experience
*/
protected static int getExperienceFromLog(BlockState blockState, ExperienceGainMethod experienceGainMethod) {
// Mushrooms aren't trees so we could never get species data from them
switch (blockState.getType()) {
case HUGE_MUSHROOM_1:
return Config.getInstance().getWoodcuttingXPHugeBrownMushroom();
case HUGE_MUSHROOM_2:
return Config.getInstance().getWoodcuttingXPHugeRedMushroom();
default:
break;
}
if (ModChecks.isCustomLogBlock(blockState)) {
return ModChecks.getCustomBlock(blockState).getXpGain();
}
switch (((Tree) blockState.getData()).getSpecies()) {
case GENERIC:
return Config.getInstance().getWoodcuttingXPOak();
case REDWOOD:
return Config.getInstance().getWoodcuttingXPSpruce();
case BIRCH:
return Config.getInstance().getWoodcuttingXPBirch();
case JUNGLE:
int xp = Config.getInstance().getWoodcuttingXPJungle();
if (experienceGainMethod == ExperienceGainMethod.TREE_FELLER) {
xp *= 0.5;
}
return xp;
default:
return 0;
}
}
/**
* Checks for double drops
*
* @param mcMMOPlayer Player breaking the block
* @param blockState Block being broken
*/
protected static void checkForDoubleDrop(Player player, BlockState blockState) {
if (!SkillTools.activationSuccessful(player, SkillType.WOODCUTTING, doubleDropsMaxChance, doubleDropsMaxLevel)) {
return;
}
if (ModChecks.isCustomLogBlock(blockState)) {
CustomBlock customBlock = ModChecks.getCustomBlock(blockState);
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
Location location = blockState.getLocation();
ItemStack item = customBlock.getItemDrop();
Misc.dropItems(location, item, minimumDropAmount);
if (minimumDropAmount != maximumDropAmount) {
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount);
}
}
else {
Location location = blockState.getLocation();
Tree tree = (Tree) blockState.getData();
ItemStack item = new ItemStack(Material.LOG, 1, tree.getSpecies().getData());
switch (((Tree) blockState.getData()).getSpecies()) {
case GENERIC:
if (Config.getInstance().getOakDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
return;
case REDWOOD:
if (Config.getInstance().getSpruceDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
return;
case BIRCH:
if (Config.getInstance().getBirchDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
return;
case JUNGLE:
if (Config.getInstance().getJungleDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
return;
default:
return;
}
}
}
}
package com.gmail.nossr50.skills.woodcutting;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Tree;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils;
public final class Woodcutting {
public static int doubleDropsMaxLevel = AdvancedConfig.getInstance().getWoodcuttingDoubleDropMaxLevel();
public static double doubleDropsMaxChance = AdvancedConfig.getInstance().getWoodcuttingDoubleDropChance();
protected enum ExperienceGainMethod {
DEFAULT,
TREE_FELLER,
};
private Woodcutting() {}
/**
* Begins the Tree Feller ability
*
* @param mcMMOPlayer Player using the ability
* @param block Block being broken
*/
public static void beginTreeFeller(BlockState blockState, Player player) {
TreeFeller.processTreeFeller(blockState, player);
}
/**
* Begins the Leaf Blower ability
*
* @param player Player using the ability
* @param block Block being broken
*/
public static void beginLeafBlower(Player player, BlockState blockState) {
mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));
player.playSound(blockState.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
}
/**
* Begins Woodcutting
*
* @param mcMMOPlayer Player breaking the block
* @param block Block being broken
*/
public static void beginWoodcutting(Player player, BlockState blockState) {
int xp = getExperienceFromLog(blockState, ExperienceGainMethod.DEFAULT);
if (Permissions.doubleDrops(player, SkillType.WOODCUTTING)) {
Material blockType = blockState.getType();
if (blockType != Material.HUGE_MUSHROOM_1 && blockType != Material.HUGE_MUSHROOM_2) {
checkForDoubleDrop(player, blockState);
}
}
UserManager.getPlayer(player).beginXpGain(SkillType.WOODCUTTING, xp);
}
/**
* Retrieves the experience reward from a log
*
* @param blockState Log being broken
* @param experienceGainMethod How the log is being broken
* @return Amount of experience
*/
protected static int getExperienceFromLog(BlockState blockState, ExperienceGainMethod experienceGainMethod) {
// Mushrooms aren't trees so we could never get species data from them
switch (blockState.getType()) {
case HUGE_MUSHROOM_1:
return Config.getInstance().getWoodcuttingXPHugeBrownMushroom();
case HUGE_MUSHROOM_2:
return Config.getInstance().getWoodcuttingXPHugeRedMushroom();
default:
break;
}
if (ModUtils.isCustomLogBlock(blockState)) {
return ModUtils.getCustomBlock(blockState).getXpGain();
}
switch (((Tree) blockState.getData()).getSpecies()) {
case GENERIC:
return Config.getInstance().getWoodcuttingXPOak();
case REDWOOD:
return Config.getInstance().getWoodcuttingXPSpruce();
case BIRCH:
return Config.getInstance().getWoodcuttingXPBirch();
case JUNGLE:
int xp = Config.getInstance().getWoodcuttingXPJungle();
if (experienceGainMethod == ExperienceGainMethod.TREE_FELLER) {
xp *= 0.5;
}
return xp;
default:
return 0;
}
}
/**
* Checks for double drops
*
* @param mcMMOPlayer Player breaking the block
* @param blockState Block being broken
*/
protected static void checkForDoubleDrop(Player player, BlockState blockState) {
if (!SkillUtils.activationSuccessful(player, SkillType.WOODCUTTING, doubleDropsMaxChance, doubleDropsMaxLevel)) {
return;
}
if (ModUtils.isCustomLogBlock(blockState)) {
CustomBlock customBlock = ModUtils.getCustomBlock(blockState);
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
Location location = blockState.getLocation();
ItemStack item = customBlock.getItemDrop();
Misc.dropItems(location, item, minimumDropAmount);
if (minimumDropAmount != maximumDropAmount) {
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount);
}
}
else {
Location location = blockState.getLocation();
Tree tree = (Tree) blockState.getData();
ItemStack item = new ItemStack(Material.LOG, 1, tree.getSpecies().getData());
switch (((Tree) blockState.getData()).getSpecies()) {
case GENERIC:
if (Config.getInstance().getOakDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
return;
case REDWOOD:
if (Config.getInstance().getSpruceDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
return;
case BIRCH:
if (Config.getInstance().getBirchDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
return;
case JUNGLE:
if (Config.getInstance().getJungleDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
return;
default:
return;
}
}
}
}

View File

@ -1,103 +0,0 @@
package com.gmail.nossr50.skills.woodcutting;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillCommand;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Permissions;
public class WoodcuttingCommand extends SkillCommand {
private String treeFellerLength;
private String treeFellerLengthEndurance;
private String doubleDropChance;
private String doubleDropChanceLucky;
private boolean canTreeFell;
private boolean canLeafBlow;
private boolean canDoubleDrop;
private boolean doubleDropsDisabled;
public WoodcuttingCommand() {
super(SkillType.WOODCUTTING);
}
@Override
protected void dataCalculations() {
//TREE FELLER
String[] treeFellerStrings = calculateLengthDisplayValues();
treeFellerLength = treeFellerStrings[0];
treeFellerLengthEndurance = treeFellerStrings[1];
//DOUBLE DROPS
String[] doubleDropStrings = calculateAbilityDisplayValues(Woodcutting.doubleDropsMaxLevel, Woodcutting.doubleDropsMaxChance);
doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1];
}
@Override
protected void permissionsCheck() {
canTreeFell = Permissions.treeFeller(player);
canDoubleDrop = Permissions.doubleDrops(player, skill);
canLeafBlow = Permissions.leafBlower(player);
doubleDropsDisabled = skill.getDoubleDropsDisabled();
}
@Override
protected boolean effectsHeaderPermissions() {
return (canDoubleDrop && !doubleDropsDisabled) || canLeafBlow || canTreeFell;
}
@Override
protected void effectsDisplay() {
luckyEffectsDisplay();
if (canTreeFell) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.0"), LocaleLoader.getString("Woodcutting.Effect.1")));
}
if (canLeafBlow) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.2"), LocaleLoader.getString("Woodcutting.Effect.3")));
}
if (canDoubleDrop && !doubleDropsDisabled) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Woodcutting.Effect.4"), LocaleLoader.getString("Woodcutting.Effect.5")));
}
}
@Override
protected boolean statsHeaderPermissions() {
return (canDoubleDrop && !doubleDropsDisabled) || canLeafBlow || canTreeFell;
}
@Override
protected void statsDisplay() {
if (canLeafBlow) {
int leafBlowerUnlockLevel = AdvancedConfig.getInstance().getLeafBlowUnlockLevel();
if (skillValue < leafBlowerUnlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Woodcutting.Ability.Locked.0", leafBlowerUnlockLevel)));
}
else {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Woodcutting.Ability.0"), LocaleLoader.getString("Woodcutting.Ability.1")));
}
}
if (canDoubleDrop && !doubleDropsDisabled) {
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", doubleDropChance));
}
}
if (canTreeFell) {
if (hasEndurance) {
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Length", treeFellerLength) + LocaleLoader.getString("Perks.activationtime.bonus", treeFellerLengthEndurance));
}
else {
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Length", treeFellerLength));
}
}
}
}