2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.skills.mining;
|
|
|
|
|
2014-07-20 00:00:36 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
2013-09-13 15:12:21 +02:00
|
|
|
import org.bukkit.Material;
|
2014-07-20 00:41:54 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.entity.TNTPrimed;
|
|
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
|
2013-09-13 15:12:21 +02:00
|
|
|
|
2014-07-20 00:41:54 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
|
|
|
import com.gmail.nossr50.config.Config;
|
2014-07-20 00:41:54 +02:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
public class BlastMining {
|
|
|
|
// The order of the values is extremely important, a few methods depend on it to work properly
|
2013-10-01 14:57:21 +02:00
|
|
|
public enum Tier {
|
|
|
|
EIGHT(8),
|
|
|
|
SEVEN(7),
|
|
|
|
SIX(6),
|
|
|
|
FIVE(5),
|
|
|
|
FOUR(4),
|
|
|
|
THREE(3),
|
|
|
|
TWO(2),
|
|
|
|
ONE(1);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
int numerical;
|
|
|
|
|
|
|
|
private Tier(int numerical) {
|
|
|
|
this.numerical = numerical;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int toNumerical() {
|
|
|
|
return numerical;
|
|
|
|
}
|
|
|
|
|
2013-10-01 14:57:21 +02:00
|
|
|
protected int getLevel() {
|
|
|
|
return AdvancedConfig.getInstance().getBlastMiningRankLevel(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected double getBlastRadiusModifier() {
|
|
|
|
return AdvancedConfig.getInstance().getBlastRadiusModifier(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected double getOreBonus() {
|
|
|
|
return AdvancedConfig.getInstance().getOreBonus(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected double getDebrisReduction() {
|
|
|
|
return AdvancedConfig.getInstance().getDebrisReduction(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected double getBlastDamageDecrease() {
|
|
|
|
return AdvancedConfig.getInstance().getBlastDamageDecrease(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int getDropMultiplier() {
|
|
|
|
return AdvancedConfig.getInstance().getDropMultiplier(this);
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-09-13 15:12:21 +02:00
|
|
|
public static Material detonator = Config.getInstance().getDetonatorItem();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
public final static int MAXIMUM_REMOTE_DETONATION_DISTANCE = 100;
|
2014-07-20 00:00:36 +02:00
|
|
|
|
|
|
|
public static int getDemolitionExpertUnlockLevel() {
|
|
|
|
List<Tier> tierList = Arrays.asList(Tier.values());
|
|
|
|
for (Tier tier : tierList) {
|
|
|
|
if (tier.getBlastDamageDecrease() > 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tier == Tier.EIGHT ? tier.getLevel() : tierList.get(tierList.indexOf(tier) - 1).getLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getBiggerBombsUnlockLevel() {
|
|
|
|
List<Tier> tierList = Arrays.asList(Tier.values());
|
|
|
|
for (Tier tier : tierList) {
|
|
|
|
if (tier.getBlastRadiusModifier() > 1.0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tier == Tier.EIGHT ? tier.getLevel() : tierList.get(tierList.indexOf(tier) - 1).getLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-07-20 00:41:54 +02:00
|
|
|
|
|
|
|
public static boolean processBlastMiningExplosion(EntityDamageByEntityEvent event, TNTPrimed tnt, Player defender) {
|
|
|
|
if (!tnt.hasMetadata(mcMMO.tntMetadataKey) || !UserManager.hasPlayerDataKey(defender)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can make this assumption because we (should) be the only ones using this exact metadata
|
|
|
|
Player player = mcMMO.p.getServer().getPlayerExact(tnt.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
|
|
|
|
|
|
|
|
if (!player.equals(defender)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MiningManager miningManager = UserManager.getPlayer(defender).getMiningManager();
|
|
|
|
|
|
|
|
if (!miningManager.canUseDemolitionsExpertise()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setDamage(DamageModifier.BASE, miningManager.processDemolitionsExpertise(event.getDamage()));
|
|
|
|
|
|
|
|
if (event.getFinalDamage() == 0) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|