Change from using Block to BlockState in many locations

Convert Herbalism ability to use BlockState instead of Block.
Move all block checks back to BlockChecks.
Don't need this if we're using BlockState
Convert Excavation to BlockState. We don't need to return booleans here
because we never edit the block state.Switch ModCheck.getCustomBlock to use BlockState
More work on the conversion to BlockState
More conversion to BlockState
Better way to handle mining drops, I believe.
Remove useless imports.
A test of making the diff look nicer
BlockChecks diff cleanup
Herbalism diff cleanup
Gotta update the block states here.
Moar blockstate.
Little more blockState stuff.
Even more blockstate.
This commit is contained in:
NuclearW 2013-02-22 11:23:46 -05:00
parent 513a9212e4
commit d052d7a3ce
24 changed files with 994 additions and 1037 deletions

View File

@ -6,6 +6,7 @@ import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -31,10 +32,10 @@ import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.runnables.StickyPistonTracker; import com.gmail.nossr50.runnables.StickyPistonTracker;
import com.gmail.nossr50.skills.excavation.Excavation; import com.gmail.nossr50.skills.excavation.Excavation;
import com.gmail.nossr50.skills.herbalism.Herbalism; import com.gmail.nossr50.skills.herbalism.Herbalism;
import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.mining.Mining;
import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.Salvage; import com.gmail.nossr50.skills.repair.Salvage;
import com.gmail.nossr50.skills.smelting.SmeltingManager; import com.gmail.nossr50.skills.smelting.Smelting;
import com.gmail.nossr50.skills.unarmed.Unarmed; import com.gmail.nossr50.skills.unarmed.Unarmed;
import com.gmail.nossr50.skills.utilities.AbilityType; import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillTools;
@ -108,15 +109,15 @@ public class BlockListener implements Listener {
return; return;
} }
Block block = event.getBlock(); BlockState blockState = event.getBlock().getState();
/* Check if the blocks placed should be monitored so they do not give out XP in the future */ /* Check if the blocks placed should be monitored so they do not give out XP in the future */
if (BlockChecks.shouldBeWatched(block)) { if (BlockChecks.shouldBeWatched(blockState)) {
mcMMO.placeStore.setTrue(block); mcMMO.placeStore.setTrue(blockState);
} }
if (Repair.anvilMessagesEnabled) { if (Repair.anvilMessagesEnabled) {
int blockID = block.getTypeId(); int blockID = blockState.getTypeId();
if (blockID == Repair.anvilID) { if (blockID == Repair.anvilID) {
Repair.placedAnvilCheck(player, blockID); Repair.placedAnvilCheck(player, blockID);
@ -146,11 +147,12 @@ public class BlockListener implements Listener {
McMMOPlayer mcMMOPlayer = Users.getPlayer(player); McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile(); PlayerProfile profile = mcMMOPlayer.getProfile();
Block block = event.getBlock(); BlockState blockState = event.getBlock().getState();
ItemStack heldItem = player.getItemInHand(); ItemStack heldItem = player.getItemInHand();
/* HERBALISM */ /* HERBALISM */
if (BlockChecks.canBeGreenTerra(block)) { if (BlockChecks.affectedByGreenTerra(blockState)) {
/* Green Terra */ /* Green Terra */
if (profile.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(player)) { if (profile.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(player)) {
SkillTools.abilityCheck(player, SkillType.HERBALISM); SkillTools.abilityCheck(player, SkillType.HERBALISM);
@ -161,53 +163,57 @@ public class BlockListener implements Listener {
* Instead, we check it inside the drops handler. * Instead, we check it inside the drops handler.
*/ */
if (Permissions.skillEnabled(player, SkillType.HERBALISM)) { if (Permissions.skillEnabled(player, SkillType.HERBALISM)) {
Herbalism.herbalismProcCheck(block, mcMMOPlayer, plugin); //Double drops
if (profile.getAbilityMode(AbilityType.GREEN_TERRA)) { //Double drops
Herbalism.herbalismProcCheck(block, mcMMOPlayer, plugin); //Triple drops if (Herbalism.herbalismBlockCheck(blockState, player)) {
blockState.update();
}
//Triple drops
if (profile.getAbilityMode(AbilityType.GREEN_TERRA) && Herbalism.herbalismBlockCheck(blockState, player)) {
blockState.update();
} }
} }
} }
/* MINING */ /* MINING */
else if (BlockChecks.canBeSuperBroken(block) && ItemChecks.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.placeStore.isTrue(block)) { else if (BlockChecks.affectedBySuperBreaker(blockState) && ItemChecks.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.placeStore.isTrue(blockState)) {
MiningManager miningManager = new MiningManager(mcMMOPlayer); Mining.miningBlockCheck(blockState, player);
miningManager.miningBlockCheck(block);
if (profile.getAbilityMode(AbilityType.SUPER_BREAKER)) { if (profile.getAbilityMode(AbilityType.SUPER_BREAKER)) {
miningManager.miningBlockCheck(block); Mining.miningBlockCheck(blockState, player);
} }
} }
/* WOOD CUTTING */ /* WOOD CUTTING */
else if (BlockChecks.isLog(block) && Permissions.skillEnabled(player, SkillType.WOODCUTTING) && !mcMMO.placeStore.isTrue(block)) { else if (BlockChecks.isLog(blockState) && Permissions.skillEnabled(player, SkillType.WOODCUTTING) && !mcMMO.placeStore.isTrue(blockState)) {
if (profile.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(player) && ItemChecks.isAxe(heldItem)) { if (profile.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(player) && ItemChecks.isAxe(heldItem)) {
Woodcutting.beginTreeFeller(mcMMOPlayer, block); Woodcutting.beginTreeFeller(blockState, player);
} }
else { else {
if (Config.getInstance().getWoodcuttingRequiresTool()) { if (Config.getInstance().getWoodcuttingRequiresTool()) {
if (ItemChecks.isAxe(heldItem)) { if (ItemChecks.isAxe(heldItem)) {
Woodcutting.beginWoodcutting(mcMMOPlayer, block); Woodcutting.beginWoodcutting(player, blockState);
} }
} }
else { else {
Woodcutting.beginWoodcutting(mcMMOPlayer, block); Woodcutting.beginWoodcutting(player, blockState);
} }
} }
} }
/* EXCAVATION */ /* EXCAVATION */
else if (BlockChecks.canBeGigaDrillBroken(block) && ItemChecks.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(block)) { else if (BlockChecks.affectedByGigaDrillBreaker(blockState) && ItemChecks.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(blockState)) {
Excavation.excavationProcCheck(block, mcMMOPlayer); Excavation.excavationBlockCheck(blockState, player);
if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) { if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
Excavation.gigaDrillBreaker(mcMMOPlayer, block); Excavation.gigaDrillBreaker(blockState, player);
} }
} }
/* Remove metadata from placed watched blocks */ /* Remove metadata from placed watched blocks */
if (BlockChecks.shouldBeWatched(block) && mcMMO.placeStore.isTrue(block)) { if (BlockChecks.shouldBeWatched(blockState) && mcMMO.placeStore.isTrue(blockState)) {
mcMMO.placeStore.setFalse(block); mcMMO.placeStore.setFalse(blockState);
} }
} }
@ -228,15 +234,20 @@ public class BlockListener implements Listener {
return; return;
} }
Block block = event.getBlock(); BlockState blockState = event.getBlock().getState();
ItemStack heldItem = player.getItemInHand(); ItemStack heldItem = player.getItemInHand();
if (Permissions.hylianLuck(player) && ItemChecks.isSword(heldItem)) { if (Permissions.hylianLuck(player) && ItemChecks.isSword(heldItem)) {
Herbalism.hylianLuck(block, player, event); if (Herbalism.processHylianLuck(blockState, player)) {
event.setCancelled(true);
blockState.update();
}
} }
else if (BlockChecks.canBeFluxMined(block) && ItemChecks.isPickaxe(heldItem) && !heldItem.containsEnchantment(Enchantment.SILK_TOUCH) && Permissions.fluxMining(player) && !mcMMO.placeStore.isTrue(block)) { else if (BlockChecks.affectedByFluxMining(blockState) && ItemChecks.isPickaxe(heldItem) && !heldItem.containsEnchantment(Enchantment.SILK_TOUCH) && Permissions.fluxMining(player) && !mcMMO.placeStore.isTrue(blockState)) {
SmeltingManager smeltingManager = new SmeltingManager(Users.getPlayer(player)); if (Smelting.processFluxMining(blockState, player)) {
smeltingManager.fluxMining(event); event.setCancelled(true);
blockState.update();
}
} }
} }
@ -258,14 +269,14 @@ public class BlockListener implements Listener {
} }
PlayerProfile profile = Users.getPlayer(player).getProfile(); PlayerProfile profile = Users.getPlayer(player).getProfile();
Block block = event.getBlock(); BlockState blockState = event.getBlock().getState();
/* /*
* ABILITY PREPARATION CHECKS * ABILITY PREPARATION CHECKS
* *
* We check permissions here before processing activation. * We check permissions here before processing activation.
*/ */
if (BlockChecks.canActivateAbilities(block)) { if (BlockChecks.canActivateAbilities(blockState)) {
ItemStack heldItem = player.getItemInHand(); ItemStack heldItem = player.getItemInHand();
if (HiddenConfig.getInstance().useEnchantmentBuffs()) { if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
@ -274,24 +285,24 @@ public class BlockListener implements Listener {
} }
} }
else { else {
if ((profile.getAbilityMode(AbilityType.SUPER_BREAKER) && !BlockChecks.canBeSuperBroken(block)) || (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && !BlockChecks.canBeGigaDrillBroken(block))) { if ((profile.getAbilityMode(AbilityType.SUPER_BREAKER) && !BlockChecks.affectedBySuperBreaker(blockState)) || (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && !BlockChecks.affectedByGigaDrillBreaker(blockState))) {
SkillTools.handleAbilitySpeedDecrease(player); SkillTools.handleAbilitySpeedDecrease(player);
} }
} }
if (profile.getToolPreparationMode(ToolType.HOE) && ItemChecks.isHoe(heldItem) && (BlockChecks.canBeGreenTerra(block) || BlockChecks.canMakeMossy(block)) && Permissions.greenTerra(player)) { if (profile.getToolPreparationMode(ToolType.HOE) && ItemChecks.isHoe(heldItem) && (BlockChecks.affectedByGreenTerra(blockState) || BlockChecks.canMakeMossy(blockState)) && Permissions.greenTerra(player)) {
SkillTools.abilityCheck(player, SkillType.HERBALISM); SkillTools.abilityCheck(player, SkillType.HERBALISM);
} }
else if (profile.getToolPreparationMode(ToolType.AXE) && ItemChecks.isAxe(heldItem) && BlockChecks.isLog(block) && Permissions.treeFeller(player)) { else if (profile.getToolPreparationMode(ToolType.AXE) && ItemChecks.isAxe(heldItem) && BlockChecks.isLog(blockState) && Permissions.treeFeller(player)) {
SkillTools.abilityCheck(player, SkillType.WOODCUTTING); SkillTools.abilityCheck(player, SkillType.WOODCUTTING);
} }
else if (profile.getToolPreparationMode(ToolType.PICKAXE) && ItemChecks.isPickaxe(heldItem) && BlockChecks.canBeSuperBroken(block) && Permissions.superBreaker(player)) { else if (profile.getToolPreparationMode(ToolType.PICKAXE) && ItemChecks.isPickaxe(heldItem) && BlockChecks.affectedBySuperBreaker(blockState) && Permissions.superBreaker(player)) {
SkillTools.abilityCheck(player, SkillType.MINING); SkillTools.abilityCheck(player, SkillType.MINING);
} }
else if (profile.getToolPreparationMode(ToolType.SHOVEL) && ItemChecks.isShovel(heldItem) && BlockChecks.canBeGigaDrillBroken(block) && Permissions.gigaDrillBreaker(player)) { else if (profile.getToolPreparationMode(ToolType.SHOVEL) && ItemChecks.isShovel(heldItem) && BlockChecks.affectedByGigaDrillBreaker(blockState) && Permissions.gigaDrillBreaker(player)) {
SkillTools.abilityCheck(player, SkillType.EXCAVATION); SkillTools.abilityCheck(player, SkillType.EXCAVATION);
} }
else if (profile.getToolPreparationMode(ToolType.FISTS) && heldItem.getType() == Material.AIR && (BlockChecks.canBeGigaDrillBroken(block) || block.getType() == Material.SNOW || (block.getType() == Material.SMOOTH_BRICK && block.getData() == 0x0)) && Permissions.berserk(player)) { else if (profile.getToolPreparationMode(ToolType.FISTS) && heldItem.getType() == Material.AIR && (BlockChecks.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW || BlockChecks.affectedByBlockCracker(blockState) && Permissions.berserk(player))) {
SkillTools.abilityCheck(player, SkillType.UNARMED); SkillTools.abilityCheck(player, SkillType.UNARMED);
} }
} }
@ -301,8 +312,8 @@ public class BlockListener implements Listener {
* *
* We don't need to check permissions here because they've already been checked for the ability to even activate. * We don't need to check permissions here because they've already been checked for the ability to even activate.
*/ */
if (profile.getAbilityMode(AbilityType.TREE_FELLER) && BlockChecks.isLog(block)) { if (profile.getAbilityMode(AbilityType.TREE_FELLER) && BlockChecks.isLog(blockState)) {
player.playSound(block.getLocation(), Sound.FIZZ, Misc.FIZZ_VOLUME, Misc.FIZZ_PITCH); player.playSound(blockState.getLocation(), Sound.FIZZ, Misc.FIZZ_VOLUME, Misc.FIZZ_PITCH);
} }
} }
@ -327,41 +338,45 @@ public class BlockListener implements Listener {
PlayerProfile profile = mcMMOPlayer.getProfile(); PlayerProfile profile = mcMMOPlayer.getProfile();
ItemStack heldItem = player.getItemInHand(); ItemStack heldItem = player.getItemInHand();
Block block = event.getBlock(); Block block = event.getBlock();
BlockState blockState = block.getState();
/* /*
* ABILITY TRIGGER CHECKS * ABILITY TRIGGER CHECKS
* *
* We don't need to check permissions here because they've already been checked for the ability to even activate. * We don't need to check permissions here because they've already been checked for the ability to even activate.
*/ */
if (profile.getAbilityMode(AbilityType.GREEN_TERRA) && BlockChecks.canMakeMossy(block)) { if (profile.getAbilityMode(AbilityType.GREEN_TERRA) && BlockChecks.canMakeMossy(blockState)) {
Herbalism.greenTerra(player, block); if (Herbalism.processGreenTerra(blockState, player)) {
blockState.update();
}
} }
else if (profile.getAbilityMode(AbilityType.BERSERK)) { else if (profile.getAbilityMode(AbilityType.BERSERK)) {
if (SkillTools.triggerCheck(player, block, AbilityType.BERSERK)) { if (SkillTools.triggerCheck(player, block, AbilityType.BERSERK)) {
if (heldItem.getType() == Material.AIR) { if (heldItem.getType() == Material.AIR) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); plugin.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));
plugin.getServer().getPluginManager().callEvent(armswing);
event.setInstaBreak(true); event.setInstaBreak(true);
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH); player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
} }
} }
// Another perm check for the cracked blocks activation // Another perm check for the cracked blocks activation
else if (BlockChecks.canBeCracked(block) && Permissions.blockCracker(player)) { else if (BlockChecks.affectedByBlockCracker(blockState) && Permissions.blockCracker(player)) {
Unarmed.blockCracker(player, block); if (Unarmed.blockCracker(player, blockState)) {
blockState.update();
}
} }
} }
else if ((profile.getSkillLevel(SkillType.WOODCUTTING) >= AdvancedConfig.getInstance().getLeafBlowUnlockLevel()) && BlockChecks.isLeaves(block)) { else if ((profile.getSkillLevel(SkillType.WOODCUTTING) >= AdvancedConfig.getInstance().getLeafBlowUnlockLevel()) && BlockChecks.isLeaves(blockState)) {
if (SkillTools.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) { if (SkillTools.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) {
if (Config.getInstance().getWoodcuttingRequiresTool()) { if (Config.getInstance().getWoodcuttingRequiresTool()) {
if (ItemChecks.isAxe(heldItem)) { if (ItemChecks.isAxe(heldItem)) {
event.setInstaBreak(true); event.setInstaBreak(true);
Woodcutting.beginLeafBlower(player, block); Woodcutting.beginLeafBlower(player, blockState);
} }
} }
else if (!(heldItem.getType() == Material.SHEARS)) { else if (!(heldItem.getType() == Material.SHEARS)) {
event.setInstaBreak(true); event.setInstaBreak(true);
Woodcutting.beginLeafBlower(player, block); Woodcutting.beginLeafBlower(player, blockState);
} }
} }
} }

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.listeners;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -326,15 +327,16 @@ public class PlayerListener implements Listener {
} }
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
BlockState blockState = block.getState();
ItemStack heldItem = player.getItemInHand(); ItemStack heldItem = player.getItemInHand();
switch (event.getAction()) { switch (event.getAction()) {
case RIGHT_CLICK_BLOCK: case RIGHT_CLICK_BLOCK:
/* ACTIVATION & ITEM CHECKS */ /* ACTIVATION & ITEM CHECKS */
if (BlockChecks.canActivateAbilities(block)) { if (BlockChecks.canActivateAbilities(blockState)) {
if (SkillTools.abilitiesEnabled) { if (SkillTools.abilitiesEnabled) {
if (BlockChecks.canActivateHerbalism(block)) { if (BlockChecks.canActivateHerbalism(blockState)) {
SkillTools.activationCheck(player, SkillType.HERBALISM); SkillTools.activationCheck(player, SkillType.HERBALISM);
} }
@ -350,8 +352,12 @@ public class PlayerListener implements Listener {
} }
/* GREEN THUMB CHECK */ /* GREEN THUMB CHECK */
if (heldItem.getType() == Material.SEEDS && BlockChecks.canMakeMossy(block)) { if (heldItem.getType() == Material.SEEDS && BlockChecks.canMakeMossy(blockState)) {
Herbalism.greenThumbBlocks(heldItem, player, block); heldItem.setAmount(heldItem.getAmount() - 1);
if (Herbalism.processGreenThumbBlocks(blockState, player) && SkillTools.blockBreakSimulate(block, player, false)) {
blockState.update();
}
} }
break; break;

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.TreeType; import org.bukkit.TreeType;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
@ -34,9 +35,11 @@ public class WorldListener implements Listener {
return; return;
} }
if (mcMMO.placeStore.isTrue(event.getLocation().getBlock())) { Location location = event.getLocation();
for (BlockState block : event.getBlocks()) {
mcMMO.placeStore.setFalse(block.getBlock()); if (mcMMO.placeStore.isTrue(location.getBlockX(), location.getBlockY(), location.getBlockZ(), location.getWorld())) {
for (BlockState blockState : event.getBlocks()) {
mcMMO.placeStore.setFalse(blockState);
} }
} }
} }

View File

@ -1,9 +1,8 @@
package com.gmail.nossr50.mods; package com.gmail.nossr50.mods;
import org.bukkit.block.Block; import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.mods.config.CustomArmorConfig; import com.gmail.nossr50.mods.config.CustomArmorConfig;
@ -47,23 +46,19 @@ public final class ModChecks {
/** /**
* Get the custom block associated with an block. * Get the custom block associated with an block.
* *
* @param block The block to check * @param blockState The block to check
* @return the block if it exists, null otherwise * @return the block if it exists, null otherwise
*/ */
public static CustomBlock getCustomBlock(Block block) { public static CustomBlock getCustomBlock(BlockState blockState) {
if (!Config.getInstance().getBlockModsEnabled()) { if (customBlocksEnabled) {
return null; ItemStack item = blockState.getData().toItemStack();
}
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); if (CustomBlocksConfig.getInstance().customItems.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if (!CustomBlocksConfig.getInstance().customItems.contains(item)) { if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return null; return block;
} }
}
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
return b;
} }
} }
@ -85,18 +80,42 @@ public final class ModChecks {
} }
/** /**
* Check if a custom block is a mining block. * Check if a custom block is a woodcutting block.
* *
* @param block The block to check * @param block The block to check
* @return true if the block is custom, false otherwise * @return true if the block represents a log, false otherwise
*/ */
public static boolean isCustomMiningBlock(Block block) { public static boolean isCustomWoodcuttingBlock(BlockState blockState) {
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) { if (CustomBlocksConfig.getInstance().customWoodcuttingBlocks.contains(item)) {
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) { for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) { if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true; return true;
}
}
}
}
return false;
}
/**
* Check if a custom block should not activate abilites.
*
* @param block The block to check
* @return true if the block represents an ability block, false otherwise
*/
public static boolean isCustomAbilityBlock(BlockState blockState) {
if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (CustomBlocksConfig.getInstance().customAbilityBlocks.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true;
}
} }
} }
} }
@ -110,13 +129,59 @@ public final class ModChecks {
* @param block The block to check * @param block The block to check
* @return true if the block is custom, false otherwise * @return true if the block is custom, false otherwise
*/ */
public static boolean isCustomExcavationBlock(Block block) { public static boolean isCustomMiningBlock(BlockState blockState) {
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) { if (CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) {
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) { for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) { if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true; return true;
}
}
}
}
return false;
}
/**
* Check if a custom block is an excavation block.
*
* @param block The block to check
* @return true if the block is custom, false otherwise
*/
public static boolean isCustomExcavationBlock(BlockState blockState) {
if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true;
}
}
}
}
return false;
}
/**
* Check if a custom block is an herbalism block.
*
* @param blockState The block to check
* @return true if the block is custom, false otherwise
*/
public static boolean isCustomHerbalismBlock(BlockState blockState) {
if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(item)) {
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true;
}
} }
} }
} }
@ -130,13 +195,15 @@ public final class ModChecks {
* @param block The block to check * @param block The block to check
* @return true if the block represents leaves, false otherwise * @return true if the block represents leaves, false otherwise
*/ */
public static boolean isCustomLeafBlock(Block block) { public static boolean isCustomLeafBlock(BlockState blockState) {
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (CustomBlocksConfig.getInstance().customLeaves.contains(item)) { if (CustomBlocksConfig.getInstance().customLeaves.contains(item)) {
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) { for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) { if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true; return true;
}
} }
} }
} }
@ -150,13 +217,15 @@ public final class ModChecks {
* @param block The block to check * @param block The block to check
* @return true if the block represents a log, false otherwise * @return true if the block represents a log, false otherwise
*/ */
public static boolean isCustomLogBlock(Block block) { public static boolean isCustomLogBlock(BlockState blockState) {
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (CustomBlocksConfig.getInstance().customLogs.contains(item)) { if (CustomBlocksConfig.getInstance().customLogs.contains(item)) {
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) { for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) { if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true; return true;
}
} }
} }
} }
@ -167,16 +236,18 @@ public final class ModChecks {
/** /**
* Check if a custom block is an ore block. * Check if a custom block is an ore block.
* *
* @param block The block to check * @param blockState The block to check
* @return true if the block represents an ore, false otherwise * @return true if the block represents an ore, false otherwise
*/ */
public static boolean isCustomOreBlock(Block block) { public static boolean isCustomOreBlock(BlockState blockState) {
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); if (customBlocksEnabled) {
ItemStack item = blockState.getData().toItemStack();
if (CustomBlocksConfig.getInstance().customOres.contains(item)) { if (CustomBlocksConfig.getInstance().customOres.contains(item)) {
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) { for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) { if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
return true; return true;
}
} }
} }
} }

View File

@ -4,8 +4,7 @@ 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.block.BlockState;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
@ -17,67 +16,34 @@ import com.gmail.nossr50.skills.utilities.PerksUtils;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.utilities.SkillType;
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.Users;
public class Excavation { public class Excavation {
/** /**
* Check to see if treasures were found. * Process treasure drops & XP gain for Excavation.
* *
* @param block The block to check * @param blockState The {@link BlockState} to check ability activation for
* @param mcMMOPlayer The player who broke the block * @param player The {@link Player} using this ability
*/ */
public static void excavationProcCheck(Block block, McMMOPlayer mcMMOPlayer) { public static void excavationBlockCheck(BlockState blockState, Player player) {
Material material = block.getType(); McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
int xp = Config.getInstance().getXp(SkillType.EXCAVATION, material); int xp = Config.getInstance().getXp(SkillType.EXCAVATION, blockState.getType());
if (xp == 0 && ModChecks.isCustomExcavationBlock(block)) { if (xp == 0 && ModChecks.isCustomExcavationBlock(blockState)) {
xp = ModChecks.getCustomBlock(block).getXpGain(); xp = ModChecks.getCustomBlock(blockState).getXpGain();
} }
Player player = mcMMOPlayer.getPlayer();
List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
if (Permissions.excavationTreasureHunter(player)) { if (Permissions.excavationTreasureHunter(player)) {
switch (material) { List<ExcavationTreasure> treasures = getTreasures(blockState);
case DIRT:
treasures = TreasuresConfig.getInstance().excavationFromDirt;
break;
case GRASS: if (!treasures.isEmpty()) {
treasures = TreasuresConfig.getInstance().excavationFromGrass; int skillLevel = mcMMOPlayer.getProfile().getSkillLevel(SkillType.EXCAVATION);
break; int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.EXCAVATION);
Location location = blockState.getLocation();
case SAND: for (ExcavationTreasure treasure : treasures) {
treasures = TreasuresConfig.getInstance().excavationFromSand; if (skillLevel >= treasure.getDropLevel() && Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) {
break;
case GRAVEL:
treasures = TreasuresConfig.getInstance().excavationFromGravel;
break;
case CLAY:
treasures = TreasuresConfig.getInstance().excavationFromClay;
break;
case MYCEL:
treasures = TreasuresConfig.getInstance().excavationFromMycel;
break;
case SOUL_SAND:
treasures = TreasuresConfig.getInstance().excavationFromSoulSand;
break;
default:
break;
}
Location location = block.getLocation();
for (ExcavationTreasure treasure : treasures) {
if (mcMMOPlayer.getProfile().getSkillLevel(SkillType.EXCAVATION) >= treasure.getDropLevel()) {
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.EXCAVATION);
if (Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) {
xp += treasure.getXp(); xp += treasure.getXp();
Misc.dropItem(location, treasure.getDrop()); Misc.dropItem(location, treasure.getDrop());
} }
@ -89,13 +55,47 @@ public class Excavation {
} }
/** /**
* Handle triple drops from Giga Drill Breaker. * Process the Giga Drill Breaker ability.
* *
* @param mcMMOPlayer The player using the ability * @param blockState The {@link BlockState} to check ability activation for
* @param block The block to check * @param player The {@link Player} using this ability
*/ */
public static void gigaDrillBreaker(McMMOPlayer mcMMOPlayer, Block block) { public static void gigaDrillBreaker(BlockState blockState, Player player) {
Excavation.excavationProcCheck(block, mcMMOPlayer); Excavation.excavationBlockCheck(blockState, player);
Excavation.excavationProcCheck(block, mcMMOPlayer); Excavation.excavationBlockCheck(blockState, player);
} }
}
/**
* Get the list of possible {@link ExcavationTreasure|ExcavationTreasures} obtained from a given block.
*
* @param blockState The {@link BlockState} of the block to check.
* @return the list of treasures that could be found
*/
private static List<ExcavationTreasure> getTreasures(BlockState blockState) {
switch (blockState.getType()) {
case DIRT:
return TreasuresConfig.getInstance().excavationFromDirt;
case GRASS:
return TreasuresConfig.getInstance().excavationFromGrass;
case SAND:
return TreasuresConfig.getInstance().excavationFromSand;
case GRAVEL:
return TreasuresConfig.getInstance().excavationFromGravel;
case CLAY:
return TreasuresConfig.getInstance().excavationFromClay;
case MYCEL:
return TreasuresConfig.getInstance().excavationFromMycel;
case SOUL_SAND:
return TreasuresConfig.getInstance().excavationFromSoulSand;
default:
return new ArrayList<ExcavationTreasure>();
}
}
}

View File

@ -1,86 +0,0 @@
package com.gmail.nossr50.skills.herbalism;
import org.bukkit.CropState;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.material.CocoaPlant;
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.SkillType;
public class GreenThumbTimer implements Runnable {
private Block block;
private PlayerProfile profile;
private Material type;
public GreenThumbTimer(Block block, PlayerProfile profile, Material material) {
this.block = block;
this.profile = profile;
this.type = material;
}
@Override
public void run() {
this.block.setType(this.type);
int skillLevel = this.profile.getSkillLevel(SkillType.HERBALISM);
int greenThumbStage = skillLevel / Herbalism.greenThumbStageChangeLevel;
if (greenThumbStage > 4) {
greenThumbStage = 4;
}
switch(this.type) {
case CROPS:
case CARROT:
case POTATO:
//This replants the wheat at a certain stage in development based on Herbalism Skill
if (!this.profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
this.block.setData((byte) greenThumbStage);
}
else {
this.block.setData(CropState.MEDIUM.getData());
}
break;
case NETHER_WARTS:
if (!this.profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
if (greenThumbStage == 3) {
this.block.setData((byte) 0x2);
}
else if (greenThumbStage == 2) {
this.block.setData((byte) 0x1);
}
else {
this.block.setData((byte) 0x0);
}
}
else {
this.block.setData((byte) 0x2);
}
break;
case COCOA:
CocoaPlant plant = (CocoaPlant) block.getState().getData();
if (!this.profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
if (greenThumbStage == 3) {
plant.setSize(CocoaPlantSize.MEDIUM);
}
else if (greenThumbStage == 2) {
plant.setSize(CocoaPlantSize.MEDIUM);
}
else {
plant.setSize(CocoaPlantSize.SMALL);
}
}
else {
plant.setSize(CocoaPlantSize.MEDIUM);
}
block.setData(plant.getData());
break;
default:
break;
}
}
}

View File

@ -3,29 +3,29 @@ package com.gmail.nossr50.skills.herbalism;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.DyeColor; import org.bukkit.CropState;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.bukkit.material.CocoaPlant;
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.TreasuresConfig; import com.gmail.nossr50.config.TreasuresConfig;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure; import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks; import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock; import com.gmail.nossr50.mods.datatypes.CustomBlock;
import com.gmail.nossr50.skills.utilities.AbilityType; import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.PerksUtils;
import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@ -65,63 +65,87 @@ public class Herbalism {
} }
/** /**
* Activate the Green Terra ability. * Process the Green Terra ability.
* *
* @param player The player activating the ability * @param blockState The {@link BlockState} to check ability activation for
* @param block The block to be changed by Green Terra * @param player The {@link Player} using this ability
* @return true if the ability was successful, false otherwise
*/ */
public static void greenTerra(Player player, Block block) { public static boolean processGreenTerra(BlockState blockState, Player player) {
PlayerInventory inventory = player.getInventory(); PlayerInventory playerInventory = player.getInventory();
boolean hasSeeds = inventory.contains(Material.SEEDS); ItemStack seed = new ItemStack(Material.SEEDS);
if (!hasSeeds) { if (!playerInventory.containsAtLeast(seed, 1)) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore")); player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
return; return false;
} }
inventory.removeItem(new ItemStack(Material.SEEDS)); playerInventory.removeItem(seed);
player.updateInventory(); // Needed until replacement available player.updateInventory(); // Needed until replacement available
greenTerraConvert(player, block);
return convertGreenTerraBlocks(blockState, player);
} }
public static void greenTerraConvert(Player player, Block block) { /**
if (SkillTools.blockBreakSimulate(block, player, false)) { * Convert blocks affected by the Green Thumb & Green Terra abilities.
Material type = block.getType(); *
* @param blockState The {@link BlockState} to check ability activation for
* @param player The {@link Player} using this ability
* @return true if the ability was successful, false otherwise
*/
private static boolean convertGreenTerraBlocks(BlockState blockState, Player player) {
Material blockType = blockState.getType();
if (!Permissions.greenThumbBlock(player, type)) { if (!Permissions.greenThumbBlock(player, blockType)) {
return; return false;
} }
switch (type) { switch (blockType) {
case SMOOTH_BRICK: case COBBLE_WALL:
block.setData((byte) 0x1); case SMOOTH_BRICK:
return; blockState.setRawData((byte) 0x1);
return true;
case DIRT: case DIRT:
block.setType(Material.GRASS); blockState.setType(Material.GRASS);
return; return true;
case COBBLESTONE: case COBBLESTONE:
block.setType(Material.MOSSY_COBBLESTONE); blockState.setType(Material.MOSSY_COBBLESTONE);
return; return true;
case COBBLE_WALL: default:
block.setData((byte) 0x1); return false;
return;
default:
return;
}
} }
} }
private static int calculateCatciAndSugarDrops(Block block) { /**
Material blockType = block.getType(); * Calculate the drop amounts for cacti & sugar cane based on the blocks above them.
*
* @param blockState The {@link BlockState} of the bottom block of the plant
* @return the number of bonus drops to award from the blocks in this plant
*/
private static int calculateCatciAndSugarDrops(BlockState blockState) {
Block block = blockState.getBlock();
Material blockType = blockState.getType();
int dropAmount = 0; int dropAmount = 0;
for (int y = 0; y <= 2; y++) { // Handle the original block
if (!mcMMO.placeStore.isTrue(blockState)) {
dropAmount++;
}
// Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
for (int y = 1; y < 3; y++) {
Block relativeBlock = block.getRelative(BlockFace.UP, y); Block relativeBlock = block.getRelative(BlockFace.UP, y);
if (relativeBlock.getType() == blockType && !mcMMO.placeStore.isTrue(relativeBlock)) { Material relativeBlockType = relativeBlock.getType();
// If the first one is air, so is the next one
if (relativeBlockType == Material.AIR) {
break;
}
if (relativeBlockType == blockType && !mcMMO.placeStore.isTrue(relativeBlock)) {
dropAmount++; dropAmount++;
} }
} }
@ -130,23 +154,18 @@ public class Herbalism {
} }
/** /**
* Check for extra Herbalism drops. * Process double drops & XP gain for Herbalism.
* *
* @param block The block to check for extra drops * @param blockState The {@link BlockState} to check ability activation for
* @param mcMMOPlayer The player getting extra drops * @param player The {@link Player} using this ability
* @param event The event to use for Green Thumb * @return true if the ability was successful, false otherwise
* @param plugin mcMMO plugin instance
*/ */
public static void herbalismProcCheck(final Block block, McMMOPlayer mcMMOPlayer, mcMMO plugin) { public static boolean herbalismBlockCheck(BlockState blockState, Player player) {
Player player = mcMMOPlayer.getPlayer();
if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle()) { if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle()) {
return; return false;
} }
PlayerProfile profile = mcMMOPlayer.getProfile(); Material blockType = blockState.getType();
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
Material blockType = block.getType();
HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(blockType); HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(blockType);
CustomBlock customBlock = null; CustomBlock customBlock = null;
@ -154,199 +173,226 @@ public class Herbalism {
int xp = 0; int xp = 0;
int dropAmount = 1; int dropAmount = 1;
ItemStack dropItem = null; ItemStack dropItem = null;
boolean update = false;
if (herbalismBlock != null) { if (herbalismBlock != null) {
if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) { if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) {
dropItem = herbalismBlock.getDropItem(); dropItem = herbalismBlock.getDropItem();
dropAmount = calculateCatciAndSugarDrops(block); dropAmount = calculateCatciAndSugarDrops(blockState);
xp = herbalismBlock.getXpGain() * dropAmount; xp = herbalismBlock.getXpGain() * dropAmount;
} }
else if (herbalismBlock.hasGreenThumbPermission(player)){ else if (herbalismBlock.hasGreenThumbPermission(player)){
dropItem = herbalismBlock.getDropItem(); dropItem = herbalismBlock.getDropItem();
xp = herbalismBlock.getXpGain(); xp = herbalismBlock.getXpGain();
update = processGreenThumbPlants(blockState, player);
greenThumbWheat(block, player, plugin);
} }
else { else {
if (!mcMMO.placeStore.isTrue(block)) { if (!mcMMO.placeStore.isTrue(blockState)) {
dropItem = herbalismBlock.getDropItem(); dropItem = herbalismBlock.getDropItem();
xp = herbalismBlock.getXpGain(); xp = herbalismBlock.getXpGain();
} }
} }
} }
else { else {
customBlock = ModChecks.getCustomBlock(block); customBlock = ModChecks.getCustomBlock(blockState);
dropItem = customBlock.getItemDrop(); dropItem = customBlock.getItemDrop();
xp = customBlock.getXpGain(); xp = customBlock.getXpGain();
} }
if (Permissions.doubleDrops(player, SkillType.HERBALISM)) { if (Permissions.doubleDrops(player, SkillType.HERBALISM) && SkillTools.activationSuccessful(player, SkillType.HERBALISM, doubleDropsMaxChance, doubleDropsMaxLevel)) {
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM); Location location = blockState.getLocation();
double chance = (doubleDropsMaxChance / doubleDropsMaxLevel) * SkillTools.skillCheck(herbLevel, doubleDropsMaxLevel);
if (chance > Misc.getRandom().nextInt(activationChance)) { if (dropItem != null && herbalismBlock != null && herbalismBlock.canDoubleDrop()) {
Location location = block.getLocation(); Misc.dropItems(location, dropItem, dropAmount);
}
else if (customBlock != null){
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
if (dropItem != null && herbalismBlock != null && herbalismBlock.canDoubleDrop()) { if (minimumDropAmount != maximumDropAmount) {
Misc.dropItems(location, dropItem, dropAmount); Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
} }
else if (customBlock != null){
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
if (minimumDropAmount != maximumDropAmount) { Misc.dropItems(location, dropItem, minimumDropAmount);
Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
}
Misc.dropItems(location, dropItem, minimumDropAmount);
}
} }
} }
mcMMOPlayer.beginXpGain(SkillType.HERBALISM, xp); Users.getPlayer(player).beginXpGain(SkillType.HERBALISM, xp);
return update;
} }
/** /**
* Apply the Green Thumb ability to crops. * Convert plants affected by the Green Terra ability.
* *
* @param block The block to apply the ability to * @param blockState The {@link BlockState} to check ability activation for
* @param player The player using the ability * @return true if the ability was successful, false otherwise
* @param event The event triggering the ability
* @param plugin mcMMO plugin instance
*/ */
private static void greenThumbWheat(Block block, Player player, mcMMO plugin) { private static boolean convertGreenTerraPlants(BlockState blockState) {
PlayerProfile profile = Users.getPlayer(player).getProfile(); switch (blockState.getType()) {
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
PlayerInventory inventory = player.getInventory();
boolean hasSeeds = false;
Material type = block.getType();
switch(type) {
case CROPS: case CROPS:
hasSeeds = inventory.contains(Material.SEEDS);
break;
case COCOA:
hasSeeds = inventory.containsAtLeast(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()), 1);
break;
case CARROT: case CARROT:
hasSeeds = inventory.contains(Material.CARROT_ITEM);
break;
case POTATO: case POTATO:
hasSeeds = inventory.contains(Material.POTATO_ITEM); blockState.setRawData(CropState.MEDIUM.getData());
break; return true;
case NETHER_WARTS: case NETHER_WARTS:
hasSeeds = inventory.contains(Material.NETHER_STALK); blockState.setRawData((byte) 0x2);
break; return true;
case COCOA:
CocoaPlant plant = (CocoaPlant) blockState.getData();
plant.setSize(CocoaPlantSize.MEDIUM);
blockState.setData(plant);
return true;
default: default:
break; return false;
}
if (!hasSeeds) {
return;
}
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
float chance = (float) (greenThumbMaxChance / greenThumbMaxLevel * herbLevel);
if (chance > greenThumbMaxChance) {
chance = (float) greenThumbMaxChance;
}
if (profile.getAbilityMode(AbilityType.GREEN_TERRA) || chance > Misc.getRandom().nextInt(activationChance)) {
switch(type) {
case CROPS:
inventory.removeItem(new ItemStack(Material.SEEDS));
break;
case COCOA:
inventory.removeItem(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()));
break;
case CARROT:
inventory.removeItem(new ItemStack(Material.CARROT_ITEM));
break;
case POTATO:
inventory.removeItem(new ItemStack(Material.POTATO_ITEM));
break;
case NETHER_WARTS:
inventory.removeItem(new ItemStack(Material.NETHER_STALK));
break;
default:
break;
}
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, profile, type), 0);
player.updateInventory(); // Needed until replacement available
} }
} }
/** /**
* Apply the Green Thumb ability to blocks. * Process the Green Thumb ability for blocks.
* *
* @param is The item in the player's hand * @param blockState The {@link BlockState} to check ability activation for
* @param player The player activating the ability * @param player The {@link Player} using this ability
* @param block The block being used in the ability * @return true if the ability was successful, false otherwise
*/ */
public static void greenThumbBlocks(ItemStack is, Player player, Block block) { public static boolean processGreenThumbBlocks(BlockState blockState, Player player) {
PlayerProfile profile = Users.getPlayer(player).getProfile(); if (!SkillTools.activationSuccessful(player, SkillType.HERBALISM, greenThumbMaxChance, greenThumbMaxLevel)) {
int skillLevel = profile.getSkillLevel(SkillType.HERBALISM);
int seeds = is.getAmount();
player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
float chance = (float) ((greenThumbMaxChance / greenThumbMaxLevel) * skillLevel);
if (chance > greenThumbMaxChance) chance = (float) greenThumbMaxChance;
if (chance > Misc.getRandom().nextInt(activationChance)) {
greenTerraConvert(player, block);
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail")); player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
return false;
}
return convertGreenTerraBlocks(blockState, player);
}
/**
* Convert plants affected by the Green Thumb ability.
*
* @param blockState The {@link BlockState} to check ability activation for
* @param skillLevel The player's Herbalism skill level
* @return true if the ability was successful, false otherwise
*/
private static boolean convertGreenThumbPlants(BlockState blockState, int skillLevel) {
int greenThumbStage = Math.min(skillLevel, greenThumbStageMaxLevel) / 4;
switch(blockState.getType()) {
case CROPS:
case CARROT:
case POTATO:
blockState.setRawData((byte) greenThumbStage);
return true;
case NETHER_WARTS:
if (greenThumbStage > 2) {
blockState.setRawData((byte) 0x2);
}
else if (greenThumbStage == 2) {
blockState.setRawData((byte) 0x1);
}
else {
blockState.setRawData((byte) 0x0);
}
return true;
case COCOA:
CocoaPlant plant = (CocoaPlant) blockState.getData();
if (greenThumbStage > 1) {
plant.setSize(CocoaPlantSize.MEDIUM);
}
else {
plant.setSize(CocoaPlantSize.SMALL);
}
blockState.setData(plant);
return true;
default:
return false;
} }
} }
public static void hylianLuck(Block block, Player player, BlockBreakEvent event) { /**
int skillLevel = Users.getPlayer(player).getProfile().getSkillLevel(SkillType.HERBALISM); * Process the Green Thumb ability for plants.
*
* @param blockState The {@link BlockState} to check ability activation for
* @param player The {@link Player} using this ability
* @return true if the ability was successful, false otherwise
*/
private static boolean processGreenThumbPlants(BlockState blockState, Player player) {
PlayerInventory playerInventory = player.getInventory();
ItemStack seed = HerbalismBlock.getHerbalismBlock(blockState.getType()).getDropItem();
double chance = (hylianLuckMaxChance / hylianLuckMaxLevel) * SkillTools.skillCheck(skillLevel, hylianLuckMaxLevel); if (!playerInventory.containsAtLeast(seed, 1)) {
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM); return false;
if (chance > Misc.getRandom().nextInt(activationChance)) {
List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
switch (block.getType()) {
case DEAD_BUSH:
case LONG_GRASS:
case SAPLING:
treasures = TreasuresConfig.getInstance().hylianFromBushes;
break;
case RED_ROSE:
case YELLOW_FLOWER:
if (mcMMO.placeStore.isTrue(block)) {
mcMMO.placeStore.setFalse(block);
return;
}
treasures = TreasuresConfig.getInstance().hylianFromFlowers;
break;
case FLOWER_POT:
treasures = TreasuresConfig.getInstance().hylianFromPots;
break;
default:
return;
}
if (treasures.isEmpty()) {
return;
}
event.setCancelled(true);
event.getBlock().setType(Material.AIR);
Misc.dropItem(block.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
} }
PlayerProfile playerProfile = Users.getPlayer(player).getProfile();
if (playerProfile.getAbilityMode(AbilityType.GREEN_TERRA)) {
playerInventory.removeItem(seed);
player.updateInventory(); // Needed until replacement available
return convertGreenTerraPlants(blockState);
}
else if (SkillTools.activationSuccessful(player, SkillType.HERBALISM, greenThumbMaxChance, greenThumbMaxLevel)) {
playerInventory.removeItem(seed);
player.updateInventory(); // Needed until replacement available
return convertGreenThumbPlants(blockState, playerProfile.getSkillLevel(SkillType.HERBALISM));
}
return false;
}
/**
* Process the Hylian Luck ability.
*
* @param blockState The {@link BlockState} to check ability activation for
* @param player The {@link Player} using this ability
* @return true if the ability was successful, false otherwise
*/
public static boolean processHylianLuck(BlockState blockState, Player player) {
if (!SkillTools.activationSuccessful(player, SkillType.HERBALISM, hylianLuckMaxChance, hylianLuckMaxLevel)) {
return false;
}
List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
switch (blockState.getType()) {
case DEAD_BUSH:
case LONG_GRASS:
case SAPLING:
treasures = TreasuresConfig.getInstance().hylianFromBushes;
break;
case RED_ROSE:
case YELLOW_FLOWER:
if (mcMMO.placeStore.isTrue(blockState)) {
mcMMO.placeStore.setFalse(blockState);
return false;
}
treasures = TreasuresConfig.getInstance().hylianFromFlowers;
break;
case FLOWER_POT:
treasures = TreasuresConfig.getInstance().hylianFromPots;
break;
default:
return false;
}
if (treasures.isEmpty()) {
return false;
}
blockState.setRawData((byte) 0x0);
blockState.setType(Material.AIR);
Misc.dropItem(blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
return true;
} }
} }

View File

@ -6,11 +6,11 @@ import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.util.BlockChecks; import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@ -20,9 +20,9 @@ public class BlastMiningDropEventHandler {
private EntityExplodeEvent event; private EntityExplodeEvent event;
private float yield; private float yield;
private List<Block> blocks; private List<Block> blocks;
private List<Block> ores = new ArrayList<Block>(); private List<BlockState> ores = new ArrayList<BlockState>();
private List<Block> debris = new ArrayList<Block>(); private List<BlockState> debris = new ArrayList<BlockState>();
private List<Block> droppedOres = new ArrayList<Block>(); private List<BlockState> droppedOres = new ArrayList<BlockState>();
private float oreBonus; private float oreBonus;
private float debrisReduction; private float debrisReduction;
private int dropMultiplier; private int dropMultiplier;
@ -38,38 +38,35 @@ public class BlastMiningDropEventHandler {
protected void sortExplosionBlocks() { protected void sortExplosionBlocks() {
for (Block block : blocks) { for (Block block : blocks) {
if (BlockChecks.isOre(block)) { BlockState blockState = block.getState();
ores.add(block);
if (BlockChecks.isOre(blockState)) {
ores.add(blockState);
} }
else { else {
debris.add(block); debris.add(blockState);
} }
} }
} }
protected void processXPGain() { protected void processXPGain() {
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer(); for (BlockState blockState : droppedOres) {
if (!mcMMO.placeStore.isTrue(blockState)) {
for (Block block : droppedOres) { Mining.awardMiningXp(blockState, manager.getMcMMOPlayer().getPlayer());
if (!mcMMO.placeStore.isTrue(block)) {
Mining.miningXP(mcMMOPlayer, block, block.getType());
} }
} }
} }
protected void processDroppedBlocks() { protected void processDroppedBlocks() {
for (Block block : ores) { for (BlockState blockState : ores) {
Location location = block.getLocation();
Material type = block.getType();
if (Misc.getRandom().nextFloat() < (yield + oreBonus)) { if (Misc.getRandom().nextFloat() < (yield + oreBonus)) {
droppedOres.add(block); droppedOres.add(blockState);
Mining.miningDrops(block, location, type); Mining.handleMiningDrops(blockState);
if (!mcMMO.placeStore.isTrue(block)) { if (!mcMMO.placeStore.isTrue(blockState)) {
for (int i = 1 ; i < dropMultiplier ; i++) { for (int i = 1 ; i < dropMultiplier ; i++) {
droppedOres.add(block); droppedOres.add(blockState);
Mining.miningDrops(block, location, type); Mining.handleMiningDrops(blockState);
} }
} }
} }
@ -78,9 +75,9 @@ public class BlastMiningDropEventHandler {
float debrisYield = yield - debrisReduction; float debrisYield = yield - debrisReduction;
if (debrisYield > 0) { if (debrisYield > 0) {
for (Block block : debris) { for (BlockState blockState : debris) {
Location location = block.getLocation(); Location location = blockState.getLocation();
Material type = block.getType(); Material type = blockState.getType();
if (Misc.getRandom().nextFloat() < debrisYield) { if (Misc.getRandom().nextFloat() < debrisYield) {
Misc.dropItem(location, new ItemStack(type)); Misc.dropItem(location, new ItemStack(type));

View File

@ -1,19 +1,21 @@
package com.gmail.nossr50.skills.mining; package com.gmail.nossr50.skills.mining;
import org.bukkit.CoalType;
import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.mods.ModChecks; import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock; 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.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class Mining { public class Mining {
private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
@ -21,44 +23,58 @@ public class Mining {
public static int doubleDropsMaxLevel = advancedConfig.getMiningDoubleDropMaxLevel(); public static int doubleDropsMaxLevel = advancedConfig.getMiningDoubleDropMaxLevel();
public static double doubleDropsMaxChance = advancedConfig.getMiningDoubleDropChance(); public static double doubleDropsMaxChance = advancedConfig.getMiningDoubleDropChance();
public static final int DIAMOND_TOOL_TIER = 4; /**
public static final int IRON_TOOL_TIER = 3; * Process double drops & XP gain for Mining.
public static final int STONE_TOOL_TIER = 2; *
* @param blockState The {@link BlockState} to check ability activation for
* @param player The {@link Player} using this ability
*/
public static void miningBlockCheck(BlockState blockState, Player player) {
awardMiningXp(blockState, player);
if (Permissions.doubleDrops(player, SkillType.MINING) && SkillTools.activationSuccessful(player, SkillType.MINING, doubleDropsMaxChance, doubleDropsMaxLevel)) {
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
handleSilkTouchDrops(blockState);
}
else {
handleMiningDrops(blockState);
}
}
}
/** /**
* Award XP for Mining blocks. * Award XP gain for Mining.
* *
* @param mcMMOPlayer The player to award XP to * @param blockState The {@link BlockState} to check ability activation for
* @param block The block to award XP for * @param player The {@link Player} using this ability
*/ */
protected static void miningXP(McMMOPlayer mcMMOPlayer, Block block, Material type) { protected static void awardMiningXp(BlockState blockState, Player player) {
int xp = Config.getInstance().getXp(SkillType.MINING, type); Material blockType = blockState.getType();
int xp = Config.getInstance().getXp(SkillType.MINING, blockType);
if (type == Material.GLOWING_REDSTONE_ORE) { if (blockType == Material.GLOWING_REDSTONE_ORE) {
xp = Config.getInstance().getXp(SkillType.MINING, Material.REDSTONE_ORE); xp = Config.getInstance().getXp(SkillType.MINING, Material.REDSTONE_ORE);
} }
else if (xp == 0 && ModChecks.isCustomMiningBlock(block)) { else if (xp == 0 && ModChecks.isCustomMiningBlock(blockState)) {
xp = ModChecks.getCustomBlock(block).getXpGain(); xp = ModChecks.getCustomBlock(blockState).getXpGain();
} }
mcMMOPlayer.beginXpGain(SkillType.MINING, xp); Users.getPlayer(player).beginXpGain(SkillType.MINING, xp);
} }
/** /**
* Handle double drops when using Silk Touch. * Handle double drops when using Silk Touch.
* *
* @param block The block to process drops for * @param blockState The {@link BlockState} to check ability activation for
* @param location The location of the block
* @param type The material type of the block
*/ */
protected static void silkTouchDrops(Block block, Location location, Material type) { protected static void handleSilkTouchDrops(BlockState blockState) {
ItemStack item = new ItemStack(type); Material blockType = blockState.getType();
if (type != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, type)) { if (blockType != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, blockType)) {
return; return;
} }
switch (type) { switch (blockType) {
case ENDER_STONE: case ENDER_STONE:
case GOLD_ORE: case GOLD_ORE:
case IRON_ORE: case IRON_ORE:
@ -66,14 +82,14 @@ public class Mining {
case NETHERRACK: case NETHERRACK:
case OBSIDIAN: case OBSIDIAN:
case SANDSTONE: case SANDSTONE:
miningDrops(block, location, type); handleMiningDrops(blockState);
break; return;
case GLOWING_REDSTONE_ORE: case GLOWING_REDSTONE_ORE:
if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) { if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) {
Misc.dropItem(location, item); Misc.dropItem(blockState.getLocation(), new ItemStack(Material.REDSTONE_ORE));
} }
break; return;
case COAL_ORE: case COAL_ORE:
case DIAMOND_ORE: case DIAMOND_ORE:
@ -82,75 +98,39 @@ public class Mining {
case LAPIS_ORE: case LAPIS_ORE:
case STONE: case STONE:
case EMERALD_ORE: case EMERALD_ORE:
Misc.dropItem(location, item); Misc.dropItem(blockState.getLocation(), new ItemStack(blockType));
break; return;
default: default:
if (ModChecks.isCustomMiningBlock(block)) { if (ModChecks.isCustomMiningBlock(blockState)) {
ItemStack dropItem = new ItemStack(block.getTypeId(), 1, block.getData()); Misc.dropItem(blockState.getLocation(), blockState.getData().toItemStack());
Misc.dropItem(location, dropItem);
} }
break; return;
} }
} }
/** /**
* Drop items from Mining & Blast Mining skills. * Handle double drops from Mining & Blast Mining.
* *
* @param block The block to process drops for * @param blockState The {@link BlockState} to check ability activation for
* @param location The location of the block
* @param type The material type of the block
*/ */
protected static void miningDrops(Block block, Location location, Material type) { protected static void handleMiningDrops(BlockState blockState) {
if (type != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, type)) { Material blockType = blockState.getType();
if (blockType != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, blockType)) {
return; return;
} }
ItemStack item = new ItemStack(type); Location location = blockState.getLocation();
ItemStack dropItem;
switch (type) { switch (blockType) {
case COAL_ORE: case COAL_ORE:
item = new ItemStack(Material.COAL, 1, CoalType.COAL.getData());
Misc.dropItem(location, item);
break;
case DIAMOND_ORE: case DIAMOND_ORE:
item = new ItemStack(Material.DIAMOND);
Misc.dropItem(location, item);
break;
case EMERALD_ORE: case EMERALD_ORE:
item = new ItemStack(Material.EMERALD);
Misc.dropItem(location, item);
break;
case GLOWING_REDSTONE_ORE:
case REDSTONE_ORE:
if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) {
item = new ItemStack(Material.REDSTONE);
Misc.dropItems(location, item, 4);
Misc.randomDropItem(location, item, 50);
}
break;
case GLOWSTONE: case GLOWSTONE:
item = new ItemStack(Material.GLOWSTONE_DUST);
Misc.dropItems(location, item, 2);
Misc.randomDropItems(location, item, 2);
break;
case LAPIS_ORE: case LAPIS_ORE:
item = new ItemStack(Material.INK_SACK, 1, DyeColor.BLUE.getDyeData());
Misc.dropItems(location, item, 4);
Misc.randomDropItems(location, item, 4);
break;
case STONE: case STONE:
item = new ItemStack(Material.COBBLESTONE);
Misc.dropItem(location, item);
break;
case ENDER_STONE: case ENDER_STONE:
case GOLD_ORE: case GOLD_ORE:
case IRON_ORE: case IRON_ORE:
@ -158,26 +138,36 @@ public class Mining {
case NETHERRACK: case NETHERRACK:
case OBSIDIAN: case OBSIDIAN:
case SANDSTONE: case SANDSTONE:
Misc.dropItem(location, item); for (ItemStack drop : blockState.getBlock().getDrops()) {
break; Misc.dropItem(location, drop);
}
return;
case GLOWING_REDSTONE_ORE:
case REDSTONE_ORE:
if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) {
for (ItemStack drop : blockState.getBlock().getDrops()) {
Misc.dropItem(location, drop);
}
}
return;
default: default:
if (ModChecks.isCustomMiningBlock(block)) { if (ModChecks.isCustomMiningBlock(blockState)) {
CustomBlock customBlock = ModChecks.getCustomBlock(block); CustomBlock customBlock = ModChecks.getCustomBlock(blockState);
int minimumDropAmount = customBlock.getMinimumDropAmount(); int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount(); int maximumDropAmount = customBlock.getMaximumDropAmount();
item = ModChecks.getCustomBlock(block).getItemDrop(); dropItem = customBlock.getItemDrop();
if (minimumDropAmount != maximumDropAmount) { if (minimumDropAmount != maximumDropAmount) {
Misc.dropItems(location, item, minimumDropAmount); Misc.dropItems(location, dropItem, minimumDropAmount);
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount); Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
} }
else { else {
Misc.dropItems(location, item, minimumDropAmount); Misc.dropItems(location, dropItem, minimumDropAmount);
} }
} }
break; return;
} }
} }
} }

View File

@ -1,45 +0,0 @@
package com.gmail.nossr50.skills.mining;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import com.gmail.nossr50.skills.utilities.SkillTools;
public class MiningBlockEventHandler {
private MiningManager manager;
private Block block;
private Location blockLocation;
private Material blockType;
protected int skillModifier;
protected MiningBlockEventHandler(MiningManager manager, Block block) {
this.manager = manager;
this.block = block;
this.blockLocation = block.getLocation();
this.blockType = block.getType();
calculateSkillModifier();
}
private void calculateSkillModifier() {
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Mining.doubleDropsMaxLevel);
}
/**
* Process Mining block drops.
*/
protected void processDrops() {
if (manager.getMcMMOPlayer().getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
Mining.silkTouchDrops(block, blockLocation, blockType);
}
else {
Mining.miningDrops(block, blockLocation, blockType);
}
}
protected void processXPGain() {
Mining.miningXP(manager.getMcMMOPlayer(), block, blockType);
}
}

View File

@ -1,7 +1,6 @@
package com.gmail.nossr50.skills.mining; package com.gmail.nossr50.skills.mining;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ExplosionPrimeEvent;
@ -12,7 +11,6 @@ import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class MiningManager extends SkillManager{ public class MiningManager extends SkillManager{
public MiningManager (McMMOPlayer mcMMOPlayer) { public MiningManager (McMMOPlayer mcMMOPlayer) {
@ -102,24 +100,4 @@ public class MiningManager extends SkillManager{
eventHandler.calculateRadiusIncrease(); eventHandler.calculateRadiusIncrease();
eventHandler.modifyBlastRadius(); eventHandler.modifyBlastRadius();
} }
/**
* Process Mining block drops.
*
* @param block The block being broken
*/
public void miningBlockCheck(Block block) {
MiningBlockEventHandler eventHandler = new MiningBlockEventHandler(this, block);
eventHandler.processXPGain();
if (!Permissions.doubleDrops(mcMMOPlayer.getPlayer(), skill)) {
return;
}
float chance = ((float) Mining.doubleDropsMaxChance / Mining.doubleDropsMaxLevel) * eventHandler.skillModifier;
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.processDrops();
}
}
} }

View File

@ -1,68 +0,0 @@
package com.gmail.nossr50.skills.smelting;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.mining.Mining;
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;
public class FluxMiningEventHandler {
private SmeltingManager manager;
private BlockBreakEvent event;
private Block block;
protected FluxMiningEventHandler(SmeltingManager manager, BlockBreakEvent event) {
this.manager = manager;
this.event = event;
this.block = event.getBlock();
}
protected void processDrops() {
ItemStack item = null;
switch (block.getType()) {
case IRON_ORE:
item = new ItemStack(Material.IRON_INGOT);
break;
case GOLD_ORE:
item = new ItemStack(Material.GOLD_INGOT);
break;
default:
break;
}
if (item == null) {
return;
}
Location location = block.getLocation();
Misc.dropItem(location, item);
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
if (Permissions.doubleDrops(mcMMOPlayer.getPlayer(), manager.getSkill())) {
int chance = (int) ((Mining.doubleDropsMaxChance / Mining.doubleDropsMaxLevel) * (SkillTools.skillCheck(mcMMOPlayer.getProfile().getSkillLevel(SkillType.MINING), Mining.doubleDropsMaxLevel)));
Misc.randomDropItem(location, item, chance);
}
}
protected void eventCancellationAndProcessing() {
event.setCancelled(true);
block.setType(Material.AIR);
}
protected void sendAbilityMessage() {
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Smelting.FluxMining.Success"));
}
}

View File

@ -1,6 +1,18 @@
package com.gmail.nossr50.skills.smelting; package com.gmail.nossr50.skills.smelting;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.mining.Mining;
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;
public class Smelting { public class Smelting {
public static int burnModifierMaxLevel = AdvancedConfig.getInstance().getBurnModifierMaxLevel(); public static int burnModifierMaxLevel = AdvancedConfig.getInstance().getBurnModifierMaxLevel();
@ -23,4 +35,49 @@ public class Smelting {
public static int vanillaXPBoostRank3Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank3Multiplier(); public static int vanillaXPBoostRank3Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank3Multiplier();
public static int vanillaXPBoostRank4Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank4Multiplier(); public static int vanillaXPBoostRank4Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank4Multiplier();
public static int vanillaXPBoostRank5Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank5Multiplier(); public static int vanillaXPBoostRank5Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank5Multiplier();
/**
* Process the Flux Mining ability.
*
* @param blockState The {@link BlockState} to check ability activation for
* @param player The {@link Player} using this ability
* @return true if the ability was successful, false otherwise
*/
public static boolean processFluxMining(BlockState blockState, Player player) {
if (SkillTools.unlockLevelReached(player, SkillType.SMELTING, fluxMiningUnlockLevel) && SkillTools.activationSuccessful(player, SkillType.SMELTING, fluxMiningChance)) {
ItemStack item = null;
switch (blockState.getType()) {
case IRON_ORE:
item = new ItemStack(Material.IRON_INGOT);
break;
case GOLD_ORE:
item = new ItemStack(Material.GOLD_INGOT);
break;
default:
break;
}
if (item == null) {
return false;
}
Location location = blockState.getLocation();
Misc.dropItem(location, item);
if (Permissions.doubleDrops(player, SkillType.SMELTING) && SkillTools.activationSuccessful(player, SkillType.SMELTING, Mining.doubleDropsMaxChance, Mining.doubleDropsMaxLevel)) {
Misc.dropItem(location, item);
}
blockState.setRawData((byte) 0x0);
blockState.setType(Material.AIR);
player.sendMessage(LocaleLoader.getString("Smelting.FluxMining.Success"));
return true;
}
return false;
}
} }

View File

@ -1,7 +1,6 @@
package com.gmail.nossr50.skills.smelting; package com.gmail.nossr50.skills.smelting;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.inventory.FurnaceBurnEvent; import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.FurnaceExtractEvent; import org.bukkit.event.inventory.FurnaceExtractEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent;
@ -60,19 +59,6 @@ public class SmeltingManager extends SkillManager {
} }
} }
public void fluxMining(BlockBreakEvent event) {
if (skillLevel < Smelting.fluxMiningUnlockLevel) {
return;
}
if (Smelting.fluxMiningChance > Misc.getRandom().nextInt(activationChance)) {
FluxMiningEventHandler eventHandler = new FluxMiningEventHandler(this, event);
eventHandler.processDrops();
eventHandler.eventCancellationAndProcessing();
eventHandler.sendAbilityMessage();
}
}
public void vanillaXPBoost(FurnaceExtractEvent event) { public void vanillaXPBoost(FurnaceExtractEvent event) {
if (skillLevel < Smelting.vanillaXPBoostRank1Level || !Permissions.vanillaXpBoost(mcMMOPlayer.getPlayer(), skill)) { if (skillLevel < Smelting.vanillaXPBoostRank1Level || !Permissions.vanillaXpBoost(mcMMOPlayer.getPlayer(), skill)) {
return; return;

View File

@ -1,7 +1,7 @@
package com.gmail.nossr50.skills.unarmed; package com.gmail.nossr50.skills.unarmed;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.BlockState;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
@ -25,20 +25,22 @@ public class Unarmed {
public static double berserkDamageModifier = 1.5; public static double berserkDamageModifier = 1.5;
public static void blockCracker(Player player, Block block) { public static boolean blockCracker(Player player, BlockState blockState) {
if (SkillTools.blockBreakSimulate(block, player, false)) { if (SkillTools.blockBreakSimulate(blockState.getBlock(), player, false)) {
Material type = block.getType(); Material type = blockState.getType();
switch (type) { switch (type) {
case SMOOTH_BRICK: case SMOOTH_BRICK:
if (blockCrackerSmoothBrick && block.getData() == 0x0) { if (blockCrackerSmoothBrick && blockState.getRawData() == (byte) 0x0) {
block.setData((byte) 0x2); blockState.setRawData((byte) 0x2);
} }
return; return true;
default: default:
return; return false;
} }
} }
return false;
} }
} }

View File

@ -1,7 +1,7 @@
package com.gmail.nossr50.skills.utilities; package com.gmail.nossr50.skills.utilities;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.BlockState;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
@ -181,28 +181,28 @@ public enum AbilityType {
/** /**
* Check if a block is affected by this ability. * Check if a block is affected by this ability.
* *
* @param block the block to check * @param blockState the block to check
* @return true if the block is affected by this ability, false otherwise * @return true if the block is affected by this ability, false otherwise
*/ */
public boolean blockCheck(Block block) { public boolean blockCheck(BlockState blockState) {
switch (this) { switch (this) {
case BERSERK: case BERSERK:
return (BlockChecks.canBeGigaDrillBroken(block) || block.getType() == Material.SNOW); return (BlockChecks.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW);
case GIGA_DRILL_BREAKER: case GIGA_DRILL_BREAKER:
return BlockChecks.canBeGigaDrillBroken(block); return BlockChecks.affectedByGigaDrillBreaker(blockState);
case GREEN_TERRA: case GREEN_TERRA:
return BlockChecks.canMakeMossy(block); return BlockChecks.canMakeMossy(blockState);
case LEAF_BLOWER: case LEAF_BLOWER:
return block.getType() == Material.LEAVES; return BlockChecks.isLeaves(blockState);
case SUPER_BREAKER: case SUPER_BREAKER:
return BlockChecks.canBeSuperBroken(block); return BlockChecks.affectedBySuperBreaker(blockState);
case TREE_FELLER: case TREE_FELLER:
return block.getType() == Material.LOG; return BlockChecks.isLog(blockState);
default: default:
return false; return false;

View File

@ -426,10 +426,8 @@ public class SkillTools {
switch (ability) { switch (ability) {
case BERSERK: case BERSERK:
case GIGA_DRILL_BREAKER:
case SUPER_BREAKER:
case LEAF_BLOWER: case LEAF_BLOWER:
if (!ability.blockCheck(block)) { if (!ability.blockCheck(block.getState())) {
activate = false; activate = false;
break; break;
} }
@ -440,8 +438,10 @@ public class SkillTools {
} }
break; break;
case GIGA_DRILL_BREAKER:
case SUPER_BREAKER:
case GREEN_TERRA: case GREEN_TERRA:
if (!ability.blockCheck(block)) { if (!ability.blockCheck(block.getState())) {
activate = false; activate = false;
break; break;
} }
@ -480,7 +480,7 @@ public class SkillTools {
} }
public static void handleAbilitySpeedIncrease(Player player) { public static void handleAbilitySpeedIncrease(Player player) {
if (HiddenConfig.getInstance().useEnchantmentBuffs()) { if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
ItemStack heldItem = player.getItemInHand(); ItemStack heldItem = player.getItemInHand();
if (heldItem == null || heldItem.getType() == Material.AIR ) { if (heldItem == null || heldItem.getType() == Material.AIR ) {
@ -583,15 +583,13 @@ public class SkillTools {
* @return true if the event wasn't cancelled, false otherwise * @return true if the event wasn't cancelled, false otherwise
*/ */
public static boolean blockBreakSimulate(Block block, Player player, Boolean shouldArmSwing) { public static boolean blockBreakSimulate(Block block, Player player, Boolean shouldArmSwing) {
PluginManager pluginManger = mcMMO.p.getServer().getPluginManager();
//Support for NoCheat //Support for NoCheat
if (shouldArmSwing) { if (shouldArmSwing) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); pluginManger.callEvent(new FakePlayerAnimationEvent(player));
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
} }
PluginManager pluginManger = mcMMO.p.getServer().getPluginManager();
FakeBlockDamageEvent damageEvent = new FakeBlockDamageEvent(player, block, player.getItemInHand(), true); FakeBlockDamageEvent damageEvent = new FakeBlockDamageEvent(player, block, player.getItemInHand(), true);
pluginManger.callEvent(damageEvent); pluginManger.callEvent(damageEvent);
@ -604,4 +602,20 @@ public class SkillTools {
return false; return false;
} }
public static boolean activationSuccessful(Player player, SkillType skill, double maxChance, int maxLevel) {
int skillLevel = Users.getPlayer(player).getProfile().getSkillLevel(skill);
int activationChance = PerksUtils.handleLuckyPerks(player, skill);
double chance = (maxChance / maxLevel) * Math.min(skillLevel, maxLevel);
return chance > Misc.getRandom().nextInt(activationChance);
}
public static boolean activationSuccessful(Player player, SkillType skill, double chance) {
return chance > Misc.getRandom().nextInt(PerksUtils.handleLuckyPerks(player, skill));
}
public static boolean unlockLevelReached(Player player, SkillType skill, int unlockLevel) {
return Users.getPlayer(player).getProfile().getSkillLevel(skill) > unlockLevel;
}
} }

View File

@ -6,13 +6,14 @@ import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.BlockState;
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.material.Tree;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks; import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock; import com.gmail.nossr50.mods.datatypes.CustomBlock;
@ -22,6 +23,7 @@ import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.skills.woodcutting.Woodcutting.ExperienceGainMethod; import com.gmail.nossr50.skills.woodcutting.Woodcutting.ExperienceGainMethod;
import com.gmail.nossr50.util.BlockChecks; import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Users;
public final class TreeFeller { public final class TreeFeller {
private static boolean treeFellerReachedThreshold = false; private static boolean treeFellerReachedThreshold = false;
@ -32,26 +34,24 @@ public final class TreeFeller {
* Begins Tree Feller * Begins Tree Feller
* *
* @param mcMMOPlayer Player using Tree Feller * @param mcMMOPlayer Player using Tree Feller
* @param block Block being broken * @param blockState Block being broken
*/ */
public static void process(McMMOPlayer mcMMOPlayer, Block block) { protected static void process(BlockState blockState, Player player) {
List<Block> treeFellerBlocks = new ArrayList<Block>(); List<BlockState> treeFellerBlocks = new ArrayList<BlockState>();
processRecursively(block, treeFellerBlocks); processRecursively(blockState, treeFellerBlocks);
// If the player is trying to break to many block // If the player is trying to break too many blocks
if (treeFellerReachedThreshold) { if (treeFellerReachedThreshold) {
treeFellerReachedThreshold = false; treeFellerReachedThreshold = false;
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold")); player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
return; return;
} }
Player player = mcMMOPlayer.getPlayer();
// If the tool can't sustain the durability loss // If the tool can't sustain the durability loss
if (!handleDurabilityLoss(treeFellerBlocks, player.getItemInHand())) { if (!handleDurabilityLoss(treeFellerBlocks, player.getItemInHand())) {
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter")); player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));
int health = player.getHealth(); int health = player.getHealth();
@ -62,28 +62,28 @@ public final class TreeFeller {
return; return;
} }
dropBlocks(treeFellerBlocks, mcMMOPlayer); dropBlocks(treeFellerBlocks, player);
} }
/** /**
* Processes Tree Feller * Processes Tree Feller
* *
* @param block Block being checked * @param blockState Block being checked
* @param treeFellerBlocks List of blocks to be removed * @param treeFellerBlocks List of blocks to be removed
*/ */
private static void processRecursively(Block block, List<Block> treeFellerBlocks) { private static void processRecursively(BlockState blockState, List<BlockState> treeFellerBlocks) {
if (!BlockChecks.isLog(block)) { if (!BlockChecks.isLog(blockState)) {
return; return;
} }
List<Block> futureCenterBlocks = new ArrayList<Block>(); List<BlockState> futureCenterBlocks = new ArrayList<BlockState>();
World world = block.getWorld(); World world = blockState.getWorld();
// Handle the blocks around 'block' // Handle the blocks around 'block'
for (int y = 0 ; y <= 1 ; y++) { for (int y = 0; y <= 1; y++) {
for (int x = -1 ; x <= 1 ; x++) { for (int x = -1; x <= 1; x++) {
for (int z = -1 ; z <= 1 ; z++) { for (int z = -1; z <= 1; z++) {
Block nextBlock = world.getBlockAt(block.getLocation().add(x, y, z)); BlockState nextBlock = world.getBlockAt(blockState.getLocation().add(x, y, z)).getState();
handleBlock(nextBlock, futureCenterBlocks, treeFellerBlocks); handleBlock(nextBlock, futureCenterBlocks, treeFellerBlocks);
@ -95,12 +95,12 @@ public final class TreeFeller {
} }
// Recursive call for each log found // Recursive call for each log found
for (Block futurCenterBlock : futureCenterBlocks) { for (BlockState futureCenterBlock : futureCenterBlocks) {
if (treeFellerReachedThreshold) { if (treeFellerReachedThreshold) {
return; return;
} }
processRecursively(futurCenterBlock, treeFellerBlocks); processRecursively(futureCenterBlock, treeFellerBlocks);
} }
} }
@ -108,23 +108,23 @@ public final class TreeFeller {
* Handle a block addition to the list of blocks to be removed * 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()' * and to the list of blocks used for future recursive calls of 'processRecursively()'
* *
* @param block Block to be added * @param blockState Block to be added
* @param futureCenterBlocks List of blocks that will be used to call 'processRecursively()' * @param futureCenterBlocks List of blocks that will be used to call 'processRecursively()'
* @param treeFellerBlocks List of blocks to be removed * @param treeFellerBlocks List of blocks to be removed
*/ */
private static void handleBlock(Block block, List<Block> futureCenterBlocks, List<Block> treeFellerBlocks) { private static void handleBlock(BlockState blockState, List<BlockState> futureCenterBlocks, List<BlockState> treeFellerBlocks) {
if (!BlockChecks.treeFellerCompatible(block) || mcMMO.placeStore.isTrue(block) || treeFellerBlocks.contains(block)) { if (!BlockChecks.affectedByTreeFeller(blockState) || mcMMO.placeStore.isTrue(blockState) || treeFellerBlocks.contains(blockState)) {
return; return;
} }
treeFellerBlocks.add(block); treeFellerBlocks.add(blockState);
if (treeFellerBlocks.size() > Woodcutting.CONFIG.getTreeFellerThreshold()) { if (treeFellerBlocks.size() > Config.getInstance().getTreeFellerThreshold()) {
treeFellerReachedThreshold = true; treeFellerReachedThreshold = true;
return; return;
} }
futureCenterBlocks.add(block); futureCenterBlocks.add(blockState);
} }
/** /**
@ -134,15 +134,15 @@ public final class TreeFeller {
* @param inHand tool being used * @param inHand tool being used
* @return True if the tool can sustain the durability loss * @return True if the tool can sustain the durability loss
*/ */
private static boolean handleDurabilityLoss(List<Block> treeFellerBlocks, ItemStack inHand) { private static boolean handleDurabilityLoss(List<BlockState> treeFellerBlocks, ItemStack inHand) {
Material inHandMaterial = inHand.getType(); Material inHandMaterial = inHand.getType();
if (inHandMaterial != Material.AIR) { if (inHandMaterial != Material.AIR) {
short durabilityLoss = 0; short durabilityLoss = 0;
int unbreakingLevel = inHand.getEnchantmentLevel(Enchantment.DURABILITY); int unbreakingLevel = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
for (Block block : treeFellerBlocks) { for (BlockState blockState : treeFellerBlocks) {
if (BlockChecks.isLog(block) && Misc.getRandom().nextInt(unbreakingLevel + 1) == 0) { if (BlockChecks.isLog(blockState) && Misc.getRandom().nextInt(unbreakingLevel + 1) == 0) {
durabilityLoss += SkillTools.toolDurabilityLoss; durabilityLoss += SkillTools.toolDurabilityLoss;
} }
} }
@ -165,87 +165,74 @@ public final class TreeFeller {
* 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 mcMMOPlayer Player using the ability * @param player Player using the ability
*/ */
private static void dropBlocks(List<Block> treeFellerBlocks, McMMOPlayer mcMMOPlayer) { private static void dropBlocks(List<BlockState> treeFellerBlocks, Player player) {
int xp = 0; int xp = 0;
for (Block block : treeFellerBlocks) { for (BlockState blockState : treeFellerBlocks) {
if (!SkillTools.blockBreakSimulate(block, mcMMOPlayer.getPlayer(), true)) { if (!SkillTools.blockBreakSimulate(blockState.getBlock(), player, true)) {
break; // TODO: Shouldn't we use continue instead? break; // TODO: Shouldn't we use continue instead?
} }
Material material = block.getType(); Material material = blockState.getType();
switch (material) { switch (material) {
case HUGE_MUSHROOM_1: case HUGE_MUSHROOM_1:
case HUGE_MUSHROOM_2: case HUGE_MUSHROOM_2:
try { xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER);
xp += Woodcutting.getExperienceFromLog(block, ExperienceGainMethod.TREE_FELLER);
}
catch (IllegalArgumentException exception) {
break;
}
// Stems have a block data value of 15 and should not drop mushrooms for (ItemStack drop : blockState.getBlock().getDrops()) {
// 0-2 mushrooms drop when you break a block Misc.dropItem(blockState.getLocation(), drop);
if (block.getData() == (byte) 15) {
break;
}
if (material == Material.HUGE_MUSHROOM_1) {
Misc.randomDropItems(block.getLocation(), new ItemStack(Material.BROWN_MUSHROOM), 2);
}
else {
Misc.randomDropItems(block.getLocation(), new ItemStack(Material.RED_MUSHROOM), 2);
} }
break; break;
case LOG:
Woodcutting.checkForDoubleDrop(mcMMOPlayer, block);
try {
xp += Woodcutting.getExperienceFromLog(block, ExperienceGainMethod.TREE_FELLER);
}
catch (IllegalArgumentException exception) {
break;
}
Misc.dropItem(block.getLocation(), new ItemStack(Material.LOG, 1, Woodcutting.extractLogItemData(block.getData())));
break;
case LEAVES:
Misc.randomDropItem(block.getLocation(), new ItemStack(Material.SAPLING, 1, Woodcutting.extractLogItemData(block.getData())), 10);
break;
default: default:
if (ModChecks.isCustomLogBlock(block)) {
Woodcutting.checkForDoubleDrop(mcMMOPlayer, block);
CustomBlock customBlock = ModChecks.getCustomBlock(block);
xp = customBlock.getXpGain();
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
Location location = block.getLocation();
ItemStack item = customBlock.getItemDrop();;
Misc.dropItems(location, item, minimumDropAmount);
if (minimumDropAmount < maximumDropAmount) {
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount);
}
}
else if (ModChecks.isCustomLeafBlock(block)) {
CustomBlock customBlock = ModChecks.getCustomBlock(block);
Misc.randomDropItem(block.getLocation(), customBlock.getItemDrop(), 10);
}
break; break;
} }
block.setData((byte) 0); if (ModChecks.isCustomLogBlock(blockState)) {
block.setType(Material.AIR); 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);
}
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();
} }
mcMMOPlayer.beginXpGain(SkillType.WOODCUTTING, xp); Users.getPlayer(player).beginXpGain(SkillType.WOODCUTTING, xp);
} }
} }

View File

@ -1,29 +1,27 @@
package com.gmail.nossr50.skills.woodcutting; package com.gmail.nossr50.skills.woodcutting;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.TreeSpecies; import org.bukkit.block.BlockState;
import org.bukkit.block.Block;
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 com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.mods.ModChecks; import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.datatypes.CustomBlock; import com.gmail.nossr50.mods.datatypes.CustomBlock;
import com.gmail.nossr50.skills.utilities.PerksUtils; import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.skills.utilities.SkillType;
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.Users; import com.gmail.nossr50.util.Users;
public final class Woodcutting { public final class Woodcutting {
static final AdvancedConfig ADVANCED_CONFIG = AdvancedConfig.getInstance(); public static double doubleDropsMaxChance = AdvancedConfig.getInstance().getWoodcuttingDoubleDropChance();
static final Config CONFIG = Config.getInstance(); public static int doubleDropsMaxLevel = AdvancedConfig.getInstance().getWoodcuttingDoubleDropMaxLevel();
protected enum ExperienceGainMethod { protected enum ExperienceGainMethod {
DEFAULT, DEFAULT,
@ -38,8 +36,8 @@ public final class Woodcutting {
* @param mcMMOPlayer Player using the ability * @param mcMMOPlayer Player using the ability
* @param block Block being broken * @param block Block being broken
*/ */
public static void beginTreeFeller(McMMOPlayer mcMMOPlayer, Block block) { public static void beginTreeFeller(BlockState blockState, Player player) {
TreeFeller.process(mcMMOPlayer, block); TreeFeller.process(blockState, player);
} }
/** /**
@ -48,10 +46,9 @@ public final class Woodcutting {
* @param player Player using the ability * @param player Player using the ability
* @param block Block being broken * @param block Block being broken
*/ */
public static void beginLeafBlower(Player player, Block block) { public static void beginLeafBlower(Player player, BlockState blockState) {
mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player)); mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));
player.playSound(blockState.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
} }
/** /**
@ -60,75 +57,61 @@ public final class Woodcutting {
* @param mcMMOPlayer Player breaking the block * @param mcMMOPlayer Player breaking the block
* @param block Block being broken * @param block Block being broken
*/ */
public static void beginWoodcutting(McMMOPlayer mcMMOPlayer, Block block) { public static void beginWoodcutting(Player player, BlockState blockState) {
int xp = 0; int xp = getExperienceFromLog(blockState, ExperienceGainMethod.DEFAULT);
if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) {
xp = ModChecks.getCustomBlock(block).getXpGain();
}
else {
try {
xp = getExperienceFromLog(block, ExperienceGainMethod.DEFAULT);
}
catch (IllegalArgumentException exception) {
return;
}
}
Player player = mcMMOPlayer.getPlayer();
if (Permissions.doubleDrops(player, SkillType.WOODCUTTING)) { if (Permissions.doubleDrops(player, SkillType.WOODCUTTING)) {
checkForDoubleDrop(mcMMOPlayer, block); checkForDoubleDrop(player, blockState);
} }
mcMMOPlayer.beginXpGain(SkillType.WOODCUTTING, xp); Users.getPlayer(player).beginXpGain(SkillType.WOODCUTTING, xp);
} }
/** /**
* Retrieves the experience reward from a log * Retrieves the experience reward from a log
* *
* @param log Log being broken * @param blockState Log being broken
* @param experienceGainMethod How the log is being broken * @param experienceGainMethod How the log is being broken
* @return Amount of experience * @return Amount of experience
* @throws IllegalArgumentException if 'log' is invalid
*/ */
protected static int getExperienceFromLog(Block log, ExperienceGainMethod experienceGainMethod) { protected static int getExperienceFromLog(BlockState blockState, ExperienceGainMethod experienceGainMethod) {
// Mushrooms aren't trees so we could never get species data from them // Mushrooms aren't trees so we could never get species data from them
switch (log.getType()) { switch (blockState.getType()) {
case HUGE_MUSHROOM_1: case HUGE_MUSHROOM_1:
return Config.getInstance().getWoodcuttingXPHugeBrownMushroom(); return Config.getInstance().getWoodcuttingXPHugeBrownMushroom();
case HUGE_MUSHROOM_2: case HUGE_MUSHROOM_2:
return Config.getInstance().getWoodcuttingXPHugeRedMushroom(); return Config.getInstance().getWoodcuttingXPHugeRedMushroom();
default: default:
break; break;
} }
TreeSpecies logType = TreeSpecies.getByData(extractLogItemData(log.getData())); if (ModChecks.isCustomLogBlock(blockState)) {
return ModChecks.getCustomBlock(blockState).getXpGain();
// 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();
} }
switch (logType) { switch (((Tree) blockState.getData()).getSpecies()) {
case GENERIC: case GENERIC:
return Config.getInstance().getWoodcuttingXPOak(); return Config.getInstance().getWoodcuttingXPOak();
case REDWOOD: case REDWOOD:
return Config.getInstance().getWoodcuttingXPSpruce(); return Config.getInstance().getWoodcuttingXPSpruce();
case BIRCH: case BIRCH:
return Config.getInstance().getWoodcuttingXPBirch(); return Config.getInstance().getWoodcuttingXPBirch();
case JUNGLE: case JUNGLE:
int xp = Config.getInstance().getWoodcuttingXPJungle(); int xp = Config.getInstance().getWoodcuttingXPJungle();
switch (experienceGainMethod) { if (experienceGainMethod == ExperienceGainMethod.TREE_FELLER) {
case TREE_FELLER: xp *= 0.5;
return (int) (xp * 0.5);
default:
return xp;
} }
return xp;
default: default:
throw new IllegalArgumentException(); return 0;
} }
} }
@ -136,28 +119,18 @@ public final class Woodcutting {
* Checks for double drops * Checks for double drops
* *
* @param mcMMOPlayer Player breaking the block * @param mcMMOPlayer Player breaking the block
* @param block Block being broken * @param blockState Block being broken
*/ */
protected static void checkForDoubleDrop(McMMOPlayer mcMMOPlayer, Block block) { protected static void checkForDoubleDrop(Player player, BlockState blockState) {
Player player = mcMMOPlayer.getPlayer(); if (!SkillTools.activationSuccessful(player, SkillType.WOODCUTTING, doubleDropsMaxChance, doubleDropsMaxLevel)) {
double configDoubleDropChance = ADVANCED_CONFIG.getWoodcuttingDoubleDropChance();
int configDoubleDropMaxLevel = ADVANCED_CONFIG.getWoodcuttingDoubleDropMaxLevel();
int probability = (int) ((configDoubleDropChance / configDoubleDropMaxLevel) * Users.getPlayer(player).getProfile().getSkillLevel(SkillType.WOODCUTTING));
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.WOODCUTTING);
if (probability > configDoubleDropChance) {
probability = (int) configDoubleDropChance;
}
if (probability <= Misc.getRandom().nextInt(activationChance)) {
return; return;
} }
if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) { if (ModChecks.isCustomLogBlock(blockState)) {
CustomBlock customBlock = ModChecks.getCustomBlock(block); CustomBlock customBlock = ModChecks.getCustomBlock(blockState);
int minimumDropAmount = customBlock.getMinimumDropAmount(); int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount(); int maximumDropAmount = customBlock.getMaximumDropAmount();
Location location = block.getLocation(); Location location = blockState.getLocation();
ItemStack item = customBlock.getItemDrop(); ItemStack item = customBlock.getItemDrop();
Misc.dropItems(location, item, minimumDropAmount); Misc.dropItems(location, item, minimumDropAmount);
@ -167,44 +140,37 @@ public final class Woodcutting {
} }
} }
else { else {
byte itemData = extractLogItemData(block.getData()); Location location = blockState.getLocation();
Location location = block.getLocation(); ItemStack item = blockState.getData().toItemStack();
ItemStack item = new ItemStack(Material.LOG, 1, itemData);
switch (TreeSpecies.getByData(itemData)) { switch (((Tree) blockState.getData()).getSpecies()) {
case GENERIC: case GENERIC:
if (Config.getInstance().getOakDoubleDropsEnabled()) { if (Config.getInstance().getOakDoubleDropsEnabled()) {
Misc.dropItem(location, item); Misc.dropItem(location, item);
} }
break; return;
case REDWOOD: case REDWOOD:
if (Config.getInstance().getSpruceDoubleDropsEnabled()) { if (Config.getInstance().getSpruceDoubleDropsEnabled()) {
Misc.dropItem(location, item); Misc.dropItem(location, item);
} }
break; return;
case BIRCH: case BIRCH:
if (Config.getInstance().getBirchDoubleDropsEnabled()) { if (Config.getInstance().getBirchDoubleDropsEnabled()) {
Misc.dropItem(location, item); Misc.dropItem(location, item);
} }
break; return;
case JUNGLE: case JUNGLE:
if (Config.getInstance().getJungleDoubleDropsEnabled()) { if (Config.getInstance().getJungleDoubleDropsEnabled()) {
Misc.dropItem(location, item); Misc.dropItem(location, item);
} }
break; return;
default: default:
break; return;
} }
} }
} }
/**
* Extracts the log type from the block data (i.e. removes rotation)
*
* @param data Original block data
* @return Extracted log type
*/
protected static byte extractLogItemData(byte data) {
return (byte) (data & 0x3);
}
} }

View File

@ -29,8 +29,7 @@ public class WoodcuttingCommand extends SkillCommand {
treeFellerLengthEndurance = treeFellerStrings[1]; treeFellerLengthEndurance = treeFellerStrings[1];
//DOUBLE DROPS //DOUBLE DROPS
AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); String[] doubleDropStrings = calculateAbilityDisplayValues(Woodcutting.doubleDropsMaxLevel, Woodcutting.doubleDropsMaxChance);
String[] doubleDropStrings = calculateAbilityDisplayValues(advancedConfig.getWoodcuttingDoubleDropMaxLevel(), advancedConfig.getWoodcuttingDoubleDropChance());
doubleDropChance = doubleDropStrings[0]; doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1]; doubleDropChanceLucky = doubleDropStrings[1];
} }

View File

@ -1,30 +1,24 @@
package com.gmail.nossr50.util; package com.gmail.nossr50.util;
import org.bukkit.CropState; import org.bukkit.CropState;
import org.bukkit.Material; import org.bukkit.block.BlockState;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.CocoaPlant; import org.bukkit.material.CocoaPlant;
import org.bukkit.material.MaterialData;
import org.bukkit.material.CocoaPlant.CocoaPlantSize; import org.bukkit.material.CocoaPlant.CocoaPlantSize;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.mods.ModChecks; import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.mods.config.CustomBlocksConfig;
public final class BlockChecks { public final class BlockChecks {
private static Config configInstance = Config.getInstance();
private BlockChecks() {} private BlockChecks() {}
/** /**
* Checks to see if a block type awards XP. * Checks to see if a given block awards XP.
* *
* @param block Block to check * @param blockState The {@link BlockState} of the block to check
* @return true if the block type awards XP, false otherwise * @return true if the block awards XP, false otherwise
*/ */
public static boolean shouldBeWatched(Block block) { public static boolean shouldBeWatched(BlockState blockState) {
switch (block.getType()) { switch (blockState.getType()) {
case BROWN_MUSHROOM: case BROWN_MUSHROOM:
case CACTUS: case CACTUS:
case CLAY: case CLAY:
@ -64,30 +58,18 @@ public final class BlockChecks {
return true; return true;
default: default:
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); return ModChecks.getCustomBlock(blockState) != null;
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customItems.contains(item)) {
return true;
}
return false;
} }
} }
/** /**
* Check if a block should allow for the activation of abilities. * Check if a given block should allow for the activation of abilities
* *
* @param block Block to check * @param blockState The {@link BlockState} of the block to check
* @return true if the block should allow ability activation, false otherwise * @return true if the block should allow ability activation, false otherwise
*/ */
public static boolean canActivateAbilities(Block block) { public static boolean canActivateAbilities(BlockState blockState) {
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); switch (blockState.getType()) {
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customAbilityBlocks.contains(item)) {
return false;
}
switch (block.getType()) {
case BED_BLOCK: case BED_BLOCK:
case BREWING_STAND: case BREWING_STAND:
case BOOKSHELF: case BOOKSHELF:
@ -114,7 +96,13 @@ public final class BlockChecks {
return false; return false;
default: default:
if (block.getTypeId() == Config.getInstance().getRepairAnvilId() || block.getTypeId() == Config.getInstance().getSalvageAnvilId()) { int blockId = blockState.getTypeId();
if (blockId == Config.getInstance().getRepairAnvilId() || blockId == Config.getInstance().getSalvageAnvilId()) {
return false;
}
if (ModChecks.isCustomAbilityBlock(blockState)) {
return false; return false;
} }
@ -123,13 +111,13 @@ public final class BlockChecks {
} }
/** /**
* Check if a block type is an ore. * Check if a given block is an ore
* *
* @param block Block to check * @param blockState The {@link BlockState} of the block to check
* @return true if the Block is an ore, false otherwise * @return true if the block is an ore, false otherwise
*/ */
public static boolean isOre(Block block) { public static boolean isOre(BlockState blockState) {
switch (block.getType()) { switch (blockState.getType()) {
case COAL_ORE: case COAL_ORE:
case DIAMOND_ORE: case DIAMOND_ORE:
case GLOWING_REDSTONE_ORE: case GLOWING_REDSTONE_ORE:
@ -141,32 +129,25 @@ public final class BlockChecks {
return true; return true;
default: default:
if (configInstance.getBlockModsEnabled() && ModChecks.isCustomOreBlock(block)) { return ModChecks.isCustomOreBlock(blockState);
return true;
}
return false;
} }
} }
/** /**
* Check if a block can be made mossy. * Determine if a given block can be made mossy
* *
* @param block The block to check * @param blockState The {@link BlockState} of the block to check
* @return true if the block can be made mossy, false otherwise * @return true if the block can be made mossy, false otherwise
*/ */
public static boolean canMakeMossy(Block block) { public static boolean canMakeMossy(BlockState blockState) {
switch (block.getType()) { switch (blockState.getType()) {
case COBBLESTONE: case COBBLESTONE:
case DIRT: case DIRT:
return true; return true;
case SMOOTH_BRICK: case SMOOTH_BRICK:
case COBBLE_WALL: case COBBLE_WALL:
if (block.getData() == (byte)0x0) { return blockState.getRawData() == (byte) 0x0;
return true;
}
return false;
default: default:
return false; return false;
@ -174,13 +155,13 @@ public final class BlockChecks {
} }
/** /**
* Check if a block is affected by Herbalism abilities. * Determine if a given block should be affected by Green Terra
* *
* @param block Block to check * @param blockState The {@link BlockState} of the block to check
* @return true if the block is affected, false otherwise * @return true if the block should affected by Green Terra, false otherwise
*/ */
public static boolean canBeGreenTerra(Block block) { public static boolean affectedByGreenTerra(BlockState blockState) {
switch (block.getType()) { switch (blockState.getType()) {
case BROWN_MUSHROOM: case BROWN_MUSHROOM:
case CACTUS: case CACTUS:
case MELON_BLOCK: case MELON_BLOCK:
@ -196,44 +177,27 @@ public final class BlockChecks {
case CARROT: case CARROT:
case CROPS: case CROPS:
case POTATO: case POTATO:
if (block.getData() == CropState.RIPE.getData()) { return blockState.getRawData() == CropState.RIPE.getData();
return true;
}
return false;
case NETHER_WARTS: case NETHER_WARTS:
if (block.getData() == (byte) 0x3) { return blockState.getRawData() == (byte) 0x3;
return true;
}
return false;
case COCOA: case COCOA:
CocoaPlant plant = (CocoaPlant) block.getState().getData(); return ((CocoaPlant) blockState.getData()).getSize() == CocoaPlantSize.LARGE;
if (plant.getSize() == CocoaPlantSize.LARGE) {
return true;
}
return false;
default: default:
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); return ModChecks.isCustomHerbalismBlock(blockState);
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(item)) {
return true;
}
return false;
} }
} }
/** /**
* Check to see if a block is broken by Super Breaker. * Determine if a given block should be affected by Super Breaker
* *
* @param block Block to check * @param blockState The {@link BlockState} of the block to check
* @return true if the block would be broken by Super Breaker, false otherwise * @return true if the block should affected by Super Breaker, false otherwise
*/ */
public static Boolean canBeSuperBroken(Block block) { public static Boolean affectedBySuperBreaker(BlockState blockState) {
switch (block.getType()) { switch (blockState.getType()) {
case COAL_ORE: case COAL_ORE:
case DIAMOND_ORE: case DIAMOND_ORE:
case ENDER_STONE: case ENDER_STONE:
@ -252,24 +216,18 @@ public final class BlockChecks {
return true; return true;
default: default:
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); return ModChecks.isCustomMiningBlock(blockState);
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) {
return true;
}
return false;
} }
} }
/** /**
* Check to see if a block can be broken by Giga Drill Breaker. * Determine if a given block should be affected by Giga Drill Breaker
* *
* @param block Block to check * @param blockState The {@link BlockState} of the block to check
* @return true if the block can be broken by Giga Drill Breaker, false otherwise * @return true if the block should affected by Giga Drill Breaker, false otherwise
*/ */
public static boolean canBeGigaDrillBroken(Block block) { public static boolean affectedByGigaDrillBreaker(BlockState blockState) {
switch (block.getType()) { switch (blockState.getType()) {
case CLAY: case CLAY:
case DIRT: case DIRT:
case GRASS: case GRASS:
@ -280,24 +238,18 @@ public final class BlockChecks {
return true; return true;
default: default:
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); return ModChecks.isCustomExcavationBlock(blockState);
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) {
return true;
}
return false;
} }
} }
/** /**
* Checks if the block is affected by Tree Feller. * Determine if a given block should be affected by Tree Feller
* *
* @param block Block to check * @param blockState The {@link BlockState} of the block to check
* @return true if the block is affected by Tree Feller, false otherwise * @return true if the block should affected by Tree Feller, false otherwise
*/ */
public static boolean treeFellerCompatible(Block block) { public static boolean affectedByTreeFeller(BlockState blockState) {
switch (block.getType()) { switch (blockState.getType()) {
case LOG: case LOG:
case LEAVES: case LEAVES:
case HUGE_MUSHROOM_1: case HUGE_MUSHROOM_1:
@ -305,38 +257,52 @@ public final class BlockChecks {
return true; return true;
default: default:
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1); return ModChecks.isCustomWoodcuttingBlock(blockState);
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customWoodcuttingBlocks.contains(item)) {
return true;
}
return false;
} }
} }
public static boolean isLog(Block block) { /**
switch (block.getType()) { * Check if a given block is a log
*
* @param blockState The {@link BlockState} of the block to check
* @return true if the block is a log, false otherwise
*/
public static boolean isLog(BlockState blockState) {
switch (blockState.getType()) {
case LOG: case LOG:
case HUGE_MUSHROOM_1: case HUGE_MUSHROOM_1:
case HUGE_MUSHROOM_2: case HUGE_MUSHROOM_2:
return true; return true;
default: default:
return (configInstance.getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)); return ModChecks.isCustomLogBlock(blockState);
} }
} }
public static boolean isLeaves(Block block) { /**
if (block.getType() == Material.LEAVES || (configInstance.getBlockModsEnabled() && ModChecks.isCustomLeafBlock(block))) { * Check if a given block is a leaf
*
* @param blockState The {@link BlockState} of the block to check
* @return true if the block is a leaf, false otherwise
*/
public static boolean isLeaves(BlockState blockState) {
switch (blockState.getType()) {
case LEAVES:
return true; return true;
}
return false; default:
return ModChecks.isCustomLeafBlock(blockState);
}
} }
public static boolean canBeFluxMined(Block block) { /**
switch (block.getType()) { * Determine if a given block should be affected by Flux Mining
*
* @param blockState The {@link BlockState} of the block to check
* @return true if the block should affected by Flux Mining, false otherwise
*/
public static boolean affectedByFluxMining(BlockState blockState) {
switch (blockState.getType()) {
case IRON_ORE: case IRON_ORE:
case GOLD_ORE: case GOLD_ORE:
return true; return true;
@ -346,8 +312,14 @@ public final class BlockChecks {
} }
} }
public static boolean canActivateHerbalism(Block block) { /**
switch (block.getType()) { * Determine if a given block can activate Herbalism abilities
*
* @param blockState The {@link BlockState} of the block to check
* @return true if the block can be made mossy, false otherwise
*/
public static boolean canActivateHerbalism(BlockState blockState) {
switch (blockState.getType()) {
case DIRT: case DIRT:
case GRASS: case GRASS:
case SOIL: case SOIL:
@ -358,13 +330,16 @@ public final class BlockChecks {
} }
} }
public static boolean canBeCracked(Block block) { /**
switch(block.getType()) { * Determine if a given block should be affected by Block Cracker
*
* @param blockState The {@link BlockState} of the block to check
* @return true if the block should affected by Block Cracker, false otherwise
*/
public static boolean affectedByBlockCracker(BlockState blockState) {
switch (blockState.getType()) {
case SMOOTH_BRICK: case SMOOTH_BRICK:
if (block.getData() == 0x0) { return blockState.getRawData() == (byte) 0x0;
return true;
}
return false;
default: default:
return false; return false;

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
public interface ChunkManager { public interface ChunkManager {
@ -60,6 +61,7 @@ public interface ChunkManager {
public void saveChunk(int cx, int cz, World world); public void saveChunk(int cx, int cz, World world);
public boolean isChunkLoaded(int cx, int cz, World world); public boolean isChunkLoaded(int cx, int cz, World world);
/** /**
* Informs the ChunkletManager a chunk is loaded * Informs the ChunkletManager a chunk is loaded
* *
@ -128,6 +130,14 @@ public interface ChunkManager {
*/ */
public boolean isTrue(Block block); public boolean isTrue(Block block);
/**
* Check to see if a given BlockState location is set to true
*
* @param location BlockState location to check
* @return true if the given BlockState location is set to true, false if otherwise
*/
public boolean isTrue(BlockState blockState);
/** /**
* Set a given location to true, should create stores as necessary if the location does not exist * Set a given location to true, should create stores as necessary if the location does not exist
* *
@ -145,6 +155,13 @@ public interface ChunkManager {
*/ */
public void setTrue(Block block); public void setTrue(Block block);
/**
* Set a given BlockState location to true, should create stores as necessary if the location does not exist
*
* @param block BlockState location to set
*/
public void setTrue(BlockState blockState);
/** /**
* Set a given location to false, should not create stores if one does not exist for the given location * Set a given location to false, should not create stores if one does not exist for the given location
* *
@ -162,6 +179,13 @@ public interface ChunkManager {
*/ */
public void setFalse(Block block); public void setFalse(Block block);
/**
* Set a given BlockState location to false, should not create stores if one does not exist for the given location
*
* @param block BlockState location to set
*/
public void setFalse(BlockState blockState);
/** /**
* Delete any ChunkletStores that are empty * Delete any ChunkletStores that are empty
*/ */

View File

@ -14,6 +14,7 @@ import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.getspout.spoutapi.chunkstore.mcMMOSimpleRegionFile; import org.getspout.spoutapi.chunkstore.mcMMOSimpleRegionFile;
@ -317,6 +318,15 @@ public class HashChunkManager implements ChunkManager {
return isTrue(block.getX(), block.getY(), block.getZ(), block.getWorld()); return isTrue(block.getX(), block.getY(), block.getZ(), block.getWorld());
} }
@Override
public synchronized boolean isTrue(BlockState blockState) {
if (blockState == null) {
return false;
}
return isTrue(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld());
}
@Override @Override
public synchronized void setTrue(int x, int y, int z, World world) { public synchronized void setTrue(int x, int y, int z, World world) {
if (world == null) if (world == null)
@ -352,6 +362,14 @@ public class HashChunkManager implements ChunkManager {
setTrue(block.getX(), block.getY(), block.getZ(), block.getWorld()); setTrue(block.getX(), block.getY(), block.getZ(), block.getWorld());
} }
@Override
public void setTrue(BlockState blockState) {
if (blockState == null)
return;
setTrue(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld());
}
@Override @Override
public synchronized void setFalse(int x, int y, int z, World world) { public synchronized void setFalse(int x, int y, int z, World world) {
if (world == null) if (world == null)
@ -380,12 +398,22 @@ public class HashChunkManager implements ChunkManager {
@Override @Override
public synchronized void setFalse(Block block) { public synchronized void setFalse(Block block) {
if (block == null) if (block == null) {
return; return;
}
setFalse(block.getX(), block.getY(), block.getZ(), block.getWorld()); setFalse(block.getX(), block.getY(), block.getZ(), block.getWorld());
} }
@Override
public synchronized void setFalse(BlockState blockState) {
if (blockState == null) {
return;
}
setFalse(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld());
}
@Override @Override
public synchronized void cleanUp() {} public synchronized void cleanUp() {}

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
public class NullChunkManager implements ChunkManager { public class NullChunkManager implements ChunkManager {
@ -73,18 +74,29 @@ public class NullChunkManager implements ChunkManager {
return false; return false;
} }
@Override
public boolean isTrue(BlockState blockState) {
return false;
}
@Override @Override
public void setTrue(int x, int y, int z, World world) {} public void setTrue(int x, int y, int z, World world) {}
@Override @Override
public void setTrue(Block block) {} public void setTrue(Block block) {}
@Override
public void setTrue(BlockState blockState) {}
@Override @Override
public void setFalse(int x, int y, int z, World world) {} public void setFalse(int x, int y, int z, World world) {}
@Override @Override
public void setFalse(Block block) {} public void setFalse(Block block) {}
@Override
public void setFalse(BlockState blockState) {}
@Override @Override
public void cleanUp() {} public void cleanUp() {}
} }