mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 19:54:44 +02:00
Fixed update for Mining refactoring
This commit is contained in:
331
src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java
Normal file
331
src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java
Normal file
@ -0,0 +1,331 @@
|
||||
package com.gmail.nossr50.skills.mining;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.datatypes.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.BlockChecks;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Skills;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class BlastMining {
|
||||
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
private static int blastMiningRank1 = advancedConfig.getBlastMiningRank1();
|
||||
private static int blastMiningRank2 = advancedConfig.getBlastMiningRank2();
|
||||
private static int blastMiningRank3 = advancedConfig.getBlastMiningRank3();
|
||||
private static int blastMiningRank4 = advancedConfig.getBlastMiningRank4();
|
||||
private static int blastMiningRank5 = advancedConfig.getBlastMiningRank5();
|
||||
private static int blastMiningRank6 = advancedConfig.getBlastMiningRank6();
|
||||
private static int blastMiningRank7 = advancedConfig.getBlastMiningRank7();
|
||||
private static int blastMiningRank8 = advancedConfig.getBlastMiningRank8();
|
||||
/**
|
||||
* Handler for what blocks drop from the explosion.
|
||||
*
|
||||
* @param ores List of ore blocks destroyed by the explosion
|
||||
* @param debris List of non-ore blocks destroyed by the explosion
|
||||
* @param yield Percentage of blocks to drop
|
||||
* @param oreBonus Percentage bonus for ore drops
|
||||
* @param debrisReduction Percentage reduction for non-ore drops
|
||||
* @param extraDrops Number of times to drop each block
|
||||
* @return A list of blocks dropped from the explosion
|
||||
*/
|
||||
private static List<Block> explosionYields(List<Block> ores, List<Block> debris, float yield, float oreBonus, float debrisReduction, int extraDrops) {
|
||||
Iterator<Block> oresIterator = ores.iterator();
|
||||
List<Block> blocksDropped = new ArrayList<Block>();
|
||||
|
||||
while (oresIterator.hasNext()) {
|
||||
Block temp = oresIterator.next();
|
||||
|
||||
if (random.nextFloat() < (yield + oreBonus)) {
|
||||
blocksDropped.add(temp);
|
||||
Mining.miningDrops(temp);
|
||||
|
||||
if (!mcMMO.placeStore.isTrue(temp)) {
|
||||
for (int i = 1 ; i < extraDrops ; i++) {
|
||||
blocksDropped.add(temp);
|
||||
Mining.miningDrops(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (yield - debrisReduction > 0) {
|
||||
Iterator<Block> debrisIterator = debris.iterator();
|
||||
|
||||
while (debrisIterator.hasNext()) {
|
||||
Block temp = debrisIterator.next();
|
||||
|
||||
if (random.nextFloat() < (yield - debrisReduction))
|
||||
Mining.miningDrops(temp);
|
||||
}
|
||||
}
|
||||
|
||||
return blocksDropped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for explosion drops and XP gain.
|
||||
*
|
||||
* @param player Player triggering the explosion
|
||||
* @param event Event whose explosion is being processed
|
||||
*/
|
||||
public static void dropProcessing(Player player, EntityExplodeEvent event) {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
final int RANK_1_LEVEL = blastMiningRank1;
|
||||
final int RANK_2_LEVEL = blastMiningRank2;
|
||||
final int RANK_3_LEVEL = blastMiningRank3;
|
||||
final int RANK_4_LEVEL = blastMiningRank4;
|
||||
final int RANK_5_LEVEL = blastMiningRank5;
|
||||
final int RANK_6_LEVEL = blastMiningRank6;
|
||||
final int RANK_7_LEVEL = blastMiningRank7;
|
||||
final int RANK_8_LEVEL = blastMiningRank8;
|
||||
|
||||
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
|
||||
float yield = event.getYield();
|
||||
List<Block> blocks = event.blockList();
|
||||
Iterator<Block> iterator = blocks.iterator();
|
||||
|
||||
List<Block> ores = new ArrayList<Block>();
|
||||
List<Block> debris = new ArrayList<Block>();
|
||||
List<Block> xp = new ArrayList<Block>();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
Block temp = iterator.next();
|
||||
|
||||
if (BlockChecks.isOre(temp)) {
|
||||
ores.add(temp);
|
||||
}
|
||||
else {
|
||||
debris.add(temp);
|
||||
}
|
||||
}
|
||||
|
||||
//Normal explosion
|
||||
if (skillLevel < RANK_1_LEVEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setYield(0);
|
||||
|
||||
//Triple Drops, No debris, +70% ores
|
||||
if (skillLevel >= RANK_8_LEVEL) {
|
||||
xp = explosionYields(ores, debris, yield, .70f, .30f, 3);
|
||||
}
|
||||
|
||||
//Triple Drops, No debris, +65% ores
|
||||
else if (skillLevel >= RANK_7_LEVEL) {
|
||||
xp = explosionYields(ores, debris, yield, .65f, .30f, 3);
|
||||
}
|
||||
|
||||
//Double Drops, No Debris, +60% ores
|
||||
else if (skillLevel >= RANK_6_LEVEL) {
|
||||
xp = explosionYields(ores, debris, yield, .60f, .30f, 2);
|
||||
}
|
||||
|
||||
//Double Drops, No Debris, +55% ores
|
||||
else if (skillLevel >= RANK_5_LEVEL) {
|
||||
xp = explosionYields(ores, debris, yield, .55f, .30f, 2);
|
||||
}
|
||||
|
||||
//No debris, +50% ores
|
||||
else if (skillLevel >= RANK_4_LEVEL) {
|
||||
xp = explosionYields(ores, debris, yield, .50f, .30f, 1);
|
||||
}
|
||||
|
||||
//No debris, +45% ores
|
||||
else if (skillLevel >= RANK_3_LEVEL) {
|
||||
xp = explosionYields(ores, debris, yield, .45f, .30f, 1);
|
||||
}
|
||||
|
||||
//+40% ores, -20% debris
|
||||
else if (skillLevel >= RANK_2_LEVEL) {
|
||||
xp = explosionYields(ores, debris, yield, .40f, .20f, 1);
|
||||
}
|
||||
|
||||
//+35% ores, -10% debris
|
||||
else if (skillLevel >= RANK_1_LEVEL) {
|
||||
xp = explosionYields(ores, debris, yield, .35f, .10f, 1);
|
||||
}
|
||||
|
||||
for (Block block : xp) {
|
||||
if (!mcMMO.placeStore.isTrue(block)) {
|
||||
Mining.miningXP(player, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the blast radius of the explosion.
|
||||
*
|
||||
* @param player Player triggering the explosion
|
||||
* @param event Event whose explosion radius is being changed
|
||||
*/
|
||||
public static void biggerBombs(Player player, ExplosionPrimeEvent event) {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
final int RANK_1_LEVEL = blastMiningRank2;
|
||||
final int RANK_2_LEVEL = blastMiningRank4;
|
||||
final int RANK_3_LEVEL = blastMiningRank6;
|
||||
final int RANK_4_LEVEL = blastMiningRank8;
|
||||
|
||||
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
|
||||
float radius = event.getRadius();
|
||||
|
||||
if (skillLevel < RANK_1_LEVEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (skillLevel >= RANK_1_LEVEL) {
|
||||
radius++;
|
||||
}
|
||||
|
||||
if (skillLevel >= RANK_2_LEVEL) {
|
||||
radius++;
|
||||
}
|
||||
|
||||
if (skillLevel >= RANK_3_LEVEL) {
|
||||
radius++;
|
||||
}
|
||||
|
||||
if (skillLevel >= RANK_4_LEVEL) {
|
||||
radius++;
|
||||
}
|
||||
|
||||
event.setRadius(radius);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decreases damage dealt by the explosion.
|
||||
*
|
||||
* @param player Player triggering the explosion
|
||||
* @param event Event whose explosion damage is being reduced
|
||||
*/
|
||||
public static void demolitionsExpertise(Player player, EntityDamageEvent event) {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
final int RANK_1_LEVEL = blastMiningRank4;
|
||||
final int RANK_2_LEVEL = blastMiningRank6;
|
||||
final int RANK_3_LEVEL = blastMiningRank8;
|
||||
|
||||
int skill = Users.getProfile(player).getSkillLevel(SkillType.MINING);
|
||||
int damage = event.getDamage();
|
||||
|
||||
if (skill < RANK_1_LEVEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (skill >= RANK_3_LEVEL) {
|
||||
damage = 0;
|
||||
}
|
||||
else if (skill >= RANK_2_LEVEL) {
|
||||
damage = damage / 2;
|
||||
}
|
||||
else if (skill >= RANK_1_LEVEL) {
|
||||
damage = damage/4;
|
||||
}
|
||||
|
||||
event.setDamage(damage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detonate TNT for Blast Mining
|
||||
*
|
||||
* @param event The PlayerInteractEvent
|
||||
* @param player Player detonating the TNT
|
||||
* @param plugin mcMMO plugin instance
|
||||
*/
|
||||
public static void detonate(PlayerInteractEvent event, Player player, mcMMO plugin) {
|
||||
if(player == null)
|
||||
return;
|
||||
|
||||
PlayerProfile profile = Users.getProfile(player);
|
||||
|
||||
if (profile.getSkillLevel(SkillType.MINING) < 125)
|
||||
return;
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
if (block == null || block.getType() != Material.TNT) {
|
||||
final byte SNOW = 78;
|
||||
final byte AIR = 0;
|
||||
final int BLOCKS_AWAY = 100;
|
||||
|
||||
HashSet<Byte> transparent = new HashSet<Byte>();
|
||||
|
||||
transparent.add(SNOW);
|
||||
transparent.add(AIR);
|
||||
|
||||
block = player.getTargetBlock(transparent, BLOCKS_AWAY);
|
||||
|
||||
if (block.getType() != Material.TNT) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (block.getType() == Material.TNT) {
|
||||
event.setCancelled(true); // This is the only way I know to avoid the original TNT to be triggered (in case the player is close to it)
|
||||
}
|
||||
|
||||
if (!Misc.blockBreakSimulate(block, player, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final double MAX_DISTANCE_AWAY = 10.0;
|
||||
final int TIME_CONVERSION_FACTOR = 1000;
|
||||
|
||||
AbilityType ability = AbilityType.BLAST_MINING;
|
||||
|
||||
/* Check Cooldown */
|
||||
if (!Skills.cooldownOver(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + Skills.calculateTimeLeft(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player) + "s)");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Send message to nearby players */
|
||||
for (Player y : player.getWorld().getPlayers()) {
|
||||
if (y != player && Misc.isNear(player.getLocation(), y.getLocation(), MAX_DISTANCE_AWAY)) {
|
||||
y.sendMessage(ability.getAbilityPlayer(player));
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom"));
|
||||
|
||||
/* Create the TNT entity */
|
||||
// TNTPrimed tnt = (TNTPrimed) player.getWorld().spawnEntity(block.getLocation(), EntityType.PRIMED_TNT);
|
||||
TNTPrimed tnt = player.getWorld().spawn(block.getLocation(), TNTPrimed.class);
|
||||
plugin.addToTNTTracker(tnt.getEntityId(), player.getName());
|
||||
tnt.setFuseTicks(0);
|
||||
|
||||
/* Disable the original one */
|
||||
block.setType(Material.AIR);
|
||||
|
||||
profile.setSkillDATS(ability, System.currentTimeMillis()); //Save DATS for Blast Mining
|
||||
profile.setAbilityInformed(ability, false);
|
||||
}
|
||||
}
|
434
src/main/java/com/gmail/nossr50/skills/mining/Mining.java
Normal file
434
src/main/java/com/gmail/nossr50/skills/mining/Mining.java
Normal file
@ -0,0 +1,434 @@
|
||||
package com.gmail.nossr50.skills.mining;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.CoalType;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.getspout.spoutapi.sound.SoundEffect;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
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.events.fake.FakePlayerAnimationEvent;
|
||||
import com.gmail.nossr50.spout.SpoutSounds;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.ModChecks;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Skills;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class Mining {
|
||||
private static Random random = new Random();
|
||||
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
||||
|
||||
/**
|
||||
* Handle double drops when using Silk Touch.
|
||||
*
|
||||
* @param block The block to process drops for
|
||||
*/
|
||||
private static void silkTouchDrops(Block block) {
|
||||
Location location = block.getLocation();
|
||||
Material type = block.getType();
|
||||
ItemStack item = new ItemStack(type);
|
||||
Config configInstance = Config.getInstance();
|
||||
|
||||
switch (type) {
|
||||
case ENDER_STONE:
|
||||
case GOLD_ORE:
|
||||
case IRON_ORE:
|
||||
case MOSSY_COBBLESTONE:
|
||||
case NETHERRACK:
|
||||
case OBSIDIAN:
|
||||
case SANDSTONE:
|
||||
miningDrops(block);
|
||||
break;
|
||||
|
||||
case COAL_ORE:
|
||||
if (configInstance.getCoalDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case DIAMOND_ORE:
|
||||
if (configInstance.getDiamondDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
case REDSTONE_ORE:
|
||||
if (configInstance.getRedstoneDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case GLOWSTONE:
|
||||
if (configInstance.getGlowstoneDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case LAPIS_ORE:
|
||||
if (configInstance.getLapisDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case STONE:
|
||||
if (configInstance.getStoneDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case EMERALD_ORE:
|
||||
if (configInstance.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
|
||||
*/
|
||||
public static void miningDrops(Block block) {
|
||||
Location location = block.getLocation();
|
||||
Material type = block.getType();
|
||||
ItemStack item = new ItemStack(type);
|
||||
Config configInstance = Config.getInstance();
|
||||
|
||||
switch (type) {
|
||||
case COAL_ORE:
|
||||
if (configInstance.getCoalDoubleDropsEnabled()) {
|
||||
item = (new MaterialData(Material.COAL, CoalType.COAL.getData())).toItemStack(1);
|
||||
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case DIAMOND_ORE:
|
||||
if (configInstance.getDiamondDoubleDropsEnabled()) {
|
||||
item = new ItemStack(Material.DIAMOND);
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case ENDER_STONE:
|
||||
if (configInstance.getEndStoneDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
case REDSTONE_ORE:
|
||||
if (configInstance.getRedstoneDoubleDropsEnabled()) {
|
||||
item = new ItemStack(Material.REDSTONE);
|
||||
Misc.dropItems(location, item, 4);
|
||||
Misc.randomDropItem(location, item, 50);
|
||||
}
|
||||
break;
|
||||
|
||||
case GLOWSTONE:
|
||||
if (configInstance.getGlowstoneDoubleDropsEnabled()) {
|
||||
item = new ItemStack(Material.GLOWSTONE_DUST);
|
||||
Misc.dropItems(location, item, 2);
|
||||
Misc.randomDropItems(location, item, 50, 2);
|
||||
}
|
||||
break;
|
||||
|
||||
case GOLD_ORE:
|
||||
if (configInstance.getGoldDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case IRON_ORE:
|
||||
if (configInstance.getIronDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case LAPIS_ORE:
|
||||
if (configInstance.getLapisDoubleDropsEnabled()) {
|
||||
item = (new MaterialData(Material.INK_SACK, (byte) 0x4)).toItemStack(1);
|
||||
|
||||
Misc.dropItems(location, item, 4);
|
||||
Misc.randomDropItems(location, item, 50, 4);
|
||||
}
|
||||
break;
|
||||
|
||||
case MOSSY_COBBLESTONE:
|
||||
if (configInstance.getMossyCobblestoneDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case NETHERRACK:
|
||||
if (configInstance.getNetherrackDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case OBSIDIAN:
|
||||
if (configInstance.getObsidianDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case SANDSTONE:
|
||||
if (configInstance.getSandstoneDoubleDropsEnabled()) {
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case STONE:
|
||||
if (configInstance.getStoneDoubleDropsEnabled()) {
|
||||
item = new ItemStack(Material.COBBLESTONE);
|
||||
Misc.dropItem(location, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case EMERALD_ORE:
|
||||
if (configInstance.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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 profile = Users.getProfile(player);
|
||||
Material type = block.getType();
|
||||
int xp = 0;
|
||||
|
||||
switch (type) {
|
||||
case COAL_ORE:
|
||||
xp += Config.getInstance().getMiningXPCoalOre();
|
||||
break;
|
||||
|
||||
case DIAMOND_ORE:
|
||||
xp += Config.getInstance().getMiningXPDiamondOre();
|
||||
break;
|
||||
|
||||
case ENDER_STONE:
|
||||
xp += Config.getInstance().getMiningXPEndStone();
|
||||
break;
|
||||
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
case REDSTONE_ORE:
|
||||
xp += Config.getInstance().getMiningXPRedstoneOre();
|
||||
break;
|
||||
|
||||
case GLOWSTONE:
|
||||
xp += Config.getInstance().getMiningXPGlowstone();
|
||||
break;
|
||||
|
||||
case GOLD_ORE:
|
||||
xp += Config.getInstance().getMiningXPGoldOre();
|
||||
break;
|
||||
|
||||
case IRON_ORE:
|
||||
xp += Config.getInstance().getMiningXPIronOre();
|
||||
break;
|
||||
|
||||
case LAPIS_ORE:
|
||||
xp += Config.getInstance().getMiningXPLapisOre();
|
||||
break;
|
||||
|
||||
case MOSSY_COBBLESTONE:
|
||||
xp += Config.getInstance().getMiningXPMossyStone();
|
||||
break;
|
||||
|
||||
case NETHERRACK:
|
||||
xp += Config.getInstance().getMiningXPNetherrack();
|
||||
break;
|
||||
|
||||
case OBSIDIAN:
|
||||
xp += Config.getInstance().getMiningXPObsidian();
|
||||
break;
|
||||
|
||||
case SANDSTONE:
|
||||
xp += Config.getInstance().getMiningXPSandstone();
|
||||
break;
|
||||
|
||||
case STONE:
|
||||
xp += Config.getInstance().getMiningXPStone();
|
||||
break;
|
||||
|
||||
case EMERALD_ORE:
|
||||
xp += Config.getInstance().getMiningXPEmeraldOre();
|
||||
break;
|
||||
|
||||
default:
|
||||
if (ModChecks.isCustomMiningBlock(block)) {
|
||||
xp += ModChecks.getCustomBlock(block).getXpGain();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Skills.xpProcessing(player, profile, SkillType.MINING, xp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process Mining block drops.
|
||||
*
|
||||
* @param player The player mining the block
|
||||
* @param block The block being broken
|
||||
*/
|
||||
public static void miningBlockCheck(Player player, Block block) {
|
||||
if (mcMMO.placeStore.isTrue(block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
miningXP(player, block);
|
||||
|
||||
final int MAX_BONUS_LEVEL = advancedConfig.getMiningDoubleDropMaxLevel();
|
||||
int MAX_CHANCE = advancedConfig.getMiningDoubleDropChance();
|
||||
|
||||
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
|
||||
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
|
||||
|
||||
int randomChance = 100;
|
||||
int chance = (int) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * skillCheck);
|
||||
|
||||
if (player.hasPermission("mcmmo.perks.lucky.mining")) {
|
||||
randomChance = (int) (randomChance * 0.75);
|
||||
}
|
||||
|
||||
if (chance > random.nextInt(randomChance) && Permissions.getInstance().miningDoubleDrops(player)) {
|
||||
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
silkTouchDrops(block);
|
||||
}
|
||||
else {
|
||||
miningDrops(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Super Breaker ability.
|
||||
*
|
||||
* @param player The player using the ability
|
||||
* @param block The block being affected
|
||||
*/
|
||||
public static void superBreakerBlockCheck(Player player, Block block) {
|
||||
Material type = block.getType();
|
||||
int tier = Misc.getTier(player.getItemInHand());
|
||||
int durabilityLoss = Config.getInstance().getAbilityToolDamage();
|
||||
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
|
||||
|
||||
if (ModChecks.isCustomMiningBlock(block)) {
|
||||
if (ModChecks.getCustomBlock(block).getTier() < tier) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mcMMO.placeStore.isTrue(block) || Misc.blockBreakSimulate(block, player, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
|
||||
Skills.abilityDurabilityLoss(player.getItemInHand(), durabilityLoss);
|
||||
|
||||
miningBlockCheck(player, block);
|
||||
|
||||
if (mcMMO.spoutEnabled) {
|
||||
SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
|
||||
}
|
||||
}
|
||||
else {
|
||||
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:
|
||||
case EMERALD_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:
|
||||
if (mcMMO.placeStore.isTrue(block) || Misc.blockBreakSimulate(block, player, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
|
||||
Skills.abilityDurabilityLoss(player.getItemInHand(), durabilityLoss);
|
||||
|
||||
miningBlockCheck(player, block);
|
||||
|
||||
if (mcMMO.spoutEnabled) {
|
||||
SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user