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

174 lines
6.1 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
import org.bukkit.Location;
import org.bukkit.Material;
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;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.util.Misc;
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 {
private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
2013-01-07 18:51:39 +01:00
public static int doubleDropsMaxLevel = advancedConfig.getMiningDoubleDropMaxLevel();
public static double doubleDropsMaxChance = advancedConfig.getMiningDoubleDropChance();
/**
* 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
/**
* Award XP gain for Mining.
2013-01-07 18:51:39 +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
*/
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
if (blockType == Material.GLOWING_REDSTONE_ORE) {
xp = Config.getInstance().getXp(SkillType.MINING, Material.REDSTONE_ORE);
}
else if (xp == 0 && ModChecks.isCustomMiningBlock(blockState)) {
xp = ModChecks.getCustomBlock(blockState).getXpGain();
2013-01-07 18:51:39 +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.
*
* @param blockState The {@link BlockState} to check ability activation for
2012-05-18 17:15:30 +02:00
*/
protected static void handleSilkTouchDrops(BlockState blockState) {
Material blockType = blockState.getType();
2012-05-18 17:15:30 +02:00
if (blockType != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, blockType)) {
return;
}
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:
handleMiningDrops(blockState);
return;
2012-05-18 17:15:30 +02:00
case GLOWING_REDSTONE_ORE:
if (Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, Material.REDSTONE_ORE)) {
Misc.dropItem(blockState.getLocation(), new ItemStack(Material.REDSTONE_ORE));
2012-05-18 17:15:30 +02:00
}
return;
2012-05-18 17:15:30 +02: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:
case EMERALD_ORE:
Misc.dropItem(blockState.getLocation(), new ItemStack(blockType));
return;
2012-05-18 17:15:30 +02:00
default:
if (ModChecks.isCustomMiningBlock(blockState)) {
Misc.dropItem(blockState.getLocation(), blockState.getData().toItemStack());
2012-05-18 17:15:30 +02:00
}
return;
2012-05-18 17:15:30 +02:00
}
}
2012-03-13 08:31:07 +01:00
/**
* Handle double drops from Mining & Blast Mining.
2012-03-13 08:31:07 +01:00
*
* @param blockState The {@link BlockState} to check ability activation for
2012-03-13 08:31:07 +01:00
*/
protected static void handleMiningDrops(BlockState blockState) {
Material blockType = blockState.getType();
if (blockType != Material.GLOWING_REDSTONE_ORE && !Config.getInstance().getDoubleDropsEnabled(SkillType.MINING, blockType)) {
return;
}
Location location = blockState.getLocation();
ItemStack dropItem;
2012-03-13 08:31:07 +01:00
switch (blockType) {
2012-03-13 08:31:07 +01:00
case COAL_ORE:
case DIAMOND_ORE:
case EMERALD_ORE:
2012-03-13 08:31:07 +01:00
case GLOWSTONE:
case LAPIS_ORE:
case STONE:
case ENDER_STONE:
case GOLD_ORE:
case IRON_ORE:
case MOSSY_COBBLESTONE:
case NETHERRACK:
case OBSIDIAN:
case SANDSTONE:
for (ItemStack drop : blockState.getBlock().getDrops()) {
Misc.dropItem(location, drop);
}
return;
2012-03-13 08:31:07 +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:
if (ModChecks.isCustomMiningBlock(blockState)) {
CustomBlock customBlock = ModChecks.getCustomBlock(blockState);
int minimumDropAmount = customBlock.getMinimumDropAmount();
int maximumDropAmount = customBlock.getMaximumDropAmount();
dropItem = customBlock.getItemDrop();
if (minimumDropAmount != maximumDropAmount) {
Misc.dropItems(location, dropItem, minimumDropAmount);
Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
}
else {
Misc.dropItems(location, dropItem, minimumDropAmount);
}
}
return;
2012-03-13 08:31:07 +01:00
}
2012-01-09 20:00:13 +01:00
}
}