123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- package com.gmail.nossr50.skills.mining;
- import java.util.Random;
- import org.bukkit.CoalType;
- import org.bukkit.DyeColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.material.MaterialData;
- import com.gmail.nossr50.config.AdvancedConfig;
- 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;
- import com.gmail.nossr50.util.Misc;
- import com.gmail.nossr50.util.ModChecks;
- import com.gmail.nossr50.util.Skills;
- public class Mining {
- private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
- private static Config config = Config.getInstance();
- private static Random random = new Random();
- public static final int DOUBLE_DROPS_MAX_BONUS_LEVEL = advancedConfig.getMiningDoubleDropMaxLevel();
- public static final int DOUBLE_DROPS_MAX_CHANCE = 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;
- /**
- * 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) {
- int xp = 0;
- switch (type) {
- case COAL_ORE:
- xp += config.getMiningXPCoalOre();
- break;
- case DIAMOND_ORE:
- xp += config.getMiningXPDiamondOre();
- break;
- case ENDER_STONE:
- xp += config.getMiningXPEndStone();
- break;
- case GLOWING_REDSTONE_ORE:
- case REDSTONE_ORE:
- xp += config.getMiningXPRedstoneOre();
- break;
- case GLOWSTONE:
- xp += config.getMiningXPGlowstone();
- break;
- case GOLD_ORE:
- xp += config.getMiningXPGoldOre();
- break;
- case IRON_ORE:
- xp += config.getMiningXPIronOre();
- break;
- case LAPIS_ORE:
- xp += config.getMiningXPLapisOre();
- break;
- case MOSSY_COBBLESTONE:
- xp += config.getMiningXPMossyStone();
- break;
- case NETHERRACK:
- xp += config.getMiningXPNetherrack();
- break;
- case OBSIDIAN:
- xp += config.getMiningXPObsidian();
- break;
- case SANDSTONE:
- xp += config.getMiningXPSandstone();
- break;
- case STONE:
- xp += config.getMiningXPStone();
- break;
- case EMERALD_ORE:
- xp += config.getMiningXPEmeraldOre();
- break;
- default:
- if (ModChecks.isCustomMiningBlock(block)) {
- xp += ModChecks.getCustomBlock(block).getXpGain();
- }
- break;
- }
- Skills.xpProcessing(player, profile, 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
- */
- protected static void silkTouchDrops(Block block, Location location, Material type) {
- 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);
- break;
- case COAL_ORE:
- if (config.getCoalDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case DIAMOND_ORE:
- if (config.getDiamondDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case GLOWING_REDSTONE_ORE:
- case REDSTONE_ORE:
- if (config.getRedstoneDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case GLOWSTONE:
- if (config.getGlowstoneDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case LAPIS_ORE:
- if (config.getLapisDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case STONE:
- if (config.getStoneDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case EMERALD_ORE:
- if (config.getEmeraldDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- default:
- if (ModChecks.isCustomMiningBlock(block)) {
- ItemStack dropItem = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
- Misc.dropItem(location, dropItem);
- }
- break;
- }
- }
- /**
- * 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
- */
- protected static void miningDrops(Block block, Location location, Material type) {
- ItemStack item = new ItemStack(type);
- switch (type) {
- case COAL_ORE:
- if (config.getCoalDoubleDropsEnabled()) {
- item = (new MaterialData(Material.COAL, CoalType.COAL.getData())).toItemStack(1);
- Misc.dropItem(location, item);
- }
- break;
- case DIAMOND_ORE:
- if (config.getDiamondDoubleDropsEnabled()) {
- item = new ItemStack(Material.DIAMOND);
- Misc.dropItem(location, item);
- }
- break;
- case ENDER_STONE:
- if (config.getEndStoneDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case GLOWING_REDSTONE_ORE:
- case REDSTONE_ORE:
- if (config.getRedstoneDoubleDropsEnabled()) {
- item = new ItemStack(Material.REDSTONE);
- Misc.dropItems(location, item, 4);
- Misc.randomDropItem(location, item, 50);
- }
- break;
- case GLOWSTONE:
- if (config.getGlowstoneDoubleDropsEnabled()) {
- item = new ItemStack(Material.GLOWSTONE_DUST);
- Misc.dropItems(location, item, 2);
- Misc.randomDropItems(location, item, 50, 2);
- }
- break;
- case GOLD_ORE:
- if (config.getGoldDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case IRON_ORE:
- if (config.getIronDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case LAPIS_ORE:
- if (config.getLapisDoubleDropsEnabled()) {
- try {
- item = (new MaterialData(Material.INK_SACK, DyeColor.BLUE.getDyeData())).toItemStack(1);
- }
- catch(Exception e) {
- item = (new MaterialData(Material.INK_SACK, (byte) 4)).toItemStack(1);
- }
- Misc.dropItems(location, item, 4);
- Misc.randomDropItems(location, item, 50, 4);
- }
- break;
- case MOSSY_COBBLESTONE:
- if (config.getMossyCobblestoneDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case NETHERRACK:
- if (config.getNetherrackDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case OBSIDIAN:
- if (config.getObsidianDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case SANDSTONE:
- if (config.getSandstoneDoubleDropsEnabled()) {
- Misc.dropItem(location, item);
- }
- break;
- case STONE:
- if (config.getStoneDoubleDropsEnabled()) {
- item = new ItemStack(Material.COBBLESTONE);
- Misc.dropItem(location, item);
- }
- break;
- case EMERALD_ORE:
- if (config.getEmeraldDoubleDropsEnabled()) {
- item = new ItemStack(Material.EMERALD);
- Misc.dropItem(location, item);
- }
- break;
- 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) {
- Misc.dropItems(location, item, minimumDropAmount);
- Misc.randomDropItems(location, item, 50, maximumDropAmount - minimumDropAmount);
- }
- else {
- Misc.dropItems(location, item, minimumDropAmount);
- }
- }
- break;
- }
- }
- protected static Random getRandom() {
- return random;
- }
- }
|