text=auto

This commit is contained in:
NuclearW 2013-03-07 14:43:03 -05:00
parent 3a809dab32
commit 03d0ecd450
3 changed files with 543 additions and 543 deletions

2
.gitattributes vendored
View File

@ -1,4 +1,4 @@
* text * text=auto
*.png binary *.png binary
*.wav binary *.wav binary

View File

@ -1,350 +1,350 @@
package com.gmail.nossr50.skills.repair; package com.gmail.nossr50.skills.repair;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent; import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.repair.Repair.Tier; import com.gmail.nossr50.skills.repair.Repair.Tier;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
public class RepairManager extends SkillManager { public class RepairManager extends SkillManager {
public RepairManager(McMMOPlayer mcMMOPlayer) { public RepairManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.REPAIR); super(mcMMOPlayer, SkillType.REPAIR);
} }
/** /**
* Handles notifications for placing an anvil. * Handles notifications for placing an anvil.
* *
* @param anvilID The item ID of the anvil block * @param anvilID The item ID of the anvil block
*/ */
public void placedAnvilCheck(int anvilId) { public void placedAnvilCheck(int anvilId) {
Player player = getPlayer(); Player player = getPlayer();
if (mcMMOPlayer.getPlacedAnvil(anvilId)) { if (mcMMOPlayer.getPlacedAnvil(anvilId)) {
return; return;
} }
if (mcMMO.spoutEnabled) { if (mcMMO.spoutEnabled) {
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player); SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
if (spoutPlayer.isSpoutCraftEnabled()) { if (spoutPlayer.isSpoutCraftEnabled()) {
String[] spoutMessages = Repair.getSpoutAnvilMessages(anvilId); String[] spoutMessages = Repair.getSpoutAnvilMessages(anvilId);
spoutPlayer.sendNotification(spoutMessages[0], spoutMessages[1], Material.getMaterial(anvilId)); spoutPlayer.sendNotification(spoutMessages[0], spoutMessages[1], Material.getMaterial(anvilId));
} }
else { else {
player.sendMessage(Repair.getAnvilMessage(anvilId)); player.sendMessage(Repair.getAnvilMessage(anvilId));
} }
} }
else { else {
player.sendMessage(Repair.getAnvilMessage(anvilId)); player.sendMessage(Repair.getAnvilMessage(anvilId));
} }
player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH); player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
mcMMOPlayer.togglePlacedAnvil(anvilId); mcMMOPlayer.togglePlacedAnvil(anvilId);
} }
public void handleRepair(ItemStack item) { public void handleRepair(ItemStack item) {
Player player = getPlayer(); Player player = getPlayer();
int itemId = item.getTypeId(); int itemId = item.getTypeId();
Repairable repairable = mcMMO.repairableManager.getRepairable(itemId); Repairable repairable = mcMMO.repairableManager.getRepairable(itemId);
// Permissions checks on material and item types // Permissions checks on material and item types
if (!repairable.getRepairItemType().getPermissions(player)) { if (!repairable.getRepairItemType().getPermissions(player)) {
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission")); player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
return; return;
} }
if (!repairable.getRepairMaterialType().getPermissions(player)) { if (!repairable.getRepairMaterialType().getPermissions(player)) {
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission")); player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
return; return;
} }
int skillLevel = getSkillLevel(); int skillLevel = getSkillLevel();
int minimumRepairableLevel = repairable.getMinimumLevel(); int minimumRepairableLevel = repairable.getMinimumLevel();
// Level check // Level check
if (skillLevel < minimumRepairableLevel) { if (skillLevel < minimumRepairableLevel) {
player.sendMessage(LocaleLoader.getString("Repair.Skills.Adept", minimumRepairableLevel, StringUtils.getPrettyItemString(itemId))); player.sendMessage(LocaleLoader.getString("Repair.Skills.Adept", minimumRepairableLevel, StringUtils.getPrettyItemString(itemId)));
return; return;
} }
PlayerInventory inventory = player.getInventory(); PlayerInventory inventory = player.getInventory();
int repairMaterialId = repairable.getRepairMaterialId(); int repairMaterialId = repairable.getRepairMaterialId();
byte repairMaterialMetadata = repairable.getRepairMaterialMetadata(); byte repairMaterialMetadata = repairable.getRepairMaterialMetadata();
// Check if they have the proper material to repair with // Check if they have the proper material to repair with
if (!inventory.contains(repairMaterialId)) { if (!inventory.contains(repairMaterialId)) {
String message = LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(repairMaterialId)); String message = LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(repairMaterialId));
if (repairMaterialMetadata != (byte) -1) { if (repairMaterialMetadata != (byte) -1) {
// TODO: Do something nicer than append the metadata as a :# ? // TODO: Do something nicer than append the metadata as a :# ?
if (Repair.findInInventory(inventory, repairMaterialId, repairMaterialMetadata) == -1) { if (Repair.findInInventory(inventory, repairMaterialId, repairMaterialMetadata) == -1) {
message += ":" + repairMaterialMetadata; message += ":" + repairMaterialMetadata;
} }
} }
player.sendMessage(message); player.sendMessage(message);
return; return;
} }
short startDurability = item.getDurability(); short startDurability = item.getDurability();
// Do not repair if at full durability // Do not repair if at full durability
if (startDurability <= 0) { if (startDurability <= 0) {
player.sendMessage(LocaleLoader.getString("Repair.Skills.FullDurability")); player.sendMessage(LocaleLoader.getString("Repair.Skills.FullDurability"));
return; return;
} }
// Do not repair stacked items // Do not repair stacked items
if (item.getAmount() != 1) { if (item.getAmount() != 1) {
player.sendMessage(LocaleLoader.getString("Repair.Skills.StackedItems")); player.sendMessage(LocaleLoader.getString("Repair.Skills.StackedItems"));
return; return;
} }
// Clear ability buffs before trying to repair. // Clear ability buffs before trying to repair.
SkillUtils.removeAbilityBuff(item); SkillUtils.removeAbilityBuff(item);
// Lets get down to business, // Lets get down to business,
// To defeat, the huns. // To defeat, the huns.
int baseRepairAmount = repairable.getBaseRepairDurability(); // Did they send me daughters? int baseRepairAmount = repairable.getBaseRepairDurability(); // Did they send me daughters?
short newDurability = repairCalculate(startDurability, baseRepairAmount); // When I asked for sons? short newDurability = repairCalculate(startDurability, baseRepairAmount); // When I asked for sons?
// We're going to hold onto our repair item location // We're going to hold onto our repair item location
int repairItemLocation; int repairItemLocation;
if (repairable.getRepairMaterialMetadata() == (byte) -1) { if (repairable.getRepairMaterialMetadata() == (byte) -1) {
repairItemLocation = Repair.findInInventory(inventory, repairMaterialId); repairItemLocation = Repair.findInInventory(inventory, repairMaterialId);
} }
else { else {
// Special case for when the repairable has metadata that must be addressed // Special case for when the repairable has metadata that must be addressed
repairItemLocation = Repair.findInInventory(inventory, repairMaterialId, repairMaterialMetadata); repairItemLocation = Repair.findInInventory(inventory, repairMaterialId, repairMaterialMetadata);
} }
// This should never happen, but if it does we need to complain loudly about it. // This should never happen, but if it does we need to complain loudly about it.
if (repairItemLocation == -1) { if (repairItemLocation == -1) {
player.sendMessage(LocaleLoader.getString("Repair.Error")); player.sendMessage(LocaleLoader.getString("Repair.Error"));
return; return;
} }
// Call event // Call event
McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, (short) (startDurability - newDurability), inventory.getItem(repairItemLocation), item); McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, (short) (startDurability - newDurability), inventory.getItem(repairItemLocation), item);
mcMMO.p.getServer().getPluginManager().callEvent(event); mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
// Handle the enchants // Handle the enchants
if (Repair.arcaneForgingEnchantLoss) { if (Repair.arcaneForgingEnchantLoss) {
addEnchants(item); addEnchants(item);
} }
// Remove the item // Remove the item
Repair.removeOneFrom(inventory, repairItemLocation); Repair.removeOneFrom(inventory, repairItemLocation);
// Give out XP like candy // Give out XP like candy
applyXpGain((int) ((startDurability - newDurability) * repairable.getXpMultiplier()) * 10); applyXpGain((int) ((startDurability - newDurability) * repairable.getXpMultiplier()) * 10);
// BWONG BWONG BWONG // BWONG BWONG BWONG
player.playSound(player.getLocation(), Sound.ANVIL_USE, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH); player.playSound(player.getLocation(), Sound.ANVIL_USE, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
// Repair the item! // Repair the item!
item.setDurability(newDurability); item.setDurability(newDurability);
} }
public void handleSalvage(Location location, ItemStack item) { public void handleSalvage(Location location, ItemStack item) {
Player player = getPlayer(); Player player = getPlayer();
if (player.getGameMode() != GameMode.SURVIVAL) { if (player.getGameMode() != GameMode.SURVIVAL) {
return; return;
} }
if (getSkillLevel() < Repair.salvageUnlockLevel) { if (getSkillLevel() < Repair.salvageUnlockLevel) {
player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptSalvage")); player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptSalvage"));
return; return;
} }
if (item.getDurability() == 0) { if (item.getDurability() == 0) {
player.setItemInHand(new ItemStack(Material.AIR)); player.setItemInHand(new ItemStack(Material.AIR));
location.setY(location.getY() + 1); location.setY(location.getY() + 1);
Misc.dropItems(location, new ItemStack(Repair.getSalvagedItem(item)), Repair.getSalvagedAmount(item) * item.getAmount()); Misc.dropItems(location, new ItemStack(Repair.getSalvagedItem(item)), Repair.getSalvagedAmount(item) * item.getAmount());
player.playSound(player.getLocation(), Sound.ANVIL_USE, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH); player.playSound(player.getLocation(), Sound.ANVIL_USE, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
player.sendMessage(LocaleLoader.getString("Repair.Skills.SalvageSuccess")); player.sendMessage(LocaleLoader.getString("Repair.Skills.SalvageSuccess"));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Repair.Skills.NotFullDurability")); player.sendMessage(LocaleLoader.getString("Repair.Skills.NotFullDurability"));
} }
} }
/** /**
* Gets the Arcane Forging rank * Gets the Arcane Forging rank
* *
* @return the current Arcane Forging rank * @return the current Arcane Forging rank
*/ */
public int getArcaneForgingRank() { public int getArcaneForgingRank() {
int skillLevel = getSkillLevel(); int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) { for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) { if (skillLevel >= tier.getLevel()) {
return tier.toNumerical(); return tier.toNumerical();
} }
} }
return 0; return 0;
} }
/** /**
* Gets chance of keeping enchantment during repair. * Gets chance of keeping enchantment during repair.
* *
* @return The chance of keeping the enchantment * @return The chance of keeping the enchantment
*/ */
public int getKeepEnchantChance() { public int getKeepEnchantChance() {
int skillLevel = getSkillLevel(); int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) { for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) { if (skillLevel >= tier.getLevel()) {
return tier.getKeepEnchantChance(); return tier.getKeepEnchantChance();
} }
} }
return 0; return 0;
} }
/** /**
* Gets chance of enchantment being downgraded during repair. * Gets chance of enchantment being downgraded during repair.
* *
* @return The chance of the enchantment being downgraded * @return The chance of the enchantment being downgraded
*/ */
public int getDowngradeEnchantChance() { public int getDowngradeEnchantChance() {
int skillLevel = getSkillLevel(); int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) { for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) { if (skillLevel >= tier.getLevel()) {
return tier.getDowngradeEnchantChance(); return tier.getDowngradeEnchantChance();
} }
} }
return 100; return 100;
} }
/** /**
* Computes repair bonuses. * Computes repair bonuses.
* *
* @param durability The durability of the item being repaired * @param durability The durability of the item being repaired
* @param repairAmount The base amount of durability repaired to the item * @param repairAmount The base amount of durability repaired to the item
* @return The final amount of durability repaired to the item * @return The final amount of durability repaired to the item
*/ */
private short repairCalculate(short durability, int repairAmount) { private short repairCalculate(short durability, int repairAmount) {
Player player = getPlayer(); Player player = getPlayer();
if (Permissions.repairMastery(player)) { if (Permissions.repairMastery(player)) {
double bonus = repairAmount * Math.min((((Repair.repairMasteryMaxBonus / Repair.repairMasteryMaxBonusLevel) * getSkillLevel()) / 100.0D), Repair.repairMasteryMaxBonus / 100.0D); double bonus = repairAmount * Math.min((((Repair.repairMasteryMaxBonus / Repair.repairMasteryMaxBonusLevel) * getSkillLevel()) / 100.0D), Repair.repairMasteryMaxBonus / 100.0D);
repairAmount += bonus; repairAmount += bonus;
} }
if (Permissions.superRepair(player) && checkPlayerProcRepair()) { if (Permissions.superRepair(player) && checkPlayerProcRepair()) {
repairAmount *= 2.0D; repairAmount *= 2.0D;
} }
if (repairAmount <= 0 || repairAmount > Short.MAX_VALUE) { if (repairAmount <= 0 || repairAmount > Short.MAX_VALUE) {
repairAmount = Short.MAX_VALUE; repairAmount = Short.MAX_VALUE;
} }
return (short) Math.max(durability - repairAmount, 0); return (short) Math.max(durability - repairAmount, 0);
} }
/** /**
* Checks for Super Repair bonus. * Checks for Super Repair bonus.
* *
* @return true if bonus granted, false otherwise * @return true if bonus granted, false otherwise
*/ */
private boolean checkPlayerProcRepair() { private boolean checkPlayerProcRepair() {
if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Repair.superRepairMaxChance, Repair.superRepairMaxBonusLevel)) { if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Repair.superRepairMaxChance, Repair.superRepairMaxBonusLevel)) {
getPlayer().sendMessage(LocaleLoader.getString("Repair.Skills.FeltEasy")); getPlayer().sendMessage(LocaleLoader.getString("Repair.Skills.FeltEasy"));
return true; return true;
} }
return false; return false;
} }
/** /**
* Handles removing & downgrading enchants. * Handles removing & downgrading enchants.
* *
* @param item Item being repaired * @param item Item being repaired
*/ */
private void addEnchants(ItemStack item) { private void addEnchants(ItemStack item) {
Player player = getPlayer(); Player player = getPlayer();
if (Permissions.arcaneBypass(player)) { if (Permissions.arcaneBypass(player)) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Perfect")); player.sendMessage(LocaleLoader.getString("Repair.Arcane.Perfect"));
return; return;
} }
Map<Enchantment, Integer> enchants = item.getEnchantments(); Map<Enchantment, Integer> enchants = item.getEnchantments();
if (enchants.isEmpty()) { if (enchants.isEmpty()) {
return; return;
} }
if (getArcaneForgingRank() == 0 || !Permissions.arcaneForging(player)) { if (getArcaneForgingRank() == 0 || !Permissions.arcaneForging(player)) {
for (Enchantment enchant : enchants.keySet()) { for (Enchantment enchant : enchants.keySet()) {
item.removeEnchantment(enchant); item.removeEnchantment(enchant);
} }
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Lost")); player.sendMessage(LocaleLoader.getString("Repair.Arcane.Lost"));
return; return;
} }
boolean downgraded = false; boolean downgraded = false;
for (Entry<Enchantment, Integer> enchant : enchants.entrySet()) { for (Entry<Enchantment, Integer> enchant : enchants.entrySet()) {
Enchantment enchantment = enchant.getKey(); Enchantment enchantment = enchant.getKey();
if (getKeepEnchantChance() > Misc.getRandom().nextInt(activationChance)) { if (getKeepEnchantChance() > Misc.getRandom().nextInt(activationChance)) {
int enchantLevel = enchant.getValue(); int enchantLevel = enchant.getValue();
if (Repair.arcaneForgingDowngrades && enchantLevel > 1 && getDowngradeEnchantChance() > Misc.getRandom().nextInt(activationChance)) { if (Repair.arcaneForgingDowngrades && enchantLevel > 1 && getDowngradeEnchantChance() > Misc.getRandom().nextInt(activationChance)) {
item.addEnchantment(enchantment, enchantLevel--); item.addEnchantment(enchantment, enchantLevel--);
downgraded = true; downgraded = true;
} }
} }
else { else {
item.removeEnchantment(enchantment); item.removeEnchantment(enchantment);
} }
} }
Map<Enchantment, Integer> newEnchants = item.getEnchantments(); Map<Enchantment, Integer> newEnchants = item.getEnchantments();
if (newEnchants.isEmpty()) { if (newEnchants.isEmpty()) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Fail")); player.sendMessage(LocaleLoader.getString("Repair.Arcane.Fail"));
} }
else if (downgraded || newEnchants.size() < enchants.size()) { else if (downgraded || newEnchants.size() < enchants.size()) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Downgrade")); player.sendMessage(LocaleLoader.getString("Repair.Arcane.Downgrade"));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Perfect")); player.sendMessage(LocaleLoader.getString("Repair.Arcane.Perfect"));
} }
} }
} }

View File

@ -1,192 +1,192 @@
package com.gmail.nossr50.skills.woodcutting; package com.gmail.nossr50.skills.woodcutting;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Tree; import org.bukkit.material.Tree;
import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.datatypes.mods.CustomBlock;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.woodcutting.Woodcutting.ExperienceGainMethod; import com.gmail.nossr50.skills.woodcutting.Woodcutting.ExperienceGainMethod;
import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModUtils; import com.gmail.nossr50.util.ModUtils;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
public class WoodcuttingManager extends SkillManager { public class WoodcuttingManager extends SkillManager {
protected static boolean treeFellerReachedThreshold = false; protected static boolean treeFellerReachedThreshold = false;
public WoodcuttingManager(McMMOPlayer mcMMOPlayer) { public WoodcuttingManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.WOODCUTTING); super(mcMMOPlayer, SkillType.WOODCUTTING);
} }
public boolean canUseLeafBlower(ItemStack heldItem) { public boolean canUseLeafBlower(ItemStack heldItem) {
return getSkillLevel() >= Woodcutting.leafBlowerUnlockLevel && ItemUtils.isAxe(heldItem); return getSkillLevel() >= Woodcutting.leafBlowerUnlockLevel && ItemUtils.isAxe(heldItem);
} }
public boolean canUseTreeFeller(ItemStack heldItem) { public boolean canUseTreeFeller(ItemStack heldItem) {
return mcMMOPlayer.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(getPlayer()) && ItemUtils.isAxe(heldItem); return mcMMOPlayer.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(getPlayer()) && ItemUtils.isAxe(heldItem);
} }
protected boolean canGetDoubleDrops() { protected boolean canGetDoubleDrops() {
return Permissions.doubleDrops(getPlayer(), skill) && SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Woodcutting.doubleDropsMaxChance, Woodcutting.doubleDropsMaxLevel); return Permissions.doubleDrops(getPlayer(), skill) && SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Woodcutting.doubleDropsMaxChance, Woodcutting.doubleDropsMaxLevel);
} }
/** /**
* Begins Woodcutting * Begins Woodcutting
* *
* @param blockState Block being broken * @param blockState Block being broken
*/ */
public void woodcuttingBlockCheck(BlockState blockState) { public void woodcuttingBlockCheck(BlockState blockState) {
int xp = Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.DEFAULT); int xp = Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.DEFAULT);
switch (blockState.getType()) { switch (blockState.getType()) {
case HUGE_MUSHROOM_1: case HUGE_MUSHROOM_1:
case HUGE_MUSHROOM_2: case HUGE_MUSHROOM_2:
break; break;
default: default:
if (canGetDoubleDrops()) { if (canGetDoubleDrops()) {
Woodcutting.checkForDoubleDrop(blockState); Woodcutting.checkForDoubleDrop(blockState);
} }
} }
applyXpGain(xp); applyXpGain(xp);
} }
/** /**
* Begins Tree Feller * Begins Tree Feller
* *
* @param blockState Block being broken * @param blockState Block being broken
*/ */
public void processTreeFeller(BlockState blockState) { public void processTreeFeller(BlockState blockState) {
Player player = getPlayer(); Player player = getPlayer();
List<BlockState> treeFellerBlocks = new ArrayList<BlockState>(); List<BlockState> treeFellerBlocks = new ArrayList<BlockState>();
switch (blockState.getType()) { switch (blockState.getType()) {
case LOG: case LOG:
case HUGE_MUSHROOM_1: case HUGE_MUSHROOM_1:
Woodcutting.processRegularTrees(blockState, treeFellerBlocks); Woodcutting.processRegularTrees(blockState, treeFellerBlocks);
break; break;
case HUGE_MUSHROOM_2: case HUGE_MUSHROOM_2:
Woodcutting.processRedMushroomTrees(blockState, treeFellerBlocks); Woodcutting.processRedMushroomTrees(blockState, treeFellerBlocks);
break; break;
default: default:
if (ModUtils.isCustomLogBlock(blockState)) { if (ModUtils.isCustomLogBlock(blockState)) {
Woodcutting.processRegularTrees(blockState, treeFellerBlocks); Woodcutting.processRegularTrees(blockState, treeFellerBlocks);
} }
break; break;
} }
// If the player is trying to break too many blocks // If the player is trying to break too many blocks
if (treeFellerReachedThreshold) { if (treeFellerReachedThreshold) {
treeFellerReachedThreshold = false; treeFellerReachedThreshold = false;
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold")); player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
return; return;
} }
// If the tool can't sustain the durability loss // If the tool can't sustain the durability loss
if (!Woodcutting.handleDurabilityLoss(treeFellerBlocks, player.getItemInHand())) { if (!Woodcutting.handleDurabilityLoss(treeFellerBlocks, player.getItemInHand())) {
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter")); player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));
int health = player.getHealth(); int health = player.getHealth();
if (health > 1) { if (health > 1) {
CombatUtils.dealDamage(player, Misc.getRandom().nextInt(health - 1)); CombatUtils.dealDamage(player, Misc.getRandom().nextInt(health - 1));
} }
return; return;
} }
dropBlocks(treeFellerBlocks); dropBlocks(treeFellerBlocks);
treeFellerReachedThreshold = false; // Reset the value after we're done with Tree Feller each time. treeFellerReachedThreshold = false; // Reset the value after we're done with Tree Feller each time.
} }
/** /**
* Handles the dropping of blocks * Handles the dropping of blocks
* *
* @param treeFellerBlocks List of blocks to be dropped * @param treeFellerBlocks List of blocks to be dropped
* @param player Player using the ability * @param player Player using the ability
*/ */
private void dropBlocks(List<BlockState> treeFellerBlocks) { private void dropBlocks(List<BlockState> treeFellerBlocks) {
Player player = getPlayer(); Player player = getPlayer();
int xp = 0; int xp = 0;
for (BlockState blockState : treeFellerBlocks) { for (BlockState blockState : treeFellerBlocks) {
if (!SkillUtils.blockBreakSimulate(blockState.getBlock(), player, true)) { if (!SkillUtils.blockBreakSimulate(blockState.getBlock(), player, true)) {
break; // TODO: Shouldn't we use continue instead? break; // TODO: Shouldn't we use continue instead?
} }
Material material = blockState.getType(); Material material = blockState.getType();
if (material == Material.HUGE_MUSHROOM_1 || material == Material.HUGE_MUSHROOM_2) { if (material == Material.HUGE_MUSHROOM_1 || material == Material.HUGE_MUSHROOM_2) {
xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER); xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER);
for (ItemStack drop : blockState.getBlock().getDrops()) { for (ItemStack drop : blockState.getBlock().getDrops()) {
Misc.dropItem(blockState.getLocation(), drop); Misc.dropItem(blockState.getLocation(), drop);
} }
} }
else if (ModUtils.isCustomLogBlock(blockState)) { else if (ModUtils.isCustomLogBlock(blockState)) {
if (canGetDoubleDrops()) { if (canGetDoubleDrops()) {
Woodcutting.checkForDoubleDrop(blockState); Woodcutting.checkForDoubleDrop(blockState);
} }
CustomBlock customBlock = ModUtils.getCustomBlock(blockState); CustomBlock customBlock = ModUtils.getCustomBlock(blockState);
xp = customBlock.getXpGain(); xp = customBlock.getXpGain();
int minimumDropAmount = customBlock.getMinimumDropAmount(); int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount(); int maximumDropAmount = customBlock.getMaximumDropAmount();
Location location = blockState.getLocation(); Location location = blockState.getLocation();
ItemStack item = customBlock.getItemDrop();; ItemStack item = customBlock.getItemDrop();;
Misc.dropItems(location, item, minimumDropAmount); Misc.dropItems(location, item, minimumDropAmount);
if (minimumDropAmount < maximumDropAmount) { if (minimumDropAmount < maximumDropAmount) {
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount); Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount);
} }
} }
else if (ModUtils.isCustomLeafBlock(blockState)) { else if (ModUtils.isCustomLeafBlock(blockState)) {
Misc.randomDropItem(blockState.getLocation(), ModUtils.getCustomBlock(blockState).getItemDrop(), 10); Misc.randomDropItem(blockState.getLocation(), ModUtils.getCustomBlock(blockState).getItemDrop(), 10);
} }
else { else {
Tree tree = (Tree) blockState.getData(); Tree tree = (Tree) blockState.getData();
switch (material) { switch (material) {
case LOG: case LOG:
if (canGetDoubleDrops()) { if (canGetDoubleDrops()) {
Woodcutting.checkForDoubleDrop(blockState); Woodcutting.checkForDoubleDrop(blockState);
} }
xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER); xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER);
Misc.dropItem(blockState.getLocation(), new ItemStack(Material.LOG, 1, tree.getSpecies().getData())); Misc.dropItem(blockState.getLocation(), new ItemStack(Material.LOG, 1, tree.getSpecies().getData()));
break; break;
case LEAVES: case LEAVES:
Misc.randomDropItem(blockState.getLocation(), new ItemStack(Material.SAPLING, 1, tree.getSpecies().getData()), 10); Misc.randomDropItem(blockState.getLocation(), new ItemStack(Material.SAPLING, 1, tree.getSpecies().getData()), 10);
break; break;
default: default:
break; break;
} }
} }
blockState.setRawData((byte) 0x0); blockState.setRawData((byte) 0x0);
blockState.setType(Material.AIR); blockState.setType(Material.AIR);
blockState.update(true); blockState.update(true);
} }
applyXpGain(xp); applyXpGain(xp);
} }
} }