2012-01-09 20:00:13 +01:00
|
|
|
package com.gmail.nossr50.skills;
|
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
import java.util.Random;
|
|
|
|
|
2012-03-13 08:31:07 +01:00
|
|
|
import org.bukkit.CoalType;
|
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.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.getspout.spoutapi.sound.SoundEffect;
|
2012-02-04 14:48:37 +01:00
|
|
|
import org.bukkit.enchantments.Enchantment;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-04-21 00:09:50 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-03-21 03:33:58 +01:00
|
|
|
import com.gmail.nossr50.spout.SpoutSounds;
|
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-04-27 05:58:21 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2012-03-27 05:01:51 +02:00
|
|
|
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
public class Mining {
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
private static Random random = new Random();
|
2012-02-27 23:28:32 +01:00
|
|
|
|
2012-03-13 08:31:07 +01:00
|
|
|
/**
|
|
|
|
* Drop items from Mining & Blast Mining skills.
|
|
|
|
*
|
|
|
|
* @param block The block to process drops for
|
|
|
|
*/
|
|
|
|
public static void miningDrops(Block block) {
|
|
|
|
Location loc = block.getLocation();
|
|
|
|
Material type = block.getType();
|
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:
|
2012-03-16 16:30:23 +01:00
|
|
|
item = new ItemStack(Material.COAL, 1, (short) 0, CoalType.COAL.getData());
|
2012-04-27 11:47:11 +02:00
|
|
|
Misc.mcDropItem(loc, item);
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIAMOND_ORE:
|
2012-03-16 18:45:30 +01:00
|
|
|
item = new ItemStack(Material.DIAMOND);
|
2012-04-27 11:47:11 +02:00
|
|
|
Misc.mcDropItem(loc, item);
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GLOWING_REDSTONE_ORE:
|
|
|
|
case REDSTONE_ORE:
|
2012-03-16 18:45:30 +01:00
|
|
|
item = new ItemStack(Material.REDSTONE);
|
2012-04-27 11:47:11 +02:00
|
|
|
Misc.mcDropItems(loc, item, 4);
|
|
|
|
Misc.mcRandomDropItem(loc, item, 50);
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GLOWSTONE:
|
2012-03-16 18:45:30 +01:00
|
|
|
item = new ItemStack(Material.GLOWSTONE_DUST);
|
2012-04-27 11:47:11 +02:00
|
|
|
Misc.mcDropItems(loc, item, 2);
|
|
|
|
Misc.mcRandomDropItems(loc, item, 50, 2);
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAPIS_ORE:
|
2012-03-17 17:22:42 +01:00
|
|
|
item = new ItemStack(Material.INK_SACK, 1, (short) 0, (byte) 0x4);
|
2012-04-27 11:47:11 +02:00
|
|
|
Misc.mcDropItems(loc, item, 4);
|
|
|
|
Misc.mcRandomDropItems(loc, item, 50, 4);
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STONE:
|
2012-03-16 18:45:30 +01:00
|
|
|
item = new ItemStack(Material.COBBLESTONE);
|
2012-04-27 11:47:11 +02:00
|
|
|
Misc.mcDropItem(loc, item);
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-04-27 11:47:11 +02:00
|
|
|
Misc.mcDropItem(loc, item);
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-01-31 18:59:33 +01:00
|
|
|
|
2012-03-13 08:31:07 +01:00
|
|
|
/**
|
|
|
|
* Award XP for Mining blocks.
|
|
|
|
*
|
|
|
|
* @param player The player to award XP to
|
|
|
|
* @param block The block to award XP for
|
|
|
|
*/
|
|
|
|
public static void miningXP(Player player, Block block) {
|
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
|
|
|
Material type = block.getType();
|
|
|
|
int xp = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case COAL_ORE:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPCoalOre();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIAMOND_ORE:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPDiamondOre();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ENDER_STONE:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPEndStone();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GLOWING_REDSTONE_ORE:
|
|
|
|
case REDSTONE_ORE:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPRedstoneOre();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GLOWSTONE:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPGlowstone();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GOLD_ORE:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPGoldOre();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRON_ORE:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPIronOre();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAPIS_ORE:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPLapisOre();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MOSSY_COBBLESTONE:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPMossyStone();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NETHERRACK:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPNetherrack();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OBSIDIAN:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPObsidian();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SANDSTONE:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPSandstone();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STONE:
|
2012-04-27 05:58:21 +02:00
|
|
|
xp += Config.getInstance().getMiningXPStone();
|
2012-03-13 08:31:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-29 20:24:41 +02:00
|
|
|
PP.addXP(SkillType.MINING, xp);
|
2012-03-13 08:31:07 +01:00
|
|
|
Skills.XpCheckSkill(SkillType.MINING, player);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process Mining block drops.
|
|
|
|
*
|
|
|
|
* @param player The player mining the block
|
|
|
|
* @param block The block being broken
|
|
|
|
*/
|
2012-03-15 22:29:27 +01:00
|
|
|
public static void miningBlockCheck(Player player, Block block) {
|
2012-03-15 05:52:37 +01:00
|
|
|
if (block.hasMetadata("mcmmoPlacedBlock")) {
|
2012-03-13 08:31:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
miningXP(player, block);
|
|
|
|
|
|
|
|
if (canBeSuperBroken(block.getType())) {
|
|
|
|
final int MAX_BONUS_LEVEL = 1000;
|
|
|
|
|
|
|
|
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
if ((skillLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= skillLevel) && Permissions.getInstance().miningDoubleDrops(player)) {
|
2012-03-13 08:31:07 +01:00
|
|
|
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
2012-04-27 11:47:11 +02:00
|
|
|
Misc.mcDropItem(block.getLocation(), new ItemStack(block.getType()));
|
2012-03-13 08:31:07 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
miningDrops(block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-13 08:31:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if a block is broken by Super Breaker.
|
|
|
|
*
|
|
|
|
* @param type The type of Block to check
|
|
|
|
* @return true if the block would be broken by Super Breaker, false otherwise
|
2012-01-09 20:00:13 +01:00
|
|
|
*/
|
2012-03-13 08:31:07 +01:00
|
|
|
public static Boolean canBeSuperBroken(Material type) {
|
|
|
|
switch (type) {
|
|
|
|
case COAL_ORE:
|
|
|
|
case DIAMOND_ORE:
|
|
|
|
case ENDER_STONE:
|
|
|
|
case GLOWING_REDSTONE_ORE:
|
|
|
|
case GLOWSTONE:
|
|
|
|
case GOLD_ORE:
|
|
|
|
case IRON_ORE:
|
|
|
|
case LAPIS_ORE:
|
|
|
|
case MOSSY_COBBLESTONE:
|
|
|
|
case NETHERRACK:
|
|
|
|
case OBSIDIAN:
|
|
|
|
case REDSTONE_ORE:
|
|
|
|
case SANDSTONE:
|
|
|
|
case STONE:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-13 08:31:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the Super Breaker ability.
|
|
|
|
*
|
|
|
|
* @param player The player using the ability
|
|
|
|
* @param block The block being affected
|
|
|
|
*/
|
2012-03-15 22:29:27 +01:00
|
|
|
public static void SuperBreakerBlockCheck(Player player, Block block) {
|
2012-03-13 08:31:07 +01:00
|
|
|
Material type = block.getType();
|
2012-04-27 11:47:11 +02:00
|
|
|
int tier = Misc.getTier(player.getItemInHand());
|
2012-04-27 05:58:21 +02:00
|
|
|
int durabilityLoss = Config.getInstance().getAbilityToolDamage();
|
2012-03-27 05:01:51 +02:00
|
|
|
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
|
2012-03-13 08:31:07 +01:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case OBSIDIAN:
|
|
|
|
if (tier < 4) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
durabilityLoss = durabilityLoss * 5; //Obsidian needs to do more damage than normal
|
|
|
|
/* FALL THROUGH */
|
|
|
|
|
|
|
|
case DIAMOND_ORE:
|
|
|
|
case GLOWING_REDSTONE_ORE:
|
|
|
|
case GOLD_ORE:
|
|
|
|
case LAPIS_ORE:
|
|
|
|
case REDSTONE_ORE:
|
|
|
|
if (tier < 3) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* FALL THROUGH */
|
|
|
|
|
|
|
|
case IRON_ORE:
|
|
|
|
if (tier < 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* FALL THROUGH */
|
|
|
|
|
|
|
|
case COAL_ORE:
|
|
|
|
case ENDER_STONE:
|
|
|
|
case GLOWSTONE:
|
|
|
|
case MOSSY_COBBLESTONE:
|
|
|
|
case NETHERRACK:
|
|
|
|
case SANDSTONE:
|
|
|
|
case STONE:
|
2012-03-22 20:48:11 +01:00
|
|
|
if (block.hasMetadata("mcmmoPlacedBlock")) {
|
2012-03-13 08:31:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-21 00:09:50 +02:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
|
2012-03-13 08:31:07 +01:00
|
|
|
Skills.abilityDurabilityLoss(player.getItemInHand(), durabilityLoss);
|
|
|
|
|
2012-03-15 22:29:27 +01:00
|
|
|
miningBlockCheck(player, block);
|
2012-03-13 08:31:07 +01:00
|
|
|
|
2012-04-27 05:58:21 +02:00
|
|
|
if (Config.getInstance().spoutEnabled) {
|
2012-03-21 03:33:58 +01:00
|
|
|
SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
|
2012-03-13 08:31:07 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
}
|