2013-01-01 22:01:51 +01:00
|
|
|
package com.gmail.nossr50.skills.mining;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-03-13 08:31:07 +01:00
|
|
|
import org.bukkit.CoalType;
|
2013-01-08 17:31:07 +01:00
|
|
|
import org.bukkit.DyeColor;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.Location;
|
2012-03-04 09:54:26 +01:00
|
|
|
import org.bukkit.Material;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-12-25 07:01:10 +01:00
|
|
|
import org.bukkit.material.MaterialData;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
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-02-01 06:38:25 +01:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2013-01-30 17:35:33 +01:00
|
|
|
import com.gmail.nossr50.mods.ModChecks;
|
|
|
|
import com.gmail.nossr50.mods.datatypes.CustomBlock;
|
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;
|
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();
|
|
|
|
private static Config config = Config.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();
|
|
|
|
public static boolean doubleDropsDisabled = config.miningDoubleDropsDisabled();
|
2013-01-07 18:51:39 +01:00
|
|
|
|
2013-01-25 18:33:48 +01:00
|
|
|
|
2013-01-08 18:52:16 +01:00
|
|
|
public static final int DIAMOND_TOOL_TIER = 4;
|
|
|
|
public static final int IRON_TOOL_TIER = 3;
|
|
|
|
public static final int STONE_TOOL_TIER = 2;
|
|
|
|
|
2013-01-07 18:51:39 +01:00
|
|
|
/**
|
|
|
|
* Award XP for Mining blocks.
|
|
|
|
*
|
2013-02-01 06:38:25 +01:00
|
|
|
* @param mcMMOPlayer The player to award XP to
|
2013-01-07 18:51:39 +01:00
|
|
|
* @param block The block to award XP for
|
|
|
|
*/
|
2013-02-01 06:38:25 +01:00
|
|
|
protected static void miningXP(McMMOPlayer mcMMOPlayer, Block block, Material type) {
|
2013-01-07 18:51:39 +01:00
|
|
|
int xp = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case COAL_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPCoalOre();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIAMOND_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPDiamondOre();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ENDER_STONE:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPEndStone();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GLOWING_REDSTONE_ORE:
|
|
|
|
case REDSTONE_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPRedstoneOre();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GLOWSTONE:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPGlowstone();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GOLD_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPGoldOre();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRON_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPIronOre();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAPIS_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPLapisOre();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MOSSY_COBBLESTONE:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPMossyStone();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NETHERRACK:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPNetherrack();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OBSIDIAN:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPObsidian();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SANDSTONE:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPSandstone();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STONE:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPStone();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EMERALD_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
xp += config.getMiningXPEmeraldOre();
|
2013-01-07 18:51:39 +01:00
|
|
|
break;
|
2013-01-23 22:34:01 +01:00
|
|
|
|
2013-01-07 18:51:39 +01:00
|
|
|
default:
|
|
|
|
if (ModChecks.isCustomMiningBlock(block)) {
|
|
|
|
xp += ModChecks.getCustomBlock(block).getXpGain();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-03 12:45:19 +01:00
|
|
|
mcMMOPlayer.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.
|
|
|
|
*
|
|
|
|
* @param block The block to process drops for
|
2013-01-08 15:35:41 +01:00
|
|
|
* @param location The location of the block
|
|
|
|
* @param type The material type of the block
|
2012-05-18 17:15:30 +02:00
|
|
|
*/
|
2013-01-08 15:35:41 +01:00
|
|
|
protected static void silkTouchDrops(Block block, Location location, Material type) {
|
2012-05-18 17:15:30 +02:00
|
|
|
ItemStack item = new ItemStack(type);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ENDER_STONE:
|
|
|
|
case GOLD_ORE:
|
|
|
|
case IRON_ORE:
|
|
|
|
case MOSSY_COBBLESTONE:
|
|
|
|
case NETHERRACK:
|
|
|
|
case OBSIDIAN:
|
|
|
|
case SANDSTONE:
|
2013-01-08 15:35:41 +01:00
|
|
|
miningDrops(block, location, type);
|
2012-05-18 17:15:30 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COAL_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getCoalDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-18 17:15:30 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIAMOND_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getDiamondDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-18 17:15:30 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GLOWING_REDSTONE_ORE:
|
|
|
|
case REDSTONE_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getRedstoneDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-18 17:15:30 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GLOWSTONE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getGlowstoneDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-18 17:15:30 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAPIS_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getLapisDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-18 17:15:30 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STONE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getStoneDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-18 17:15:30 +02:00
|
|
|
}
|
|
|
|
break;
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2012-09-05 10:19:34 +02:00
|
|
|
case EMERALD_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getEmeraldDoubleDropsEnabled()) {
|
2012-09-05 10:19:34 +02:00
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
|
|
|
break;
|
2012-05-18 17:15:30 +02:00
|
|
|
|
|
|
|
default:
|
2012-05-22 05:41:11 +02:00
|
|
|
if (ModChecks.isCustomMiningBlock(block)) {
|
2012-12-29 21:59:18 +01:00
|
|
|
ItemStack dropItem = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
|
|
|
Misc.dropItem(location, dropItem);
|
2012-05-18 17:15:30 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 08:31:07 +01:00
|
|
|
/**
|
|
|
|
* Drop items from Mining & Blast Mining skills.
|
|
|
|
*
|
|
|
|
* @param block The block to process drops for
|
2013-01-08 15:35:41 +01:00
|
|
|
* @param location The location of the block
|
|
|
|
* @param type The material type of the block
|
2012-03-13 08:31:07 +01:00
|
|
|
*/
|
2013-01-08 15:35:41 +01:00
|
|
|
protected static void miningDrops(Block block, Location location, Material type) {
|
2012-03-16 18:45:30 +01:00
|
|
|
ItemStack item = new ItemStack(type);
|
2012-03-13 08:31:07 +01:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case COAL_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getCoalDoubleDropsEnabled()) {
|
2012-12-29 21:59:18 +01:00
|
|
|
item = (new MaterialData(Material.COAL, CoalType.COAL.getData())).toItemStack(1);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIAMOND_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getDiamondDoubleDropsEnabled()) {
|
2012-05-01 07:14:32 +02:00
|
|
|
item = new ItemStack(Material.DIAMOND);
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENDER_STONE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getEndStoneDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GLOWING_REDSTONE_ORE:
|
|
|
|
case REDSTONE_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getRedstoneDoubleDropsEnabled()) {
|
2012-05-01 07:14:32 +02:00
|
|
|
item = new ItemStack(Material.REDSTONE);
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItems(location, item, 4);
|
|
|
|
Misc.randomDropItem(location, item, 50);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GLOWSTONE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getGlowstoneDoubleDropsEnabled()) {
|
2012-05-01 07:14:32 +02:00
|
|
|
item = new ItemStack(Material.GLOWSTONE_DUST);
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItems(location, item, 2);
|
2013-02-17 07:26:47 +01:00
|
|
|
Misc.randomDropItems(location, item, 2);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GOLD_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getGoldDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRON_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getIronDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAPIS_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getLapisDoubleDropsEnabled()) {
|
2013-02-15 18:16:31 +01:00
|
|
|
item = new ItemStack(Material.INK_SACK, 1, DyeColor.BLUE.getDyeData());
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItems(location, item, 4);
|
2013-02-17 07:26:47 +01:00
|
|
|
Misc.randomDropItems(location, item, 4);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOSSY_COBBLESTONE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getMossyCobblestoneDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NETHERRACK:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getNetherrackDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OBSIDIAN:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getObsidianDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SANDSTONE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getSandstoneDoubleDropsEnabled()) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STONE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getStoneDoubleDropsEnabled()) {
|
2012-05-01 07:14:32 +02:00
|
|
|
item = new ItemStack(Material.COBBLESTONE);
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItem(location, item);
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2012-09-05 10:19:34 +02:00
|
|
|
case EMERALD_ORE:
|
2013-01-07 23:40:33 +01:00
|
|
|
if (config.getEmeraldDoubleDropsEnabled()) {
|
2012-09-05 10:19:34 +02:00
|
|
|
item = new ItemStack(Material.EMERALD);
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
}
|
|
|
|
break;
|
2012-03-13 08:31:07 +01:00
|
|
|
|
|
|
|
default:
|
2012-12-29 06:11:22 +01:00
|
|
|
if (ModChecks.isCustomMiningBlock(block)) {
|
2012-06-25 15:39:02 +02:00
|
|
|
CustomBlock customBlock = ModChecks.getCustomBlock(block);
|
|
|
|
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
|
|
|
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
|
|
|
|
2012-05-17 06:24:33 +02:00
|
|
|
item = ModChecks.getCustomBlock(block).getItemDrop();
|
2012-06-25 15:39:02 +02:00
|
|
|
|
|
|
|
if (minimumDropAmount != maximumDropAmount) {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItems(location, item, minimumDropAmount);
|
2013-02-17 07:26:47 +01:00
|
|
|
Misc.randomDropItems(location, item, maximumDropAmount - minimumDropAmount);
|
2012-06-25 15:39:02 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-07-04 21:35:14 +02:00
|
|
|
Misc.dropItems(location, item, minimumDropAmount);
|
2012-06-25 15:39:02 +02:00
|
|
|
}
|
2012-05-17 06:24:33 +02:00
|
|
|
}
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
}
|