2013-01-01 22:01:51 +01:00
|
|
|
package com.gmail.nossr50.skills.mining;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
import org.bukkit.Location;
|
2012-03-04 09:54:26 +01:00
|
|
|
import org.bukkit.Material;
|
2013-02-22 17:23:46 +01:00
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
import org.bukkit.enchantments.Enchantment;
|
|
|
|
import org.bukkit.entity.Player;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2012-11-21 21:49:54 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2012-06-05 16:13:10 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-01-30 17:35:33 +01:00
|
|
|
import com.gmail.nossr50.mods.ModChecks;
|
|
|
|
import com.gmail.nossr50.mods.datatypes.CustomBlock;
|
2013-02-22 17:23:46 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillTools;
|
2013-01-30 17:53:51 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2013-02-22 17:23:46 +01:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
public class Mining {
|
2013-01-07 23:40:33 +01:00
|
|
|
private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
2013-01-07 18:51:39 +01:00
|
|
|
|
2013-01-22 08:20:05 +01:00
|
|
|
public static int doubleDropsMaxLevel = advancedConfig.getMiningDoubleDropMaxLevel();
|
|
|
|
public static double doubleDropsMaxChance = advancedConfig.getMiningDoubleDropChance();
|
2013-01-25 18:33:48 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-08 18:52:16 +01:00
|
|
|
|
2013-01-07 18:51:39 +01:00
|
|
|
/**
|
2013-02-22 17:23:46 +01:00
|
|
|
* Award XP gain for Mining.
|
2013-01-07 18:51:39 +01:00
|
|
|
*
|
2013-02-22 17:23:46 +01:00
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @param player The {@link Player} using this ability
|
2013-01-07 18:51:39 +01:00
|
|
|
*/
|
2013-02-22 17:23:46 +01:00
|
|
|
protected static void awardMiningXp(BlockState blockState, Player player) {
|
|
|
|
Material blockType = blockState.getType();
|
|
|
|
int xp = Config.getInstance().getXp(SkillType.MINING, blockType);
|
2013-01-07 18:51:39 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
if (blockType == Material.GLOWING_REDSTONE_ORE) {
|
2013-02-20 22:44:15 +01:00
|
|
|
xp = Config.getInstance().getXp(SkillType.MINING, Material.REDSTONE_ORE);
|
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
else if (xp == 0 && ModChecks.isCustomMiningBlock(blockState)) {
|
|
|
|
xp = ModChecks.getCustomBlock(blockState).getXpGain();
|
2013-01-07 18:51:39 +01:00
|
|
|
}
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
Users.getPlayer(player).beginXpGain(SkillType.MINING, xp);
|
2013-01-07 18:51:39 +01:00
|
|
|
}
|
|
|
|
|
2012-05-18 17:15:30 +02:00
|
|
|
/**
|
|
|
|
* Handle double drops when using Silk Touch.
|
|
|
|
*
|
2013-02-22 17:23:46 +01:00
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
2012-05-18 17:15:30 +02:00
|
|
|
*/
|
2013-02-22 17:23:46 +01:00
|
|
|
protected static void handleSilkTouchDrops(BlockState blockState) {
|
|
|
|
Material blockType = blockState.getType();
|
2012-05-18 17:15:30 +02:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
if (blockType != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, blockType)) {
|
2013-02-20 22:44:15 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
switch (blockType) {
|
2012-05-18 17:15:30 +02:00
|
|
|
case ENDER_STONE:
|
|
|
|
case GOLD_ORE:
|
|
|
|
case IRON_ORE:
|
|
|
|
case MOSSY_COBBLESTONE:
|
|
|
|
case NETHERRACK:
|
|
|
|
case OBSIDIAN:
|
|
|
|
case SANDSTONE:
|
2013-02-22 17:23:46 +01:00
|
|
|
handleMiningDrops(blockState);
|
|
|
|
return;
|
2012-05-18 17:15:30 +02:00
|
|
|
|
2013-02-20 22:44:15 +01:00
|
|
|
case GLOWING_REDSTONE_ORE:
|
|
|
|
if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) {
|
2013-02-22 17:23:46 +01:00
|
|
|
Misc.dropItem(blockState.getLocation(), new ItemStack(Material.REDSTONE_ORE));
|
2012-05-18 17:15:30 +02:00
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
return;
|
2012-05-18 17:15:30 +02:00
|
|
|
|
2013-02-20 22:44:15 +01:00
|
|
|
case COAL_ORE:
|
2012-05-18 17:15:30 +02:00
|
|
|
case DIAMOND_ORE:
|
|
|
|
case REDSTONE_ORE:
|
|
|
|
case GLOWSTONE:
|
|
|
|
case LAPIS_ORE:
|
|
|
|
case STONE:
|
2012-09-05 10:19:34 +02:00
|
|
|
case EMERALD_ORE:
|
2013-02-22 17:23:46 +01:00
|
|
|
Misc.dropItem(blockState.getLocation(), new ItemStack(blockType));
|
|
|
|
return;
|
2012-05-18 17:15:30 +02:00
|
|
|
|
|
|
|
default:
|
2013-02-22 17:23:46 +01:00
|
|
|
if (ModChecks.isCustomMiningBlock(blockState)) {
|
|
|
|
Misc.dropItem(blockState.getLocation(), blockState.getData().toItemStack());
|
2012-05-18 17:15:30 +02:00
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
return;
|
2012-05-18 17:15:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 08:31:07 +01:00
|
|
|
/**
|
2013-02-22 17:23:46 +01:00
|
|
|
* Handle double drops from Mining & Blast Mining.
|
2012-03-13 08:31:07 +01:00
|
|
|
*
|
2013-02-22 17:23:46 +01:00
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
2012-03-13 08:31:07 +01:00
|
|
|
*/
|
2013-02-22 17:23:46 +01:00
|
|
|
protected static void handleMiningDrops(BlockState blockState) {
|
|
|
|
Material blockType = blockState.getType();
|
|
|
|
|
|
|
|
if (blockType != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, blockType)) {
|
2013-02-20 22:44:15 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
Location location = blockState.getLocation();
|
|
|
|
ItemStack dropItem;
|
2012-03-13 08:31:07 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
switch (blockType) {
|
2012-03-13 08:31:07 +01:00
|
|
|
case COAL_ORE:
|
|
|
|
case DIAMOND_ORE:
|
2013-02-20 22:44:15 +01:00
|
|
|
case EMERALD_ORE:
|
2012-03-13 08:31:07 +01:00
|
|
|
case GLOWSTONE:
|
|
|
|
case LAPIS_ORE:
|
2013-02-20 22:44:15 +01:00
|
|
|
case STONE:
|
|
|
|
case ENDER_STONE:
|
|
|
|
case GOLD_ORE:
|
|
|
|
case IRON_ORE:
|
|
|
|
case MOSSY_COBBLESTONE:
|
2012-05-01 07:14:32 +02:00
|
|
|
case NETHERRACK:
|
|
|
|
case OBSIDIAN:
|
|
|
|
case SANDSTONE:
|
2013-02-22 17:23:46 +01:00
|
|
|
for (ItemStack drop : blockState.getBlock().getDrops()) {
|
|
|
|
Misc.dropItem(location, drop);
|
|
|
|
}
|
|
|
|
return;
|
2012-03-13 08:31:07 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
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;
|
2012-03-13 08:31:07 +01:00
|
|
|
default:
|
2013-02-22 17:23:46 +01:00
|
|
|
if (ModChecks.isCustomMiningBlock(blockState)) {
|
|
|
|
CustomBlock customBlock = ModChecks.getCustomBlock(blockState);
|
2012-06-25 15:39:02 +02:00
|
|
|
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
|
|
|
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
dropItem = customBlock.getItemDrop();
|
2012-06-25 15:39:02 +02:00
|
|
|
|
|
|
|
if (minimumDropAmount != maximumDropAmount) {
|
2013-02-22 17:23:46 +01:00
|
|
|
Misc.dropItems(location, dropItem, minimumDropAmount);
|
|
|
|
Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
|
2012-06-25 15:39:02 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-02-22 17:23:46 +01:00
|
|
|
Misc.dropItems(location, dropItem, minimumDropAmount);
|
2012-06-25 15:39:02 +02:00
|
|
|
}
|
2012-05-17 06:24:33 +02:00
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
return;
|
2012-03-13 08:31:07 +01:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
}
|