mcMMO/src/main/java/com/gmail/nossr50/skills/mining/Mining.java

320 lines
9.8 KiB
Java
Raw Normal View History

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;
import org.bukkit.Material;
2012-01-09 20:00:13 +01:00
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
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;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModChecks;
2012-05-01 19:58:47 +02:00
import com.gmail.nossr50.util.Skills;
2012-01-09 20:00:13 +01:00
2012-03-26 17:04:17 +02:00
public class Mining {
private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
private static Config config = Config.getInstance();
2013-01-07 18:51:39 +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-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.
*
* @param player The player to award XP to
* @param block The block to award XP for
*/
protected static void miningXP(Player player, PlayerProfile profile, Block block, Material type) {
2013-01-07 18:51:39 +01:00
int xp = 0;
switch (type) {
case COAL_ORE:
xp += config.getMiningXPCoalOre();
2013-01-07 18:51:39 +01:00
break;
case DIAMOND_ORE:
xp += config.getMiningXPDiamondOre();
2013-01-07 18:51:39 +01:00
break;
case ENDER_STONE:
xp += config.getMiningXPEndStone();
2013-01-07 18:51:39 +01:00
break;
case GLOWING_REDSTONE_ORE:
case REDSTONE_ORE:
xp += config.getMiningXPRedstoneOre();
2013-01-07 18:51:39 +01:00
break;
case GLOWSTONE:
xp += config.getMiningXPGlowstone();
2013-01-07 18:51:39 +01:00
break;
case GOLD_ORE:
xp += config.getMiningXPGoldOre();
2013-01-07 18:51:39 +01:00
break;
case IRON_ORE:
xp += config.getMiningXPIronOre();
2013-01-07 18:51:39 +01:00
break;
case LAPIS_ORE:
xp += config.getMiningXPLapisOre();
2013-01-07 18:51:39 +01:00
break;
case MOSSY_COBBLESTONE:
xp += config.getMiningXPMossyStone();
2013-01-07 18:51:39 +01:00
break;
case NETHERRACK:
xp += config.getMiningXPNetherrack();
2013-01-07 18:51:39 +01:00
break;
case OBSIDIAN:
xp += config.getMiningXPObsidian();
2013-01-07 18:51:39 +01:00
break;
case SANDSTONE:
xp += config.getMiningXPSandstone();
2013-01-07 18:51:39 +01:00
break;
case STONE:
xp += config.getMiningXPStone();
2013-01-07 18:51:39 +01:00
break;
case EMERALD_ORE:
xp += config.getMiningXPEmeraldOre();
2013-01-07 18:51:39 +01:00
break;
default:
if (ModChecks.isCustomMiningBlock(block)) {
xp += ModChecks.getCustomBlock(block).getXpGain();
}
break;
}
Skills.xpProcessing(player, profile, SkillType.MINING, xp);
}
2012-05-18 17:15:30 +02:00
/**
* 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
2012-05-18 17:15:30 +02: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:
miningDrops(block, location, type);
2012-05-18 17:15:30 +02:00
break;
case COAL_ORE:
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:
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:
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:
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:
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:
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
case EMERALD_ORE:
if (config.getEmeraldDoubleDropsEnabled()) {
Misc.dropItem(location, item);
}
break;
2012-05-18 17:15:30 +02:00
default:
if (ModChecks.isCustomMiningBlock(block)) {
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
* @param location The location of the block
* @param type The material type of the block
2012-03-13 08:31:07 +01:00
*/
protected static void miningDrops(Block block, Location location, Material type) {
ItemStack item = new ItemStack(type);
2012-03-13 08:31:07 +01:00
switch (type) {
case COAL_ORE:
if (config.getCoalDoubleDropsEnabled()) {
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-03-13 08:31:07 +01:00
break;
case DIAMOND_ORE:
if (config.getDiamondDoubleDropsEnabled()) {
item = new ItemStack(Material.DIAMOND);
2012-07-04 21:35:14 +02:00
Misc.dropItem(location, item);
}
break;
case ENDER_STONE:
if (config.getEndStoneDoubleDropsEnabled()) {
2012-07-04 21:35:14 +02:00
Misc.dropItem(location, item);
}
2012-03-13 08:31:07 +01:00
break;
case GLOWING_REDSTONE_ORE:
case REDSTONE_ORE:
if (config.getRedstoneDoubleDropsEnabled()) {
item = new ItemStack(Material.REDSTONE);
2012-07-04 21:35:14 +02:00
Misc.dropItems(location, item, 4);
Misc.randomDropItem(location, item, 50);
}
2012-03-13 08:31:07 +01:00
break;
case GLOWSTONE:
if (config.getGlowstoneDoubleDropsEnabled()) {
item = new ItemStack(Material.GLOWSTONE_DUST);
2012-07-04 21:35:14 +02:00
Misc.dropItems(location, item, 2);
Misc.randomDropItems(location, item, 50, 2);
}
break;
case GOLD_ORE:
if (config.getGoldDoubleDropsEnabled()) {
2012-07-04 21:35:14 +02:00
Misc.dropItem(location, item);
}
break;
case IRON_ORE:
if (config.getIronDoubleDropsEnabled()) {
2012-07-04 21:35:14 +02:00
Misc.dropItem(location, item);
}
2012-03-13 08:31:07 +01:00
break;
case LAPIS_ORE:
if (config.getLapisDoubleDropsEnabled()) {
try {
2013-01-14 03:23:11 +01:00
item = (new MaterialData(Material.INK_SACK, DyeColor.BLUE.getDyeData())).toItemStack(1);
}
catch(Exception e) {
item = (new MaterialData(Material.INK_SACK, (byte) 4)).toItemStack(1);
}
catch(NoSuchMethodError e) {
item = (new MaterialData(Material.INK_SACK, (byte) 4)).toItemStack(1);
}
2012-12-25 07:01:10 +01:00
2012-07-04 21:35:14 +02:00
Misc.dropItems(location, item, 4);
Misc.randomDropItems(location, item, 50, 4);
}
break;
case MOSSY_COBBLESTONE:
if (config.getMossyCobblestoneDoubleDropsEnabled()) {
2012-07-04 21:35:14 +02:00
Misc.dropItem(location, item);
}
break;
case NETHERRACK:
if (config.getNetherrackDoubleDropsEnabled()) {
2012-07-04 21:35:14 +02:00
Misc.dropItem(location, item);
}
break;
case OBSIDIAN:
if (config.getObsidianDoubleDropsEnabled()) {
2012-07-04 21:35:14 +02:00
Misc.dropItem(location, item);
}
break;
case SANDSTONE:
if (config.getSandstoneDoubleDropsEnabled()) {
2012-07-04 21:35:14 +02:00
Misc.dropItem(location, item);
}
2012-03-13 08:31:07 +01:00
break;
case STONE:
if (config.getStoneDoubleDropsEnabled()) {
item = new ItemStack(Material.COBBLESTONE);
2012-07-04 21:35:14 +02:00
Misc.dropItem(location, item);
}
2012-03-13 08:31:07 +01:00
break;
2012-12-24 22:56:25 +01:00
case EMERALD_ORE:
if (config.getEmeraldDoubleDropsEnabled()) {
item = new ItemStack(Material.EMERALD);
Misc.dropItem(location, item);
}
break;
2012-03-13 08:31:07 +01:00
default:
if (ModChecks.isCustomMiningBlock(block)) {
CustomBlock customBlock = ModChecks.getCustomBlock(block);
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
item = ModChecks.getCustomBlock(block).getItemDrop();
if (minimumDropAmount != maximumDropAmount) {
2012-07-04 21:35:14 +02:00
Misc.dropItems(location, item, minimumDropAmount);
Misc.randomDropItems(location, item, 50, maximumDropAmount - minimumDropAmount);
}
else {
2012-07-04 21:35:14 +02:00
Misc.dropItems(location, item, minimumDropAmount);
}
}
2012-03-13 08:31:07 +01:00
break;
}
2012-01-09 20:00:13 +01:00
}
}