mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-27 02:58:03 +01:00
More mining restructuring.
This commit is contained in:
parent
85fb12a4ec
commit
ccfe1181be
@ -83,7 +83,6 @@ import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory;
|
||||
|
||||
|
||||
public class mcMMO extends JavaPlugin {
|
||||
|
||||
private final PlayerListener playerListener = new PlayerListener(this);
|
||||
private final BlockListener blockListener = new BlockListener(this);
|
||||
private final EntityListener entityListener = new EntityListener(this);
|
||||
|
@ -10,16 +10,12 @@ import org.bukkit.block.Block;
|
||||
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.Skills;
|
||||
@ -32,13 +28,17 @@ public class Mining {
|
||||
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) {
|
||||
protected static void miningXP(Player player, PlayerProfile profile, Block block, Material type) {
|
||||
int xp = 0;
|
||||
|
||||
switch (type) {
|
||||
@ -109,91 +109,6 @@ public class Mining {
|
||||
Skills.xpProcessing(player, profile, SkillType.MINING, xp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.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);
|
||||
|
||||
MiningManager manager = new MiningManager(player);
|
||||
manager.miningBlockCheck(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);
|
||||
|
||||
MiningManager manager = new MiningManager(player);
|
||||
manager.miningBlockCheck(block);
|
||||
|
||||
if (mcMMO.spoutEnabled) {
|
||||
SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle double drops when using Silk Touch.
|
||||
*
|
||||
@ -266,7 +181,6 @@ public class Mining {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,11 +4,13 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public class MiningBlockEventHandler {
|
||||
private MiningManager manager;
|
||||
private Player player;
|
||||
|
||||
private Block block;
|
||||
private Location blockLocation;
|
||||
@ -18,6 +20,7 @@ public class MiningBlockEventHandler {
|
||||
|
||||
protected MiningBlockEventHandler(MiningManager manager, Block block) {
|
||||
this.manager = manager;
|
||||
this.player = manager.getPlayer();
|
||||
|
||||
this.block = block;
|
||||
this.blockLocation = block.getLocation();
|
||||
@ -37,7 +40,7 @@ public class MiningBlockEventHandler {
|
||||
* @param block The block being broken
|
||||
*/
|
||||
protected void processDrops() {
|
||||
if (manager.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
Mining.silkTouchDrops(block, blockLocation, blockType);
|
||||
}
|
||||
else {
|
||||
@ -46,6 +49,6 @@ public class MiningBlockEventHandler {
|
||||
}
|
||||
|
||||
protected void processXP() {
|
||||
Mining.miningXP(manager.getPlayer(), manager.getProfile(), block, blockType);
|
||||
Mining.miningXP(player, manager.getProfile(), block, blockType);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
@ -44,13 +45,37 @@ public class MiningManager {
|
||||
randomChance = (int) (randomChance * 0.75);
|
||||
}
|
||||
|
||||
float chance = (float) (((double) Mining.DOUBLE_DROPS_MAX_CHANCE / Mining.DOUBLE_DROPS_MAX_BONUS_LEVEL) * eventHandler.skillModifier);
|
||||
float chance = ((float) Mining.DOUBLE_DROPS_MAX_CHANCE / Mining.DOUBLE_DROPS_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
|
||||
|
||||
if (chance > Mining.getRandom().nextInt(randomChance)) {
|
||||
eventHandler.processDrops();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Super Breaker ability.
|
||||
*
|
||||
* @param player The player using the ability
|
||||
* @param block The block being affected
|
||||
*/
|
||||
public void superBreakerBlockCheck(Block block) {
|
||||
if (mcMMO.placeStore.isTrue(block) || Misc.blockBreakSimulate(block, player, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MiningManager manager = new MiningManager(player);
|
||||
SuperBreakerEventHandler eventHandler = new SuperBreakerEventHandler(manager, block);
|
||||
|
||||
if (eventHandler.tierCheck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
eventHandler.callFakeArmswing();
|
||||
eventHandler.processDurabilityLoss();
|
||||
eventHandler.processDropsAndXP();
|
||||
eventHandler.playSpoutSound();
|
||||
}
|
||||
|
||||
protected int getSkillLevel() {
|
||||
return skillLevel;
|
||||
}
|
||||
|
@ -0,0 +1,123 @@
|
||||
package com.gmail.nossr50.skills.mining;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.getspout.spoutapi.sound.SoundEffect;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
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.Skills;
|
||||
|
||||
public class SuperBreakerEventHandler {
|
||||
private MiningManager manager;
|
||||
private Player player;
|
||||
|
||||
private Block block;
|
||||
private Material blockType;
|
||||
private boolean customBlock;
|
||||
|
||||
private ItemStack heldItem;
|
||||
private int tier;
|
||||
|
||||
private int durabilityLoss;
|
||||
private FakePlayerAnimationEvent armswing;
|
||||
|
||||
protected SuperBreakerEventHandler (MiningManager manager, Block block) {
|
||||
this.manager = manager;
|
||||
this.player = manager.getPlayer();
|
||||
|
||||
this.block = block;
|
||||
this.blockType = block.getType();
|
||||
this.customBlock = ModChecks.isCustomMiningBlock(block);
|
||||
|
||||
this.heldItem = player.getItemInHand();
|
||||
this.tier = Misc.getTier(heldItem);
|
||||
|
||||
this.armswing = new FakePlayerAnimationEvent(player);
|
||||
|
||||
calculateDurabilityLoss();
|
||||
}
|
||||
|
||||
protected void callFakeArmswing() {
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
|
||||
}
|
||||
|
||||
protected void processDurabilityLoss() {
|
||||
Skills.abilityDurabilityLoss(heldItem, durabilityLoss);
|
||||
}
|
||||
|
||||
protected void processDropsAndXP() {
|
||||
manager.miningBlockCheck(block);
|
||||
}
|
||||
|
||||
protected void playSpoutSound() {
|
||||
SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for the proper tier of item for use with Super Breaker.
|
||||
*
|
||||
* @return True if the item is the required tier or higher, false otherwise
|
||||
*/
|
||||
protected boolean tierCheck() {
|
||||
if (customBlock) {
|
||||
if (ModChecks.getCustomBlock(block).getTier() < tier) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (blockType) {
|
||||
case OBSIDIAN:
|
||||
if (tier < Mining.DIAMOND_TOOL_TIER) {
|
||||
return false;
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
|
||||
case DIAMOND_ORE:
|
||||
case GLOWING_REDSTONE_ORE:
|
||||
case GOLD_ORE:
|
||||
case LAPIS_ORE:
|
||||
case REDSTONE_ORE:
|
||||
case EMERALD_ORE:
|
||||
if (tier < Mining.IRON_TOOL_TIER) {
|
||||
return false;
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
|
||||
case IRON_ORE:
|
||||
if (tier < Mining.STONE_TOOL_TIER) {
|
||||
return false;
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
|
||||
case COAL_ORE:
|
||||
case ENDER_STONE:
|
||||
case GLOWSTONE:
|
||||
case MOSSY_COBBLESTONE:
|
||||
case NETHERRACK:
|
||||
case SANDSTONE:
|
||||
case STONE:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateDurabilityLoss() {
|
||||
this.durabilityLoss = Misc.TOOL_DURABILITY_LOSS;
|
||||
|
||||
if (blockType.equals(Material.OBSIDIAN)) {
|
||||
durabilityLoss = durabilityLoss * 5;
|
||||
}
|
||||
}
|
||||
}
|
@ -20,9 +20,10 @@ import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
||||
import com.gmail.nossr50.events.items.McMMOItemSpawnEvent;
|
||||
|
||||
public class Misc {
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
public static final int TOOL_DURABILITY_LOSS = Config.getInstance().getAbilityToolDamage();
|
||||
|
||||
/**
|
||||
* Gets a capitalized version of the target string.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user