mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
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:
parent
513a9212e4
commit
d052d7a3ce
@ -6,6 +6,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
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.skills.excavation.Excavation;
|
||||
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.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.utilities.AbilityType;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
@ -108,15 +109,15 @@ public class BlockListener implements Listener {
|
||||
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 */
|
||||
if (BlockChecks.shouldBeWatched(block)) {
|
||||
mcMMO.placeStore.setTrue(block);
|
||||
if (BlockChecks.shouldBeWatched(blockState)) {
|
||||
mcMMO.placeStore.setTrue(blockState);
|
||||
}
|
||||
|
||||
if (Repair.anvilMessagesEnabled) {
|
||||
int blockID = block.getTypeId();
|
||||
int blockID = blockState.getTypeId();
|
||||
|
||||
if (blockID == Repair.anvilID) {
|
||||
Repair.placedAnvilCheck(player, blockID);
|
||||
@ -146,11 +147,12 @@ public class BlockListener implements Listener {
|
||||
|
||||
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
|
||||
PlayerProfile profile = mcMMOPlayer.getProfile();
|
||||
Block block = event.getBlock();
|
||||
BlockState blockState = event.getBlock().getState();
|
||||
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
|
||||
/* HERBALISM */
|
||||
if (BlockChecks.canBeGreenTerra(block)) {
|
||||
if (BlockChecks.affectedByGreenTerra(blockState)) {
|
||||
/* Green Terra */
|
||||
if (profile.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(player)) {
|
||||
SkillTools.abilityCheck(player, SkillType.HERBALISM);
|
||||
@ -161,53 +163,57 @@ public class BlockListener implements Listener {
|
||||
* Instead, we check it inside the drops handler.
|
||||
*/
|
||||
if (Permissions.skillEnabled(player, SkillType.HERBALISM)) {
|
||||
Herbalism.herbalismProcCheck(block, mcMMOPlayer, plugin); //Double drops
|
||||
|
||||
if (profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
|
||||
Herbalism.herbalismProcCheck(block, mcMMOPlayer, plugin); //Triple drops
|
||||
//Double drops
|
||||
if (Herbalism.herbalismBlockCheck(blockState, player)) {
|
||||
blockState.update();
|
||||
}
|
||||
|
||||
//Triple drops
|
||||
if (profile.getAbilityMode(AbilityType.GREEN_TERRA) && Herbalism.herbalismBlockCheck(blockState, player)) {
|
||||
blockState.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* MINING */
|
||||
else if (BlockChecks.canBeSuperBroken(block) && ItemChecks.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.placeStore.isTrue(block)) {
|
||||
MiningManager miningManager = new MiningManager(mcMMOPlayer);
|
||||
miningManager.miningBlockCheck(block);
|
||||
else if (BlockChecks.affectedBySuperBreaker(blockState) && ItemChecks.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.placeStore.isTrue(blockState)) {
|
||||
Mining.miningBlockCheck(blockState, player);
|
||||
|
||||
if (profile.getAbilityMode(AbilityType.SUPER_BREAKER)) {
|
||||
miningManager.miningBlockCheck(block);
|
||||
Mining.miningBlockCheck(blockState, player);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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)) {
|
||||
Woodcutting.beginTreeFeller(mcMMOPlayer, block);
|
||||
Woodcutting.beginTreeFeller(blockState, player);
|
||||
}
|
||||
else {
|
||||
if (Config.getInstance().getWoodcuttingRequiresTool()) {
|
||||
if (ItemChecks.isAxe(heldItem)) {
|
||||
Woodcutting.beginWoodcutting(mcMMOPlayer, block);
|
||||
Woodcutting.beginWoodcutting(player, blockState);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Woodcutting.beginWoodcutting(mcMMOPlayer, block);
|
||||
Woodcutting.beginWoodcutting(player, blockState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* EXCAVATION */
|
||||
else if (BlockChecks.canBeGigaDrillBroken(block) && ItemChecks.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(block)) {
|
||||
Excavation.excavationProcCheck(block, mcMMOPlayer);
|
||||
else if (BlockChecks.affectedByGigaDrillBreaker(blockState) && ItemChecks.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(blockState)) {
|
||||
Excavation.excavationBlockCheck(blockState, player);
|
||||
|
||||
if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
|
||||
Excavation.gigaDrillBreaker(mcMMOPlayer, block);
|
||||
Excavation.gigaDrillBreaker(blockState, player);
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove metadata from placed watched blocks */
|
||||
if (BlockChecks.shouldBeWatched(block) && mcMMO.placeStore.isTrue(block)) {
|
||||
mcMMO.placeStore.setFalse(block);
|
||||
if (BlockChecks.shouldBeWatched(blockState) && mcMMO.placeStore.isTrue(blockState)) {
|
||||
mcMMO.placeStore.setFalse(blockState);
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,15 +234,20 @@ public class BlockListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
BlockState blockState = event.getBlock().getState();
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
|
||||
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.affectedByFluxMining(blockState) && ItemChecks.isPickaxe(heldItem) && !heldItem.containsEnchantment(Enchantment.SILK_TOUCH) && Permissions.fluxMining(player) && !mcMMO.placeStore.isTrue(blockState)) {
|
||||
if (Smelting.processFluxMining(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)) {
|
||||
SmeltingManager smeltingManager = new SmeltingManager(Users.getPlayer(player));
|
||||
smeltingManager.fluxMining(event);
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,14 +269,14 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
|
||||
PlayerProfile profile = Users.getPlayer(player).getProfile();
|
||||
Block block = event.getBlock();
|
||||
BlockState blockState = event.getBlock().getState();
|
||||
|
||||
/*
|
||||
* ABILITY PREPARATION CHECKS
|
||||
*
|
||||
* We check permissions here before processing activation.
|
||||
*/
|
||||
if (BlockChecks.canActivateAbilities(block)) {
|
||||
if (BlockChecks.canActivateAbilities(blockState)) {
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
|
||||
if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
|
||||
@ -274,24 +285,24 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -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.
|
||||
*/
|
||||
if (profile.getAbilityMode(AbilityType.TREE_FELLER) && BlockChecks.isLog(block)) {
|
||||
player.playSound(block.getLocation(), Sound.FIZZ, Misc.FIZZ_VOLUME, Misc.FIZZ_PITCH);
|
||||
if (profile.getAbilityMode(AbilityType.TREE_FELLER) && BlockChecks.isLog(blockState)) {
|
||||
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();
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
Block block = event.getBlock();
|
||||
BlockState blockState = block.getState();
|
||||
|
||||
/*
|
||||
* ABILITY TRIGGER CHECKS
|
||||
*
|
||||
* 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)) {
|
||||
Herbalism.greenTerra(player, block);
|
||||
if (profile.getAbilityMode(AbilityType.GREEN_TERRA) && BlockChecks.canMakeMossy(blockState)) {
|
||||
if (Herbalism.processGreenTerra(blockState, player)) {
|
||||
blockState.update();
|
||||
}
|
||||
}
|
||||
else if (profile.getAbilityMode(AbilityType.BERSERK)) {
|
||||
if (SkillTools.triggerCheck(player, block, AbilityType.BERSERK)) {
|
||||
if (heldItem.getType() == Material.AIR) {
|
||||
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
|
||||
plugin.getServer().getPluginManager().callEvent(armswing);
|
||||
plugin.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));
|
||||
|
||||
event.setInstaBreak(true);
|
||||
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
|
||||
}
|
||||
}
|
||||
// Another perm check for the cracked blocks activation
|
||||
else if (BlockChecks.canBeCracked(block) && Permissions.blockCracker(player)) {
|
||||
Unarmed.blockCracker(player, block);
|
||||
else if (BlockChecks.affectedByBlockCracker(blockState) && Permissions.blockCracker(player)) {
|
||||
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 (Config.getInstance().getWoodcuttingRequiresTool()) {
|
||||
if (ItemChecks.isAxe(heldItem)) {
|
||||
event.setInstaBreak(true);
|
||||
Woodcutting.beginLeafBlower(player, block);
|
||||
Woodcutting.beginLeafBlower(player, blockState);
|
||||
}
|
||||
}
|
||||
else if (!(heldItem.getType() == Material.SHEARS)) {
|
||||
event.setInstaBreak(true);
|
||||
Woodcutting.beginLeafBlower(player, block);
|
||||
Woodcutting.beginLeafBlower(player, blockState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.gmail.nossr50.listeners;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -326,15 +327,16 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
BlockState blockState = block.getState();
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
|
||||
switch (event.getAction()) {
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
|
||||
/* ACTIVATION & ITEM CHECKS */
|
||||
if (BlockChecks.canActivateAbilities(block)) {
|
||||
if (BlockChecks.canActivateAbilities(blockState)) {
|
||||
if (SkillTools.abilitiesEnabled) {
|
||||
if (BlockChecks.canActivateHerbalism(block)) {
|
||||
if (BlockChecks.canActivateHerbalism(blockState)) {
|
||||
SkillTools.activationCheck(player, SkillType.HERBALISM);
|
||||
}
|
||||
|
||||
@ -350,8 +352,12 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
/* GREEN THUMB CHECK */
|
||||
if (heldItem.getType() == Material.SEEDS && BlockChecks.canMakeMossy(block)) {
|
||||
Herbalism.greenThumbBlocks(heldItem, player, block);
|
||||
if (heldItem.getType() == Material.SEEDS && BlockChecks.canMakeMossy(blockState)) {
|
||||
heldItem.setAmount(heldItem.getAmount() - 1);
|
||||
|
||||
if (Herbalism.processGreenThumbBlocks(blockState, player) && SkillTools.blockBreakSimulate(block, player, false)) {
|
||||
blockState.update();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
@ -34,9 +35,11 @@ public class WorldListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mcMMO.placeStore.isTrue(event.getLocation().getBlock())) {
|
||||
for (BlockState block : event.getBlocks()) {
|
||||
mcMMO.placeStore.setFalse(block.getBlock());
|
||||
Location location = event.getLocation();
|
||||
|
||||
if (mcMMO.placeStore.isTrue(location.getBlockX(), location.getBlockY(), location.getBlockZ(), location.getWorld())) {
|
||||
for (BlockState blockState : event.getBlocks()) {
|
||||
mcMMO.placeStore.setFalse(blockState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package com.gmail.nossr50.mods;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.mods.config.CustomArmorConfig;
|
||||
@ -47,23 +46,19 @@ public final class ModChecks {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static CustomBlock getCustomBlock(Block block) {
|
||||
if (!Config.getInstance().getBlockModsEnabled()) {
|
||||
return null;
|
||||
public static CustomBlock getCustomBlock(BlockState blockState) {
|
||||
if (customBlocksEnabled) {
|
||||
ItemStack item = blockState.getData().toItemStack();
|
||||
|
||||
if (CustomBlocksConfig.getInstance().customItems.contains(item)) {
|
||||
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
|
||||
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
|
||||
return block;
|
||||
}
|
||||
|
||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
||||
|
||||
if (!CustomBlocksConfig.getInstance().customItems.contains(item)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
|
||||
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,21 +80,45 @@ 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
|
||||
* @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) {
|
||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
||||
public static boolean isCustomWoodcuttingBlock(BlockState blockState) {
|
||||
if (customBlocksEnabled) {
|
||||
ItemStack item = blockState.getData().toItemStack();
|
||||
|
||||
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) {
|
||||
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
|
||||
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
||||
if (CustomBlocksConfig.getInstance().customWoodcuttingBlocks.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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -110,16 +129,62 @@ public final class ModChecks {
|
||||
* @param block The block to check
|
||||
* @return true if the block is custom, false otherwise
|
||||
*/
|
||||
public static boolean isCustomExcavationBlock(Block block) {
|
||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
||||
public static boolean isCustomMiningBlock(BlockState blockState) {
|
||||
if (customBlocksEnabled) {
|
||||
ItemStack item = blockState.getData().toItemStack();
|
||||
|
||||
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) {
|
||||
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
|
||||
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
||||
if (CustomBlocksConfig.getInstance().customMiningBlocks.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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -130,16 +195,18 @@ public final class ModChecks {
|
||||
* @param block The block to check
|
||||
* @return true if the block represents leaves, false otherwise
|
||||
*/
|
||||
public static boolean isCustomLeafBlock(Block block) {
|
||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
||||
public static boolean isCustomLeafBlock(BlockState blockState) {
|
||||
if (customBlocksEnabled) {
|
||||
ItemStack item = blockState.getData().toItemStack();
|
||||
|
||||
if (CustomBlocksConfig.getInstance().customLeaves.contains(item)) {
|
||||
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
|
||||
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
||||
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
|
||||
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -150,16 +217,18 @@ public final class ModChecks {
|
||||
* @param block The block to check
|
||||
* @return true if the block represents a log, false otherwise
|
||||
*/
|
||||
public static boolean isCustomLogBlock(Block block) {
|
||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
||||
public static boolean isCustomLogBlock(BlockState blockState) {
|
||||
if (customBlocksEnabled) {
|
||||
ItemStack item = blockState.getData().toItemStack();
|
||||
|
||||
if (CustomBlocksConfig.getInstance().customLogs.contains(item)) {
|
||||
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
|
||||
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
||||
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
|
||||
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -167,19 +236,21 @@ public final class ModChecks {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static boolean isCustomOreBlock(Block block) {
|
||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
||||
public static boolean isCustomOreBlock(BlockState blockState) {
|
||||
if (customBlocksEnabled) {
|
||||
ItemStack item = blockState.getData().toItemStack();
|
||||
|
||||
if (CustomBlocksConfig.getInstance().customOres.contains(item)) {
|
||||
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
|
||||
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
||||
for (CustomBlock block : CustomBlocksConfig.getInstance().customBlocks) {
|
||||
if ((block.getItemID() == blockState.getTypeId()) && (block.getDataValue() == blockState.getRawData())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class Excavation {
|
||||
|
||||
/**
|
||||
* Check to see if treasures were found.
|
||||
* Process treasure drops & XP gain for Excavation.
|
||||
*
|
||||
* @param block The block to check
|
||||
* @param mcMMOPlayer The player who broke the block
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
* @param player The {@link Player} using this ability
|
||||
*/
|
||||
public static void excavationProcCheck(Block block, McMMOPlayer mcMMOPlayer) {
|
||||
Material material = block.getType();
|
||||
int xp = Config.getInstance().getXp(SkillType.EXCAVATION, material);
|
||||
public static void excavationBlockCheck(BlockState blockState, Player player) {
|
||||
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
|
||||
int xp = Config.getInstance().getXp(SkillType.EXCAVATION, blockState.getType());
|
||||
|
||||
if (xp == 0 && ModChecks.isCustomExcavationBlock(block)) {
|
||||
xp = ModChecks.getCustomBlock(block).getXpGain();
|
||||
if (xp == 0 && ModChecks.isCustomExcavationBlock(blockState)) {
|
||||
xp = ModChecks.getCustomBlock(blockState).getXpGain();
|
||||
}
|
||||
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
|
||||
|
||||
if (Permissions.excavationTreasureHunter(player)) {
|
||||
switch (material) {
|
||||
case DIRT:
|
||||
treasures = TreasuresConfig.getInstance().excavationFromDirt;
|
||||
break;
|
||||
List<ExcavationTreasure> treasures = getTreasures(blockState);
|
||||
|
||||
case GRASS:
|
||||
treasures = TreasuresConfig.getInstance().excavationFromGrass;
|
||||
break;
|
||||
|
||||
case SAND:
|
||||
treasures = TreasuresConfig.getInstance().excavationFromSand;
|
||||
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();
|
||||
if (!treasures.isEmpty()) {
|
||||
int skillLevel = mcMMOPlayer.getProfile().getSkillLevel(SkillType.EXCAVATION);
|
||||
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.EXCAVATION);
|
||||
Location location = blockState.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()) {
|
||||
if (skillLevel >= treasure.getDropLevel() && Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) {
|
||||
xp += treasure.getXp();
|
||||
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 block The block to check
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
* @param player The {@link Player} using this ability
|
||||
*/
|
||||
public static void gigaDrillBreaker(McMMOPlayer mcMMOPlayer, Block block) {
|
||||
Excavation.excavationProcCheck(block, mcMMOPlayer);
|
||||
Excavation.excavationProcCheck(block, mcMMOPlayer);
|
||||
public static void gigaDrillBreaker(BlockState blockState, Player player) {
|
||||
Excavation.excavationBlockCheck(blockState, player);
|
||||
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>();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,29 +3,29 @@ package com.gmail.nossr50.skills.herbalism;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.CropState;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
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.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.TreasuresConfig;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mods.ModChecks;
|
||||
import com.gmail.nossr50.mods.datatypes.CustomBlock;
|
||||
import com.gmail.nossr50.skills.utilities.AbilityType;
|
||||
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.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 block The block to be changed by Green Terra
|
||||
* @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 void greenTerra(Player player, Block block) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
boolean hasSeeds = inventory.contains(Material.SEEDS);
|
||||
public static boolean processGreenTerra(BlockState blockState, Player player) {
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
ItemStack seed = new ItemStack(Material.SEEDS);
|
||||
|
||||
if (!hasSeeds) {
|
||||
if (!playerInventory.containsAtLeast(seed, 1)) {
|
||||
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
|
||||
greenTerraConvert(player, block);
|
||||
|
||||
return convertGreenTerraBlocks(blockState, player);
|
||||
}
|
||||
|
||||
public static void greenTerraConvert(Player player, Block block) {
|
||||
if (SkillTools.blockBreakSimulate(block, player, false)) {
|
||||
Material type = block.getType();
|
||||
/**
|
||||
* Convert blocks affected by the Green Thumb & Green Terra abilities.
|
||||
*
|
||||
* @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)) {
|
||||
return;
|
||||
if (!Permissions.greenThumbBlock(player, blockType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
switch (blockType) {
|
||||
case COBBLE_WALL:
|
||||
case SMOOTH_BRICK:
|
||||
block.setData((byte) 0x1);
|
||||
return;
|
||||
blockState.setRawData((byte) 0x1);
|
||||
return true;
|
||||
|
||||
case DIRT:
|
||||
block.setType(Material.GRASS);
|
||||
return;
|
||||
blockState.setType(Material.GRASS);
|
||||
return true;
|
||||
|
||||
case COBBLESTONE:
|
||||
block.setType(Material.MOSSY_COBBLESTONE);
|
||||
return;
|
||||
|
||||
case COBBLE_WALL:
|
||||
block.setData((byte) 0x1);
|
||||
return;
|
||||
blockState.setType(Material.MOSSY_COBBLESTONE);
|
||||
return true;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
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++;
|
||||
}
|
||||
}
|
||||
@ -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 mcMMOPlayer The player getting extra drops
|
||||
* @param event The event to use for Green Thumb
|
||||
* @param plugin mcMMO plugin instance
|
||||
* @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 void herbalismProcCheck(final Block block, McMMOPlayer mcMMOPlayer, mcMMO plugin) {
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
public static boolean herbalismBlockCheck(BlockState blockState, Player player) {
|
||||
if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
PlayerProfile profile = mcMMOPlayer.getProfile();
|
||||
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
||||
Material blockType = block.getType();
|
||||
Material blockType = blockState.getType();
|
||||
|
||||
HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(blockType);
|
||||
CustomBlock customBlock = null;
|
||||
@ -154,38 +173,34 @@ public class Herbalism {
|
||||
int xp = 0;
|
||||
int dropAmount = 1;
|
||||
ItemStack dropItem = null;
|
||||
boolean update = false;
|
||||
|
||||
if (herbalismBlock != null) {
|
||||
if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) {
|
||||
dropItem = herbalismBlock.getDropItem();
|
||||
dropAmount = calculateCatciAndSugarDrops(block);
|
||||
dropAmount = calculateCatciAndSugarDrops(blockState);
|
||||
xp = herbalismBlock.getXpGain() * dropAmount;
|
||||
}
|
||||
else if (herbalismBlock.hasGreenThumbPermission(player)){
|
||||
dropItem = herbalismBlock.getDropItem();
|
||||
xp = herbalismBlock.getXpGain();
|
||||
|
||||
greenThumbWheat(block, player, plugin);
|
||||
update = processGreenThumbPlants(blockState, player);
|
||||
}
|
||||
else {
|
||||
if (!mcMMO.placeStore.isTrue(block)) {
|
||||
if (!mcMMO.placeStore.isTrue(blockState)) {
|
||||
dropItem = herbalismBlock.getDropItem();
|
||||
xp = herbalismBlock.getXpGain();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
customBlock = ModChecks.getCustomBlock(block);
|
||||
customBlock = ModChecks.getCustomBlock(blockState);
|
||||
dropItem = customBlock.getItemDrop();
|
||||
xp = customBlock.getXpGain();
|
||||
}
|
||||
|
||||
if (Permissions.doubleDrops(player, SkillType.HERBALISM)) {
|
||||
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
|
||||
double chance = (doubleDropsMaxChance / doubleDropsMaxLevel) * SkillTools.skillCheck(herbLevel, doubleDropsMaxLevel);
|
||||
|
||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
||||
Location location = block.getLocation();
|
||||
if (Permissions.doubleDrops(player, SkillType.HERBALISM) && SkillTools.activationSuccessful(player, SkillType.HERBALISM, doubleDropsMaxChance, doubleDropsMaxLevel)) {
|
||||
Location location = blockState.getLocation();
|
||||
|
||||
if (dropItem != null && herbalismBlock != null && herbalismBlock.canDoubleDrop()) {
|
||||
Misc.dropItems(location, dropItem, dropAmount);
|
||||
@ -201,120 +216,150 @@ public class Herbalism {
|
||||
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 player The player using the ability
|
||||
* @param event The event triggering the ability
|
||||
* @param plugin mcMMO plugin instance
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
* @return true if the ability was successful, false otherwise
|
||||
*/
|
||||
private static void greenThumbWheat(Block block, Player player, mcMMO plugin) {
|
||||
PlayerProfile profile = Users.getPlayer(player).getProfile();
|
||||
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
boolean hasSeeds = false;
|
||||
Material type = block.getType();
|
||||
|
||||
switch(type) {
|
||||
private static boolean convertGreenTerraPlants(BlockState blockState) {
|
||||
switch (blockState.getType()) {
|
||||
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:
|
||||
hasSeeds = inventory.contains(Material.CARROT_ITEM);
|
||||
break;
|
||||
case POTATO:
|
||||
hasSeeds = inventory.contains(Material.POTATO_ITEM);
|
||||
break;
|
||||
blockState.setRawData(CropState.MEDIUM.getData());
|
||||
return true;
|
||||
|
||||
case NETHER_WARTS:
|
||||
hasSeeds = inventory.contains(Material.NETHER_STALK);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
blockState.setRawData((byte) 0x2);
|
||||
return true;
|
||||
|
||||
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;
|
||||
}
|
||||
CocoaPlant plant = (CocoaPlant) blockState.getData();
|
||||
plant.setSize(CocoaPlantSize.MEDIUM);
|
||||
blockState.setData(plant);
|
||||
return true;
|
||||
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, profile, type), 0);
|
||||
player.updateInventory(); // Needed until replacement available
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the Green Thumb ability to blocks.
|
||||
* Process the Green Thumb ability for blocks.
|
||||
*
|
||||
* @param is The item in the player's hand
|
||||
* @param player The player activating the ability
|
||||
* @param block The block being used in the 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 void greenThumbBlocks(ItemStack is, Player player, Block block) {
|
||||
PlayerProfile profile = Users.getPlayer(player).getProfile();
|
||||
int skillLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
||||
int seeds = is.getAmount();
|
||||
public static boolean processGreenThumbBlocks(BlockState blockState, Player player) {
|
||||
if (!SkillTools.activationSuccessful(player, SkillType.HERBALISM, greenThumbMaxChance, greenThumbMaxLevel)) {
|
||||
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
|
||||
return false;
|
||||
}
|
||||
|
||||
player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
|
||||
return convertGreenTerraBlocks(blockState, player);
|
||||
}
|
||||
|
||||
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
|
||||
/**
|
||||
* 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;
|
||||
|
||||
float chance = (float) ((greenThumbMaxChance / greenThumbMaxLevel) * skillLevel);
|
||||
if (chance > greenThumbMaxChance) chance = (float) greenThumbMaxChance;
|
||||
switch(blockState.getType()) {
|
||||
case CROPS:
|
||||
case CARROT:
|
||||
case POTATO:
|
||||
blockState.setRawData((byte) greenThumbStage);
|
||||
return true;
|
||||
|
||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
||||
greenTerraConvert(player, block);
|
||||
case NETHER_WARTS:
|
||||
if (greenThumbStage > 2) {
|
||||
blockState.setRawData((byte) 0x2);
|
||||
}
|
||||
else if (greenThumbStage == 2) {
|
||||
blockState.setRawData((byte) 0x1);
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
|
||||
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);
|
||||
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.HERBALISM);
|
||||
if (!playerInventory.containsAtLeast(seed, 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
||||
List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
|
||||
|
||||
switch (block.getType()) {
|
||||
switch (blockState.getType()) {
|
||||
case DEAD_BUSH:
|
||||
case LONG_GRASS:
|
||||
case SAPLING:
|
||||
@ -323,9 +368,9 @@ public class Herbalism {
|
||||
|
||||
case RED_ROSE:
|
||||
case YELLOW_FLOWER:
|
||||
if (mcMMO.placeStore.isTrue(block)) {
|
||||
mcMMO.placeStore.setFalse(block);
|
||||
return;
|
||||
if (mcMMO.placeStore.isTrue(blockState)) {
|
||||
mcMMO.placeStore.setFalse(blockState);
|
||||
return false;
|
||||
}
|
||||
|
||||
treasures = TreasuresConfig.getInstance().hylianFromFlowers;
|
||||
@ -336,17 +381,18 @@ public class Herbalism {
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (treasures.isEmpty()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
event.getBlock().setType(Material.AIR);
|
||||
Misc.dropItem(block.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,11 @@ import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.util.BlockChecks;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
@ -20,9 +20,9 @@ public class BlastMiningDropEventHandler {
|
||||
private EntityExplodeEvent event;
|
||||
private float yield;
|
||||
private List<Block> blocks;
|
||||
private List<Block> ores = new ArrayList<Block>();
|
||||
private List<Block> debris = new ArrayList<Block>();
|
||||
private List<Block> droppedOres = new ArrayList<Block>();
|
||||
private List<BlockState> ores = new ArrayList<BlockState>();
|
||||
private List<BlockState> debris = new ArrayList<BlockState>();
|
||||
private List<BlockState> droppedOres = new ArrayList<BlockState>();
|
||||
private float oreBonus;
|
||||
private float debrisReduction;
|
||||
private int dropMultiplier;
|
||||
@ -38,38 +38,35 @@ public class BlastMiningDropEventHandler {
|
||||
|
||||
protected void sortExplosionBlocks() {
|
||||
for (Block block : blocks) {
|
||||
if (BlockChecks.isOre(block)) {
|
||||
ores.add(block);
|
||||
BlockState blockState = block.getState();
|
||||
|
||||
if (BlockChecks.isOre(blockState)) {
|
||||
ores.add(blockState);
|
||||
}
|
||||
else {
|
||||
debris.add(block);
|
||||
debris.add(blockState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void processXPGain() {
|
||||
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
|
||||
|
||||
for (Block block : droppedOres) {
|
||||
if (!mcMMO.placeStore.isTrue(block)) {
|
||||
Mining.miningXP(mcMMOPlayer, block, block.getType());
|
||||
for (BlockState blockState : droppedOres) {
|
||||
if (!mcMMO.placeStore.isTrue(blockState)) {
|
||||
Mining.awardMiningXp(blockState, manager.getMcMMOPlayer().getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void processDroppedBlocks() {
|
||||
for (Block block : ores) {
|
||||
Location location = block.getLocation();
|
||||
Material type = block.getType();
|
||||
|
||||
for (BlockState blockState : ores) {
|
||||
if (Misc.getRandom().nextFloat() < (yield + oreBonus)) {
|
||||
droppedOres.add(block);
|
||||
Mining.miningDrops(block, location, type);
|
||||
droppedOres.add(blockState);
|
||||
Mining.handleMiningDrops(blockState);
|
||||
|
||||
if (!mcMMO.placeStore.isTrue(block)) {
|
||||
if (!mcMMO.placeStore.isTrue(blockState)) {
|
||||
for (int i = 1 ; i < dropMultiplier ; i++) {
|
||||
droppedOres.add(block);
|
||||
Mining.miningDrops(block, location, type);
|
||||
droppedOres.add(blockState);
|
||||
Mining.handleMiningDrops(blockState);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,9 +75,9 @@ public class BlastMiningDropEventHandler {
|
||||
float debrisYield = yield - debrisReduction;
|
||||
|
||||
if (debrisYield > 0) {
|
||||
for (Block block : debris) {
|
||||
Location location = block.getLocation();
|
||||
Material type = block.getType();
|
||||
for (BlockState blockState : debris) {
|
||||
Location location = blockState.getLocation();
|
||||
Material type = blockState.getType();
|
||||
|
||||
if (Misc.getRandom().nextFloat() < debrisYield) {
|
||||
Misc.dropItem(location, new ItemStack(type));
|
||||
|
@ -1,19 +1,21 @@
|
||||
package com.gmail.nossr50.skills.mining;
|
||||
|
||||
import org.bukkit.CoalType;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
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 com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.mods.ModChecks;
|
||||
import com.gmail.nossr50.mods.datatypes.CustomBlock;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class Mining {
|
||||
private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
||||
@ -21,44 +23,58 @@ public class Mining {
|
||||
public static int doubleDropsMaxLevel = advancedConfig.getMiningDoubleDropMaxLevel();
|
||||
public static double doubleDropsMaxChance = advancedConfig.getMiningDoubleDropChance();
|
||||
|
||||
public static final int DIAMOND_TOOL_TIER = 4;
|
||||
public static final int IRON_TOOL_TIER = 3;
|
||||
public static final int STONE_TOOL_TIER = 2;
|
||||
/**
|
||||
* Process double drops & XP gain for Mining.
|
||||
*
|
||||
* @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 block The block to award XP for
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
* @param player The {@link Player} using this ability
|
||||
*/
|
||||
protected static void miningXP(McMMOPlayer mcMMOPlayer, Block block, Material type) {
|
||||
int xp = Config.getInstance().getXp(SkillType.MINING, type);
|
||||
protected static void awardMiningXp(BlockState blockState, Player player) {
|
||||
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);
|
||||
}
|
||||
else if (xp == 0 && ModChecks.isCustomMiningBlock(block)) {
|
||||
xp = ModChecks.getCustomBlock(block).getXpGain();
|
||||
else if (xp == 0 && ModChecks.isCustomMiningBlock(blockState)) {
|
||||
xp = ModChecks.getCustomBlock(blockState).getXpGain();
|
||||
}
|
||||
|
||||
mcMMOPlayer.beginXpGain(SkillType.MINING, xp);
|
||||
Users.getPlayer(player).beginXpGain(SkillType.MINING, xp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle double drops when using Silk Touch.
|
||||
*
|
||||
* @param block The block to process drops for
|
||||
* @param location The location of the block
|
||||
* @param type The material type of the block
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
*/
|
||||
protected static void silkTouchDrops(Block block, Location location, Material type) {
|
||||
ItemStack item = new ItemStack(type);
|
||||
protected static void handleSilkTouchDrops(BlockState blockState) {
|
||||
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;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
switch (blockType) {
|
||||
case ENDER_STONE:
|
||||
case GOLD_ORE:
|
||||
case IRON_ORE:
|
||||
@ -66,14 +82,14 @@ public class Mining {
|
||||
case NETHERRACK:
|
||||
case OBSIDIAN:
|
||||
case SANDSTONE:
|
||||
miningDrops(block, location, type);
|
||||
break;
|
||||
handleMiningDrops(blockState);
|
||||
return;
|
||||
|
||||
case GLOWING_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 DIAMOND_ORE:
|
||||
@ -82,75 +98,39 @@ public class Mining {
|
||||
case LAPIS_ORE:
|
||||
case STONE:
|
||||
case EMERALD_ORE:
|
||||
Misc.dropItem(location, item);
|
||||
break;
|
||||
Misc.dropItem(blockState.getLocation(), new ItemStack(blockType));
|
||||
return;
|
||||
|
||||
default:
|
||||
if (ModChecks.isCustomMiningBlock(block)) {
|
||||
ItemStack dropItem = new ItemStack(block.getTypeId(), 1, block.getData());
|
||||
|
||||
Misc.dropItem(location, dropItem);
|
||||
if (ModChecks.isCustomMiningBlock(blockState)) {
|
||||
Misc.dropItem(blockState.getLocation(), blockState.getData().toItemStack());
|
||||
}
|
||||
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 location The location of the block
|
||||
* @param type The material type of the block
|
||||
* @param blockState The {@link BlockState} to check ability activation for
|
||||
*/
|
||||
protected static void miningDrops(Block block, Location location, Material type) {
|
||||
if (type != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, type)) {
|
||||
protected static void handleMiningDrops(BlockState blockState) {
|
||||
Material blockType = blockState.getType();
|
||||
|
||||
if (blockType != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, blockType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = new ItemStack(type);
|
||||
Location location = blockState.getLocation();
|
||||
ItemStack dropItem;
|
||||
|
||||
switch (type) {
|
||||
switch (blockType) {
|
||||
case COAL_ORE:
|
||||
item = new ItemStack(Material.COAL, 1, CoalType.COAL.getData());
|
||||
Misc.dropItem(location, item);
|
||||
break;
|
||||
|
||||
case DIAMOND_ORE:
|
||||
item = new ItemStack(Material.DIAMOND);
|
||||
Misc.dropItem(location, item);
|
||||
break;
|
||||
|
||||
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:
|
||||
item = new ItemStack(Material.GLOWSTONE_DUST);
|
||||
Misc.dropItems(location, item, 2);
|
||||
Misc.randomDropItems(location, item, 2);
|
||||
break;
|
||||
|
||||
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:
|
||||
item = new ItemStack(Material.COBBLESTONE);
|
||||
Misc.dropItem(location, item);
|
||||
break;
|
||||
|
||||
case ENDER_STONE:
|
||||
case GOLD_ORE:
|
||||
case IRON_ORE:
|
||||
@ -158,26 +138,36 @@ public class Mining {
|
||||
case NETHERRACK:
|
||||
case OBSIDIAN:
|
||||
case SANDSTONE:
|
||||
Misc.dropItem(location, item);
|
||||
break;
|
||||
for (ItemStack drop : blockState.getBlock().getDrops()) {
|
||||
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:
|
||||
if (ModChecks.isCustomMiningBlock(block)) {
|
||||
CustomBlock customBlock = ModChecks.getCustomBlock(block);
|
||||
if (ModChecks.isCustomMiningBlock(blockState)) {
|
||||
CustomBlock customBlock = ModChecks.getCustomBlock(blockState);
|
||||
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
||||
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
||||
|
||||
item = ModChecks.getCustomBlock(block).getItemDrop();
|
||||
dropItem = customBlock.getItemDrop();
|
||||
|
||||
if (minimumDropAmount != maximumDropAmount) {
|
||||
Misc.dropItems(location, item, minimumDropAmount);
|
||||
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount);
|
||||
Misc.dropItems(location, dropItem, minimumDropAmount);
|
||||
Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
|
||||
}
|
||||
else {
|
||||
Misc.dropItems(location, item, minimumDropAmount);
|
||||
Misc.dropItems(location, dropItem, minimumDropAmount);
|
||||
}
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.gmail.nossr50.skills.mining;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
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.SkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
|
||||
public class MiningManager extends SkillManager{
|
||||
public MiningManager (McMMOPlayer mcMMOPlayer) {
|
||||
@ -102,24 +100,4 @@ public class MiningManager extends SkillManager{
|
||||
eventHandler.calculateRadiusIncrease();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
@ -1,6 +1,18 @@
|
||||
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.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 static int burnModifierMaxLevel = AdvancedConfig.getInstance().getBurnModifierMaxLevel();
|
||||
@ -23,4 +35,49 @@ public class Smelting {
|
||||
public static int vanillaXPBoostRank3Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank3Multiplier();
|
||||
public static int vanillaXPBoostRank4Multiplier = AdvancedConfig.getInstance().getSmeltingVanillaXPBoostRank4Multiplier();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.gmail.nossr50.skills.smelting;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.inventory.FurnaceBurnEvent;
|
||||
import org.bukkit.event.inventory.FurnaceExtractEvent;
|
||||
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) {
|
||||
if (skillLevel < Smelting.vanillaXPBoostRank1Level || !Permissions.vanillaXpBoost(mcMMOPlayer.getPlayer(), skill)) {
|
||||
return;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.gmail.nossr50.skills.unarmed;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
@ -25,20 +25,22 @@ public class Unarmed {
|
||||
|
||||
public static double berserkDamageModifier = 1.5;
|
||||
|
||||
public static void blockCracker(Player player, Block block) {
|
||||
if (SkillTools.blockBreakSimulate(block, player, false)) {
|
||||
Material type = block.getType();
|
||||
public static boolean blockCracker(Player player, BlockState blockState) {
|
||||
if (SkillTools.blockBreakSimulate(blockState.getBlock(), player, false)) {
|
||||
Material type = blockState.getType();
|
||||
|
||||
switch (type) {
|
||||
case SMOOTH_BRICK:
|
||||
if (blockCrackerSmoothBrick && block.getData() == 0x0) {
|
||||
block.setData((byte) 0x2);
|
||||
if (blockCrackerSmoothBrick && blockState.getRawData() == (byte) 0x0) {
|
||||
blockState.setRawData((byte) 0x2);
|
||||
}
|
||||
return;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.gmail.nossr50.skills.utilities;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
@ -181,28 +181,28 @@ public enum AbilityType {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public boolean blockCheck(Block block) {
|
||||
public boolean blockCheck(BlockState blockState) {
|
||||
switch (this) {
|
||||
case BERSERK:
|
||||
return (BlockChecks.canBeGigaDrillBroken(block) || block.getType() == Material.SNOW);
|
||||
return (BlockChecks.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW);
|
||||
|
||||
case GIGA_DRILL_BREAKER:
|
||||
return BlockChecks.canBeGigaDrillBroken(block);
|
||||
return BlockChecks.affectedByGigaDrillBreaker(blockState);
|
||||
|
||||
case GREEN_TERRA:
|
||||
return BlockChecks.canMakeMossy(block);
|
||||
return BlockChecks.canMakeMossy(blockState);
|
||||
|
||||
case LEAF_BLOWER:
|
||||
return block.getType() == Material.LEAVES;
|
||||
return BlockChecks.isLeaves(blockState);
|
||||
|
||||
case SUPER_BREAKER:
|
||||
return BlockChecks.canBeSuperBroken(block);
|
||||
return BlockChecks.affectedBySuperBreaker(blockState);
|
||||
|
||||
case TREE_FELLER:
|
||||
return block.getType() == Material.LOG;
|
||||
return BlockChecks.isLog(blockState);
|
||||
|
||||
default:
|
||||
return false;
|
||||
|
@ -426,10 +426,8 @@ public class SkillTools {
|
||||
|
||||
switch (ability) {
|
||||
case BERSERK:
|
||||
case GIGA_DRILL_BREAKER:
|
||||
case SUPER_BREAKER:
|
||||
case LEAF_BLOWER:
|
||||
if (!ability.blockCheck(block)) {
|
||||
if (!ability.blockCheck(block.getState())) {
|
||||
activate = false;
|
||||
break;
|
||||
}
|
||||
@ -440,8 +438,10 @@ public class SkillTools {
|
||||
}
|
||||
break;
|
||||
|
||||
case GIGA_DRILL_BREAKER:
|
||||
case SUPER_BREAKER:
|
||||
case GREEN_TERRA:
|
||||
if (!ability.blockCheck(block)) {
|
||||
if (!ability.blockCheck(block.getState())) {
|
||||
activate = false;
|
||||
break;
|
||||
}
|
||||
@ -583,15 +583,13 @@ public class SkillTools {
|
||||
* @return true if the event wasn't cancelled, false otherwise
|
||||
*/
|
||||
public static boolean blockBreakSimulate(Block block, Player player, Boolean shouldArmSwing) {
|
||||
PluginManager pluginManger = mcMMO.p.getServer().getPluginManager();
|
||||
|
||||
//Support for NoCheat
|
||||
if (shouldArmSwing) {
|
||||
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
|
||||
pluginManger.callEvent(new FakePlayerAnimationEvent(player));
|
||||
}
|
||||
|
||||
PluginManager pluginManger = mcMMO.p.getServer().getPluginManager();
|
||||
|
||||
FakeBlockDamageEvent damageEvent = new FakeBlockDamageEvent(player, block, player.getItemInHand(), true);
|
||||
pluginManger.callEvent(damageEvent);
|
||||
|
||||
@ -604,4 +602,20 @@ public class SkillTools {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,14 @@ import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
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.material.Tree;
|
||||
|
||||
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.mods.ModChecks;
|
||||
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.util.BlockChecks;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public final class TreeFeller {
|
||||
private static boolean treeFellerReachedThreshold = false;
|
||||
@ -32,26 +34,24 @@ public final class TreeFeller {
|
||||
* Begins 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) {
|
||||
List<Block> treeFellerBlocks = new ArrayList<Block>();
|
||||
protected static void process(BlockState blockState, Player player) {
|
||||
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) {
|
||||
treeFellerReachedThreshold = false;
|
||||
|
||||
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
|
||||
player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
// If the tool can't sustain the durability loss
|
||||
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();
|
||||
|
||||
@ -62,28 +62,28 @@ public final class TreeFeller {
|
||||
return;
|
||||
}
|
||||
|
||||
dropBlocks(treeFellerBlocks, mcMMOPlayer);
|
||||
dropBlocks(treeFellerBlocks, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes Tree Feller
|
||||
*
|
||||
* @param block Block being checked
|
||||
* @param blockState Block being checked
|
||||
* @param treeFellerBlocks List of blocks to be removed
|
||||
*/
|
||||
private static void processRecursively(Block block, List<Block> treeFellerBlocks) {
|
||||
if (!BlockChecks.isLog(block)) {
|
||||
private static void processRecursively(BlockState blockState, List<BlockState> treeFellerBlocks) {
|
||||
if (!BlockChecks.isLog(blockState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Block> futureCenterBlocks = new ArrayList<Block>();
|
||||
World world = block.getWorld();
|
||||
List<BlockState> futureCenterBlocks = new ArrayList<BlockState>();
|
||||
World world = blockState.getWorld();
|
||||
|
||||
// Handle the blocks around 'block'
|
||||
for (int y = 0; y <= 1; y++) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
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);
|
||||
|
||||
@ -95,12 +95,12 @@ public final class TreeFeller {
|
||||
}
|
||||
|
||||
// Recursive call for each log found
|
||||
for (Block futurCenterBlock : futureCenterBlocks) {
|
||||
for (BlockState futureCenterBlock : futureCenterBlocks) {
|
||||
if (treeFellerReachedThreshold) {
|
||||
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
|
||||
* 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 treeFellerBlocks List of blocks to be removed
|
||||
*/
|
||||
private static void handleBlock(Block block, List<Block> futureCenterBlocks, List<Block> treeFellerBlocks) {
|
||||
if (!BlockChecks.treeFellerCompatible(block) || mcMMO.placeStore.isTrue(block) || treeFellerBlocks.contains(block)) {
|
||||
private static void handleBlock(BlockState blockState, List<BlockState> futureCenterBlocks, List<BlockState> treeFellerBlocks) {
|
||||
if (!BlockChecks.affectedByTreeFeller(blockState) || mcMMO.placeStore.isTrue(blockState) || treeFellerBlocks.contains(blockState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
treeFellerBlocks.add(block);
|
||||
treeFellerBlocks.add(blockState);
|
||||
|
||||
if (treeFellerBlocks.size() > Woodcutting.CONFIG.getTreeFellerThreshold()) {
|
||||
if (treeFellerBlocks.size() > Config.getInstance().getTreeFellerThreshold()) {
|
||||
treeFellerReachedThreshold = true;
|
||||
return;
|
||||
}
|
||||
|
||||
futureCenterBlocks.add(block);
|
||||
futureCenterBlocks.add(blockState);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,15 +134,15 @@ public final class TreeFeller {
|
||||
* @param inHand tool being used
|
||||
* @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();
|
||||
|
||||
if (inHandMaterial != Material.AIR) {
|
||||
short durabilityLoss = 0;
|
||||
int unbreakingLevel = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
|
||||
|
||||
for (Block block : treeFellerBlocks) {
|
||||
if (BlockChecks.isLog(block) && Misc.getRandom().nextInt(unbreakingLevel + 1) == 0) {
|
||||
for (BlockState blockState : treeFellerBlocks) {
|
||||
if (BlockChecks.isLog(blockState) && Misc.getRandom().nextInt(unbreakingLevel + 1) == 0) {
|
||||
durabilityLoss += SkillTools.toolDurabilityLoss;
|
||||
}
|
||||
}
|
||||
@ -165,66 +165,41 @@ public final class TreeFeller {
|
||||
* Handles the dropping of blocks
|
||||
*
|
||||
* @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;
|
||||
|
||||
for (Block block : treeFellerBlocks) {
|
||||
if (!SkillTools.blockBreakSimulate(block, mcMMOPlayer.getPlayer(), true)) {
|
||||
for (BlockState blockState : treeFellerBlocks) {
|
||||
if (!SkillTools.blockBreakSimulate(blockState.getBlock(), player, true)) {
|
||||
break; // TODO: Shouldn't we use continue instead?
|
||||
}
|
||||
|
||||
Material material = block.getType();
|
||||
Material material = blockState.getType();
|
||||
|
||||
switch (material) {
|
||||
case HUGE_MUSHROOM_1:
|
||||
case HUGE_MUSHROOM_2:
|
||||
try {
|
||||
xp += Woodcutting.getExperienceFromLog(block, ExperienceGainMethod.TREE_FELLER);
|
||||
}
|
||||
catch (IllegalArgumentException exception) {
|
||||
break;
|
||||
}
|
||||
xp += Woodcutting.getExperienceFromLog(blockState, ExperienceGainMethod.TREE_FELLER);
|
||||
|
||||
// Stems have a block data value of 15 and should not drop mushrooms
|
||||
// 0-2 mushrooms drop when you break a block
|
||||
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);
|
||||
for (ItemStack drop : blockState.getBlock().getDrops()) {
|
||||
Misc.dropItem(blockState.getLocation(), drop);
|
||||
}
|
||||
|
||||
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:
|
||||
if (ModChecks.isCustomLogBlock(block)) {
|
||||
Woodcutting.checkForDoubleDrop(mcMMOPlayer, block);
|
||||
break;
|
||||
}
|
||||
|
||||
CustomBlock customBlock = ModChecks.getCustomBlock(block);
|
||||
if (ModChecks.isCustomLogBlock(blockState)) {
|
||||
Woodcutting.checkForDoubleDrop(player, blockState);
|
||||
|
||||
CustomBlock customBlock = ModChecks.getCustomBlock(blockState);
|
||||
xp = customBlock.getXpGain();
|
||||
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
||||
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
||||
Location location = block.getLocation();
|
||||
Location location = blockState.getLocation();
|
||||
ItemStack item = customBlock.getItemDrop();;
|
||||
|
||||
Misc.dropItems(location, item, minimumDropAmount);
|
||||
@ -233,19 +208,31 @@ public final class TreeFeller {
|
||||
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount);
|
||||
}
|
||||
}
|
||||
else if (ModChecks.isCustomLeafBlock(block)) {
|
||||
CustomBlock customBlock = ModChecks.getCustomBlock(block);
|
||||
|
||||
Misc.randomDropItem(block.getLocation(), customBlock.getItemDrop(), 10);
|
||||
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;
|
||||
}
|
||||
|
||||
block.setData((byte) 0);
|
||||
block.setType(Material.AIR);
|
||||
blockState.setRawData((byte) 0x0);
|
||||
blockState.setType(Material.AIR);
|
||||
blockState.update();
|
||||
}
|
||||
|
||||
mcMMOPlayer.beginXpGain(SkillType.WOODCUTTING, xp);
|
||||
Users.getPlayer(player).beginXpGain(SkillType.WOODCUTTING, xp);
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,27 @@
|
||||
package com.gmail.nossr50.skills.woodcutting;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Tree;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
||||
import com.gmail.nossr50.mods.ModChecks;
|
||||
import com.gmail.nossr50.mods.datatypes.CustomBlock;
|
||||
import com.gmail.nossr50.skills.utilities.PerksUtils;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public final class Woodcutting {
|
||||
static final AdvancedConfig ADVANCED_CONFIG = AdvancedConfig.getInstance();
|
||||
static final Config CONFIG = Config.getInstance();
|
||||
public static double doubleDropsMaxChance = AdvancedConfig.getInstance().getWoodcuttingDoubleDropChance();
|
||||
public static int doubleDropsMaxLevel = AdvancedConfig.getInstance().getWoodcuttingDoubleDropMaxLevel();
|
||||
|
||||
protected enum ExperienceGainMethod {
|
||||
DEFAULT,
|
||||
@ -38,8 +36,8 @@ public final class Woodcutting {
|
||||
* @param mcMMOPlayer Player using the ability
|
||||
* @param block Block being broken
|
||||
*/
|
||||
public static void beginTreeFeller(McMMOPlayer mcMMOPlayer, Block block) {
|
||||
TreeFeller.process(mcMMOPlayer, block);
|
||||
public static void beginTreeFeller(BlockState blockState, Player player) {
|
||||
TreeFeller.process(blockState, player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,10 +46,9 @@ public final class Woodcutting {
|
||||
* @param player Player using the ability
|
||||
* @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));
|
||||
|
||||
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
|
||||
player.playSound(blockState.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 block Block being broken
|
||||
*/
|
||||
public static void beginWoodcutting(McMMOPlayer mcMMOPlayer, Block block) {
|
||||
int xp = 0;
|
||||
|
||||
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();
|
||||
public static void beginWoodcutting(Player player, BlockState blockState) {
|
||||
int xp = getExperienceFromLog(blockState, ExperienceGainMethod.DEFAULT);
|
||||
|
||||
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
|
||||
*
|
||||
* @param log Log being broken
|
||||
* @param blockState Log being broken
|
||||
* @param experienceGainMethod How the log is being broken
|
||||
* @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
|
||||
switch (log.getType()) {
|
||||
switch (blockState.getType()) {
|
||||
case HUGE_MUSHROOM_1:
|
||||
return Config.getInstance().getWoodcuttingXPHugeBrownMushroom();
|
||||
|
||||
case HUGE_MUSHROOM_2:
|
||||
return Config.getInstance().getWoodcuttingXPHugeRedMushroom();
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
TreeSpecies logType = TreeSpecies.getByData(extractLogItemData(log.getData()));
|
||||
|
||||
// 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();
|
||||
if (ModChecks.isCustomLogBlock(blockState)) {
|
||||
return ModChecks.getCustomBlock(blockState).getXpGain();
|
||||
}
|
||||
|
||||
switch (logType) {
|
||||
switch (((Tree) blockState.getData()).getSpecies()) {
|
||||
case GENERIC:
|
||||
return Config.getInstance().getWoodcuttingXPOak();
|
||||
|
||||
case REDWOOD:
|
||||
return Config.getInstance().getWoodcuttingXPSpruce();
|
||||
|
||||
case BIRCH:
|
||||
return Config.getInstance().getWoodcuttingXPBirch();
|
||||
|
||||
case JUNGLE:
|
||||
int xp = Config.getInstance().getWoodcuttingXPJungle();
|
||||
|
||||
switch (experienceGainMethod) {
|
||||
case TREE_FELLER:
|
||||
return (int) (xp * 0.5);
|
||||
default:
|
||||
return xp;
|
||||
if (experienceGainMethod == ExperienceGainMethod.TREE_FELLER) {
|
||||
xp *= 0.5;
|
||||
}
|
||||
|
||||
return xp;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,28 +119,18 @@ public final class Woodcutting {
|
||||
* Checks for double drops
|
||||
*
|
||||
* @param mcMMOPlayer Player breaking the block
|
||||
* @param block Block being broken
|
||||
* @param blockState Block being broken
|
||||
*/
|
||||
protected static void checkForDoubleDrop(McMMOPlayer mcMMOPlayer, Block block) {
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
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)) {
|
||||
protected static void checkForDoubleDrop(Player player, BlockState blockState) {
|
||||
if (!SkillTools.activationSuccessful(player, SkillType.WOODCUTTING, doubleDropsMaxChance, doubleDropsMaxLevel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(block)) {
|
||||
CustomBlock customBlock = ModChecks.getCustomBlock(block);
|
||||
if (ModChecks.isCustomLogBlock(blockState)) {
|
||||
CustomBlock customBlock = ModChecks.getCustomBlock(blockState);
|
||||
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
||||
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
||||
Location location = block.getLocation();
|
||||
Location location = blockState.getLocation();
|
||||
ItemStack item = customBlock.getItemDrop();
|
||||
|
||||
Misc.dropItems(location, item, minimumDropAmount);
|
||||
@ -167,44 +140,37 @@ public final class Woodcutting {
|
||||
}
|
||||
}
|
||||
else {
|
||||
byte itemData = extractLogItemData(block.getData());
|
||||
Location location = block.getLocation();
|
||||
ItemStack item = new ItemStack(Material.LOG, 1, itemData);
|
||||
Location location = blockState.getLocation();
|
||||
ItemStack item = blockState.getData().toItemStack();
|
||||
|
||||
switch (TreeSpecies.getByData(itemData)) {
|
||||
switch (((Tree) blockState.getData()).getSpecies()) {
|
||||
case GENERIC:
|
||||
if (Config.getInstance().getOakDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
return;
|
||||
|
||||
case REDWOOD:
|
||||
if (Config.getInstance().getSpruceDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
return;
|
||||
|
||||
case BIRCH:
|
||||
if (Config.getInstance().getBirchDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
return;
|
||||
|
||||
case JUNGLE:
|
||||
if (Config.getInstance().getJungleDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
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);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,7 @@ public class WoodcuttingCommand extends SkillCommand {
|
||||
treeFellerLengthEndurance = treeFellerStrings[1];
|
||||
|
||||
//DOUBLE DROPS
|
||||
AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
||||
String[] doubleDropStrings = calculateAbilityDisplayValues(advancedConfig.getWoodcuttingDoubleDropMaxLevel(), advancedConfig.getWoodcuttingDoubleDropChance());
|
||||
String[] doubleDropStrings = calculateAbilityDisplayValues(Woodcutting.doubleDropsMaxLevel, Woodcutting.doubleDropsMaxChance);
|
||||
doubleDropChance = doubleDropStrings[0];
|
||||
doubleDropChanceLucky = doubleDropStrings[1];
|
||||
}
|
||||
|
@ -1,30 +1,24 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import org.bukkit.CropState;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.material.CocoaPlant;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.mods.ModChecks;
|
||||
import com.gmail.nossr50.mods.config.CustomBlocksConfig;
|
||||
|
||||
public final class BlockChecks {
|
||||
private static Config configInstance = Config.getInstance();
|
||||
|
||||
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
|
||||
* @return true if the block type awards XP, false otherwise
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block awards XP, false otherwise
|
||||
*/
|
||||
public static boolean shouldBeWatched(Block block) {
|
||||
switch (block.getType()) {
|
||||
public static boolean shouldBeWatched(BlockState blockState) {
|
||||
switch (blockState.getType()) {
|
||||
case BROWN_MUSHROOM:
|
||||
case CACTUS:
|
||||
case CLAY:
|
||||
@ -64,30 +58,18 @@ public final class BlockChecks {
|
||||
return true;
|
||||
|
||||
default:
|
||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
||||
|
||||
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customItems.contains(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ModChecks.getCustomBlock(blockState) != null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static boolean canActivateAbilities(Block block) {
|
||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
||||
|
||||
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customAbilityBlocks.contains(item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (block.getType()) {
|
||||
public static boolean canActivateAbilities(BlockState blockState) {
|
||||
switch (blockState.getType()) {
|
||||
case BED_BLOCK:
|
||||
case BREWING_STAND:
|
||||
case BOOKSHELF:
|
||||
@ -114,7 +96,13 @@ public final class BlockChecks {
|
||||
return false;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
* @return true if the Block is an ore, false otherwise
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block is an ore, false otherwise
|
||||
*/
|
||||
public static boolean isOre(Block block) {
|
||||
switch (block.getType()) {
|
||||
public static boolean isOre(BlockState blockState) {
|
||||
switch (blockState.getType()) {
|
||||
case COAL_ORE:
|
||||
case DIAMOND_ORE:
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
@ -141,32 +129,25 @@ public final class BlockChecks {
|
||||
return true;
|
||||
|
||||
default:
|
||||
if (configInstance.getBlockModsEnabled() && ModChecks.isCustomOreBlock(block)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ModChecks.isCustomOreBlock(blockState);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static boolean canMakeMossy(Block block) {
|
||||
switch (block.getType()) {
|
||||
public static boolean canMakeMossy(BlockState blockState) {
|
||||
switch (blockState.getType()) {
|
||||
case COBBLESTONE:
|
||||
case DIRT:
|
||||
return true;
|
||||
|
||||
case SMOOTH_BRICK:
|
||||
case COBBLE_WALL:
|
||||
if (block.getData() == (byte)0x0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return blockState.getRawData() == (byte) 0x0;
|
||||
|
||||
default:
|
||||
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
|
||||
* @return true if the block is affected, false otherwise
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block should affected by Green Terra, false otherwise
|
||||
*/
|
||||
public static boolean canBeGreenTerra(Block block) {
|
||||
switch (block.getType()) {
|
||||
public static boolean affectedByGreenTerra(BlockState blockState) {
|
||||
switch (blockState.getType()) {
|
||||
case BROWN_MUSHROOM:
|
||||
case CACTUS:
|
||||
case MELON_BLOCK:
|
||||
@ -196,44 +177,27 @@ public final class BlockChecks {
|
||||
case CARROT:
|
||||
case CROPS:
|
||||
case POTATO:
|
||||
if (block.getData() == CropState.RIPE.getData()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return blockState.getRawData() == CropState.RIPE.getData();
|
||||
|
||||
case NETHER_WARTS:
|
||||
if (block.getData() == (byte) 0x3) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return blockState.getRawData() == (byte) 0x3;
|
||||
|
||||
case COCOA:
|
||||
CocoaPlant plant = (CocoaPlant) block.getState().getData();
|
||||
|
||||
if (plant.getSize() == CocoaPlantSize.LARGE) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ((CocoaPlant) blockState.getData()).getSize() == CocoaPlantSize.LARGE;
|
||||
|
||||
default:
|
||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
||||
|
||||
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ModChecks.isCustomHerbalismBlock(blockState);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return true if the block would be broken by Super Breaker, false otherwise
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block should affected by Super Breaker, false otherwise
|
||||
*/
|
||||
public static Boolean canBeSuperBroken(Block block) {
|
||||
switch (block.getType()) {
|
||||
public static Boolean affectedBySuperBreaker(BlockState blockState) {
|
||||
switch (blockState.getType()) {
|
||||
case COAL_ORE:
|
||||
case DIAMOND_ORE:
|
||||
case ENDER_STONE:
|
||||
@ -252,24 +216,18 @@ public final class BlockChecks {
|
||||
return true;
|
||||
|
||||
default:
|
||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
||||
|
||||
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ModChecks.isCustomMiningBlock(blockState);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return true if the block can be broken by Giga Drill Breaker, false otherwise
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block should affected by Giga Drill Breaker, false otherwise
|
||||
*/
|
||||
public static boolean canBeGigaDrillBroken(Block block) {
|
||||
switch (block.getType()) {
|
||||
public static boolean affectedByGigaDrillBreaker(BlockState blockState) {
|
||||
switch (blockState.getType()) {
|
||||
case CLAY:
|
||||
case DIRT:
|
||||
case GRASS:
|
||||
@ -280,24 +238,18 @@ public final class BlockChecks {
|
||||
return true;
|
||||
|
||||
default:
|
||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
||||
|
||||
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ModChecks.isCustomExcavationBlock(blockState);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return true if the block is affected by Tree Feller, false otherwise
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block should affected by Tree Feller, false otherwise
|
||||
*/
|
||||
public static boolean treeFellerCompatible(Block block) {
|
||||
switch (block.getType()) {
|
||||
public static boolean affectedByTreeFeller(BlockState blockState) {
|
||||
switch (blockState.getType()) {
|
||||
case LOG:
|
||||
case LEAVES:
|
||||
case HUGE_MUSHROOM_1:
|
||||
@ -305,38 +257,52 @@ public final class BlockChecks {
|
||||
return true;
|
||||
|
||||
default:
|
||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
||||
|
||||
if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customWoodcuttingBlocks.contains(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ModChecks.isCustomWoodcuttingBlock(blockState);
|
||||
}
|
||||
}
|
||||
|
||||
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 HUGE_MUSHROOM_1:
|
||||
case HUGE_MUSHROOM_2:
|
||||
return true;
|
||||
|
||||
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;
|
||||
|
||||
default:
|
||||
return ModChecks.isCustomLeafBlock(blockState);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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 GOLD_ORE:
|
||||
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 GRASS:
|
||||
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:
|
||||
if (block.getData() == 0x0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return blockState.getRawData() == (byte) 0x0;
|
||||
|
||||
default:
|
||||
return false;
|
||||
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public interface ChunkManager {
|
||||
@ -60,6 +61,7 @@ public interface ChunkManager {
|
||||
public void saveChunk(int cx, int cz, World world);
|
||||
|
||||
public boolean isChunkLoaded(int cx, int cz, World world);
|
||||
|
||||
/**
|
||||
* Informs the ChunkletManager a chunk is loaded
|
||||
*
|
||||
@ -128,6 +130,14 @@ public interface ChunkManager {
|
||||
*/
|
||||
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
|
||||
*
|
||||
@ -145,6 +155,13 @@ public interface ChunkManager {
|
||||
*/
|
||||
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
|
||||
*
|
||||
@ -162,6 +179,13 @@ public interface ChunkManager {
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
@ -14,6 +14,7 @@ import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isTrue(BlockState blockState) {
|
||||
if (blockState == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isTrue(blockState.getX(), blockState.getY(), blockState.getZ(), blockState.getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setTrue(int x, int y, int z, World world) {
|
||||
if (world == null)
|
||||
@ -352,6 +362,14 @@ public class HashChunkManager implements ChunkManager {
|
||||
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
|
||||
public synchronized void setFalse(int x, int y, int z, World world) {
|
||||
if (world == null)
|
||||
@ -380,12 +398,22 @@ public class HashChunkManager implements ChunkManager {
|
||||
|
||||
@Override
|
||||
public synchronized void setFalse(Block block) {
|
||||
if (block == null)
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
public synchronized void cleanUp() {}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class NullChunkManager implements ChunkManager {
|
||||
@ -73,18 +74,29 @@ public class NullChunkManager implements ChunkManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTrue(BlockState blockState) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTrue(int x, int y, int z, World world) {}
|
||||
|
||||
@Override
|
||||
public void setTrue(Block block) {}
|
||||
|
||||
@Override
|
||||
public void setTrue(BlockState blockState) {}
|
||||
|
||||
@Override
|
||||
public void setFalse(int x, int y, int z, World world) {}
|
||||
|
||||
@Override
|
||||
public void setFalse(Block block) {}
|
||||
|
||||
@Override
|
||||
public void setFalse(BlockState blockState) {}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user