Convert or Tweaked Mining/Salvage/Smelting for behaviours

This commit is contained in:
nossr50 2019-07-03 02:40:41 -07:00
parent cf6d28a1bd
commit 5af09581e0
11 changed files with 313 additions and 420 deletions

View File

@ -1,6 +1,21 @@
package com.gmail.nossr50.datatypes.skills.behaviours; package com.gmail.nossr50.datatypes.skills.behaviours;
import com.gmail.nossr50.core.MetadataConstants;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.RankUtils;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import java.util.List;
/** /**
* These behaviour classes are a band-aid fix for a larger problem * These behaviour classes are a band-aid fix for a larger problem
@ -12,8 +27,244 @@ import com.gmail.nossr50.mcMMO;
public class MiningBehaviour { public class MiningBehaviour {
private final mcMMO pluginRef; private final mcMMO pluginRef;
private List<Material> detonators;
public final int MAXIMUM_REMOTE_DETONATION_DISTANCE = 100;
public MiningBehaviour(mcMMO pluginRef) { public MiningBehaviour(mcMMO pluginRef) {
this.pluginRef = pluginRef; this.pluginRef = pluginRef;
this.detonators = ItemUtils.matchMaterials(pluginRef.getConfigManager().getConfigMining().getDetonators());
}
public double getBlastRadiusModifier(int rank) {
return pluginRef.getConfigManager().getConfigMining().getBlastMining().getRadius(rank);
}
public double getBlastDamageDecrease(int rank) {
return pluginRef.getConfigManager().getConfigMining().getBlastMining().getDamageDecrease(rank);
}
public int getDemolitionExpertUnlockLevel() {
for (int i = 0; i < SubSkillType.MINING_BLAST_MINING.getNumRanks() - 1; i++) {
if (getBlastDamageDecrease(i + 1) > 0)
return RankUtils.getRankUnlockLevel(SubSkillType.MINING_BLAST_MINING, i + 1);
}
return 0;
}
public int getBiggerBombsUnlockLevel() {
for (int i = 0; i < SubSkillType.MINING_BLAST_MINING.getNumRanks() - 1; i++) {
if (getBlastRadiusModifier(i + 1) > 0)
return RankUtils.getRankUnlockLevel(SubSkillType.MINING_BLAST_MINING, i + 1);
}
return 0;
}
public boolean processBlastMiningExplosion(EntityDamageByEntityEvent event, TNTPrimed tnt, Player defender) {
if (!tnt.hasMetadata(MetadataConstants.TNT_TRACKING_METAKEY) || !pluginRef.getUserManager().hasPlayerDataKey(defender)) {
return false;
}
// We can make this assumption because we (should) be the only ones using this exact metadata
Player player = pluginRef.getServer().getPlayerExact(tnt.getMetadata(MetadataConstants.TNT_TRACKING_METAKEY).get(0).asString());
if (!player.equals(defender)) {
return false;
}
if (pluginRef.getUserManager().getPlayer(defender) == null) {
return false;
}
MiningManager miningManager = pluginRef.getUserManager().getPlayer(defender).getMiningManager();
if (!miningManager.canUseDemolitionsExpertise()) {
return false;
}
event.setDamage(EntityDamageEvent.DamageModifier.BASE, miningManager.processDemolitionsExpertise(event.getDamage()));
if (event.getFinalDamage() == 0) {
event.setCancelled(true);
return false;
}
return true;
}
/**
* Calculate XP gain for Mining.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
public int getBlockXp(BlockState blockState) {
int xp = pluginRef.getDynamicSettingsManager().getExperienceManager().getMiningXp(blockState.getType());
return xp;
}
/**
* Handle double drops when using Silk Touch.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
public void handleSilkTouchDrops(BlockState blockState) {
Material blockType = blockState.getType();
switch (blockType) {
case ANDESITE:
case DIORITE:
case GRANITE:
case END_STONE:
case TERRACOTTA:
case CLAY:
case IRON_ORE:
case MOSSY_COBBLESTONE:
case NETHERRACK:
case OBSIDIAN:
case SANDSTONE:
case BLACK_GLAZED_TERRACOTTA:
case BLACK_TERRACOTTA:
case BLUE_GLAZED_TERRACOTTA:
case BLUE_TERRACOTTA:
case BROWN_GLAZED_TERRACOTTA:
case BROWN_TERRACOTTA:
case CYAN_GLAZED_TERRACOTTA:
case CYAN_TERRACOTTA:
case GRAY_GLAZED_TERRACOTTA:
case GRAY_TERRACOTTA:
case GREEN_GLAZED_TERRACOTTA:
case GREEN_TERRACOTTA:
case LIGHT_BLUE_GLAZED_TERRACOTTA:
case LIGHT_BLUE_TERRACOTTA:
case LIGHT_GRAY_GLAZED_TERRACOTTA:
case LIGHT_GRAY_TERRACOTTA:
case LIME_GLAZED_TERRACOTTA:
case LIME_TERRACOTTA:
case MAGENTA_GLAZED_TERRACOTTA:
case MAGENTA_TERRACOTTA:
case ORANGE_GLAZED_TERRACOTTA:
case ORANGE_TERRACOTTA:
case PINK_GLAZED_TERRACOTTA:
case PINK_TERRACOTTA:
case PURPLE_GLAZED_TERRACOTTA:
case PURPLE_TERRACOTTA:
case RED_GLAZED_TERRACOTTA:
case RED_TERRACOTTA:
case WHITE_GLAZED_TERRACOTTA:
case WHITE_TERRACOTTA:
case YELLOW_GLAZED_TERRACOTTA:
case YELLOW_TERRACOTTA:
handleMiningDrops(blockState);
return;
case COAL_ORE:
case DIAMOND_ORE:
case EMERALD_ORE:
case GLOWSTONE:
case LAPIS_ORE:
case PACKED_ICE:
case NETHER_QUARTZ_ORE:
case REDSTONE_ORE:
case STONE:
case PRISMARINE:
Misc.dropItem(Misc.getBlockCenter(blockState), new ItemStack(blockState.getType()));
return;
default:
/*if (mcMMO.getModManager().isCustomMiningBlock(blockState)) {
Misc.dropItem(Misc.getBlockCenter(blockState), new ItemStack(blockState.getType()));
}*/
}
}
/**
* Handle double drops from Mining & Blast Mining.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
public void handleMiningDrops(BlockState blockState) {
switch (blockState.getType()) {
case COAL_ORE:
case DIAMOND_ORE:
case EMERALD_ORE:
case END_STONE:
case GLOWSTONE:
case GOLD_ORE:
case TERRACOTTA:
case IRON_ORE:
case LAPIS_ORE:
case MOSSY_COBBLESTONE:
case NETHERRACK:
case OBSIDIAN:
case PACKED_ICE:
case REDSTONE_ORE:
case SANDSTONE:
case BLACK_GLAZED_TERRACOTTA:
case BLACK_TERRACOTTA:
case BLUE_GLAZED_TERRACOTTA:
case BLUE_TERRACOTTA:
case BROWN_GLAZED_TERRACOTTA:
case BROWN_TERRACOTTA:
case CYAN_GLAZED_TERRACOTTA:
case CYAN_TERRACOTTA:
case GRAY_GLAZED_TERRACOTTA:
case GRAY_TERRACOTTA:
case GREEN_GLAZED_TERRACOTTA:
case GREEN_TERRACOTTA:
case LIGHT_BLUE_GLAZED_TERRACOTTA:
case LIGHT_BLUE_TERRACOTTA:
case LIGHT_GRAY_GLAZED_TERRACOTTA:
case LIGHT_GRAY_TERRACOTTA:
case LIME_GLAZED_TERRACOTTA:
case LIME_TERRACOTTA:
case MAGENTA_GLAZED_TERRACOTTA:
case MAGENTA_TERRACOTTA:
case ORANGE_GLAZED_TERRACOTTA:
case ORANGE_TERRACOTTA:
case PINK_GLAZED_TERRACOTTA:
case PINK_TERRACOTTA:
case PURPLE_GLAZED_TERRACOTTA:
case PURPLE_TERRACOTTA:
case RED_GLAZED_TERRACOTTA:
case RED_TERRACOTTA:
case WHITE_GLAZED_TERRACOTTA:
case WHITE_TERRACOTTA:
case YELLOW_GLAZED_TERRACOTTA:
case YELLOW_TERRACOTTA:
case STONE:
case NETHER_QUARTZ_ORE:
Misc.dropItems(Misc.getBlockCenter(blockState), blockState.getBlock().getDrops());
return;
default:
/*if (mcMMO.getModManager().isCustomMiningBlock(blockState)) {
Misc.dropItems(Misc.getBlockCenter(blockState), blockState.getBlock().getDrops());
}*/
}
}
/**
* Retrieve a list of Blast Mining detonator types
*
* @return blast mining detonator materials
*/
public List<Material> getDetonators() {
return detonators;
}
/**
* Check if an itemStack is a valid blast mining detonator
*
* @param itemStack target itemstack
* @return true if valid blast mining detonator
*/
public Boolean isDetonator(ItemStack itemStack) {
return getDetonators().contains(itemStack.getType());
} }
} }

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.datatypes.skills.behaviours; package com.gmail.nossr50.datatypes.skills.behaviours;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import org.bukkit.Material;
/** /**
* These behaviour classes are a band-aid fix for a larger problem * These behaviour classes are a band-aid fix for a larger problem
@ -13,7 +14,33 @@ public class SalvageBehaviour {
private final mcMMO pluginRef; private final mcMMO pluginRef;
private Material anvilMaterial;
private boolean arcaneSalvageDowngrades;
private boolean arcaneSalvageEnchantLoss;
public SalvageBehaviour(mcMMO pluginRef) { public SalvageBehaviour(mcMMO pluginRef) {
this.pluginRef = pluginRef; this.pluginRef = pluginRef;
anvilMaterial = pluginRef.getConfigManager().getConfigSalvage().getGeneral().getSalvageAnvilMaterial();
arcaneSalvageDowngrades = pluginRef.getConfigManager().getConfigSalvage().getConfigArcaneSalvage().isDowngradesEnabled();
arcaneSalvageEnchantLoss = pluginRef.getConfigManager().getConfigSalvage().getConfigArcaneSalvage().isMayLoseEnchants();
}
public int calculateSalvageableAmount(short currentDurability, short maxDurability, int baseAmount) {
double percentDamaged = (maxDurability <= 0) ? 1D : (double) (maxDurability - currentDurability) / maxDurability;
return (int) Math.floor(baseAmount * percentDamaged);
}
public Material getAnvilMaterial() {
return anvilMaterial;
}
public boolean isArcaneSalvageDowngrades() {
return arcaneSalvageDowngrades;
}
public boolean isArcaneSalvageEnchantLoss() {
return arcaneSalvageEnchantLoss;
} }
} }

View File

@ -1,76 +0,0 @@
package com.gmail.nossr50.skills.mining;
import com.gmail.nossr50.core.MetadataConstants;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.util.skills.RankUtils;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
public class BlastMining {
public final static int MAXIMUM_REMOTE_DETONATION_DISTANCE = 100;
public static double getBlastRadiusModifier(int rank) {
return pluginRef.getConfigManager().getConfigMining().getBlastMining().getRadius(rank);
}
public static double getBlastDamageDecrease(int rank) {
return pluginRef.getConfigManager().getConfigMining().getBlastMining().getDamageDecrease(rank);
}
public static int getDemolitionExpertUnlockLevel() {
for (int i = 0; i < SubSkillType.MINING_BLAST_MINING.getNumRanks() - 1; i++) {
if (getBlastDamageDecrease(i + 1) > 0)
return RankUtils.getRankUnlockLevel(SubSkillType.MINING_BLAST_MINING, i + 1);
}
return 0;
}
public static int getBiggerBombsUnlockLevel() {
for (int i = 0; i < SubSkillType.MINING_BLAST_MINING.getNumRanks() - 1; i++) {
if (getBlastRadiusModifier(i + 1) > 0)
return RankUtils.getRankUnlockLevel(SubSkillType.MINING_BLAST_MINING, i + 1);
}
return 0;
}
public static boolean processBlastMiningExplosion(EntityDamageByEntityEvent event, TNTPrimed tnt, Player defender) {
if (!tnt.hasMetadata(MetadataConstants.TNT_TRACKING_METAKEY) || !pluginRef.getUserManager().hasPlayerDataKey(defender)) {
return false;
}
// We can make this assumption because we (should) be the only ones using this exact metadata
Player player = pluginRef.getServer().getPlayerExact(tnt.getMetadata(MetadataConstants.TNT_TRACKING_METAKEY).get(0).asString());
if (!player.equals(defender)) {
return false;
}
if (pluginRef.getUserManager().getPlayer(defender) == null) {
return false;
}
MiningManager miningManager = pluginRef.getUserManager().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;
}
}

View File

@ -1,198 +0,0 @@
package com.gmail.nossr50.skills.mining;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public class Mining {
private static Mining instance;
private List<Material> detonators;
public Mining() {
//Init detonators
this.detonators = ItemUtils.matchMaterials(pluginRef.getConfigManager().getConfigMining().getDetonators());
}
public static Mining getInstance() {
if (instance == null)
instance = new Mining();
return instance;
}
/**
* Calculate XP gain for Mining.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
public static int getBlockXp(BlockState blockState) {
int xp = pluginRef.getDynamicSettingsManager().getExperienceManager().getMiningXp(blockState.getType());
return xp;
}
/**
* Handle double drops when using Silk Touch.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
protected static void handleSilkTouchDrops(BlockState blockState) {
Material blockType = blockState.getType();
switch (blockType) {
case ANDESITE:
case DIORITE:
case GRANITE:
case END_STONE:
case TERRACOTTA:
case CLAY:
case IRON_ORE:
case MOSSY_COBBLESTONE:
case NETHERRACK:
case OBSIDIAN:
case SANDSTONE:
case BLACK_GLAZED_TERRACOTTA:
case BLACK_TERRACOTTA:
case BLUE_GLAZED_TERRACOTTA:
case BLUE_TERRACOTTA:
case BROWN_GLAZED_TERRACOTTA:
case BROWN_TERRACOTTA:
case CYAN_GLAZED_TERRACOTTA:
case CYAN_TERRACOTTA:
case GRAY_GLAZED_TERRACOTTA:
case GRAY_TERRACOTTA:
case GREEN_GLAZED_TERRACOTTA:
case GREEN_TERRACOTTA:
case LIGHT_BLUE_GLAZED_TERRACOTTA:
case LIGHT_BLUE_TERRACOTTA:
case LIGHT_GRAY_GLAZED_TERRACOTTA:
case LIGHT_GRAY_TERRACOTTA:
case LIME_GLAZED_TERRACOTTA:
case LIME_TERRACOTTA:
case MAGENTA_GLAZED_TERRACOTTA:
case MAGENTA_TERRACOTTA:
case ORANGE_GLAZED_TERRACOTTA:
case ORANGE_TERRACOTTA:
case PINK_GLAZED_TERRACOTTA:
case PINK_TERRACOTTA:
case PURPLE_GLAZED_TERRACOTTA:
case PURPLE_TERRACOTTA:
case RED_GLAZED_TERRACOTTA:
case RED_TERRACOTTA:
case WHITE_GLAZED_TERRACOTTA:
case WHITE_TERRACOTTA:
case YELLOW_GLAZED_TERRACOTTA:
case YELLOW_TERRACOTTA:
handleMiningDrops(blockState);
return;
case COAL_ORE:
case DIAMOND_ORE:
case EMERALD_ORE:
case GLOWSTONE:
case LAPIS_ORE:
case PACKED_ICE:
case NETHER_QUARTZ_ORE:
case REDSTONE_ORE:
case STONE:
case PRISMARINE:
Misc.dropItem(Misc.getBlockCenter(blockState), new ItemStack(blockState.getType()));
return;
default:
/*if (mcMMO.getModManager().isCustomMiningBlock(blockState)) {
Misc.dropItem(Misc.getBlockCenter(blockState), new ItemStack(blockState.getType()));
}*/
}
}
/**
* Handle double drops from Mining & Blast Mining.
*
* @param blockState The {@link BlockState} to check ability activation for
*/
protected static void handleMiningDrops(BlockState blockState) {
switch (blockState.getType()) {
case COAL_ORE:
case DIAMOND_ORE:
case EMERALD_ORE:
case END_STONE:
case GLOWSTONE:
case GOLD_ORE:
case TERRACOTTA:
case IRON_ORE:
case LAPIS_ORE:
case MOSSY_COBBLESTONE:
case NETHERRACK:
case OBSIDIAN:
case PACKED_ICE:
case REDSTONE_ORE:
case SANDSTONE:
case BLACK_GLAZED_TERRACOTTA:
case BLACK_TERRACOTTA:
case BLUE_GLAZED_TERRACOTTA:
case BLUE_TERRACOTTA:
case BROWN_GLAZED_TERRACOTTA:
case BROWN_TERRACOTTA:
case CYAN_GLAZED_TERRACOTTA:
case CYAN_TERRACOTTA:
case GRAY_GLAZED_TERRACOTTA:
case GRAY_TERRACOTTA:
case GREEN_GLAZED_TERRACOTTA:
case GREEN_TERRACOTTA:
case LIGHT_BLUE_GLAZED_TERRACOTTA:
case LIGHT_BLUE_TERRACOTTA:
case LIGHT_GRAY_GLAZED_TERRACOTTA:
case LIGHT_GRAY_TERRACOTTA:
case LIME_GLAZED_TERRACOTTA:
case LIME_TERRACOTTA:
case MAGENTA_GLAZED_TERRACOTTA:
case MAGENTA_TERRACOTTA:
case ORANGE_GLAZED_TERRACOTTA:
case ORANGE_TERRACOTTA:
case PINK_GLAZED_TERRACOTTA:
case PINK_TERRACOTTA:
case PURPLE_GLAZED_TERRACOTTA:
case PURPLE_TERRACOTTA:
case RED_GLAZED_TERRACOTTA:
case RED_TERRACOTTA:
case WHITE_GLAZED_TERRACOTTA:
case WHITE_TERRACOTTA:
case YELLOW_GLAZED_TERRACOTTA:
case YELLOW_TERRACOTTA:
case STONE:
case NETHER_QUARTZ_ORE:
Misc.dropItems(Misc.getBlockCenter(blockState), blockState.getBlock().getDrops());
return;
default:
/*if (mcMMO.getModManager().isCustomMiningBlock(blockState)) {
Misc.dropItems(Misc.getBlockCenter(blockState), blockState.getBlock().getDrops());
}*/
}
}
/**
* Retrieve a list of Blast Mining detonator types
*
* @return blast mining detonator materials
*/
public List<Material> getDetonators() {
return detonators;
}
/**
* Check if an itemStack is a valid blast mining detonator
*
* @param itemStack target itemstack
* @return true if valid blast mining detonator
*/
public Boolean isDetonator(ItemStack itemStack) {
return getDetonators().contains(itemStack.getType());
}
}

View File

@ -7,6 +7,7 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.datatypes.skills.behaviours.MiningBehaviour;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.skills.AbilityCooldownTask; import com.gmail.nossr50.runnables.skills.AbilityCooldownTask;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
@ -28,19 +29,25 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MiningManager extends SkillManager { public class MiningManager extends SkillManager {
private final MiningBehaviour miningBehaviour;
public MiningManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) { public MiningManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) {
super(pluginRef, mcMMOPlayer, PrimarySkillType.MINING); super(pluginRef, mcMMOPlayer, PrimarySkillType.MINING);
//Init behaviour
miningBehaviour = pluginRef.getDynamicSettingsManager().getSkillBehaviourManager().getMiningBehaviour();
} }
public static double getOreBonus(int rank) { public double getOreBonus(int rank) {
return pluginRef.getConfigManager().getConfigMining().getBlastMining().getOreBonus(rank); return pluginRef.getConfigManager().getConfigMining().getBlastMining().getOreBonus(rank);
} }
public static double getDebrisReduction(int rank) { public double getDebrisReduction(int rank) {
return pluginRef.getConfigManager().getConfigMining().getBlastMining().getDebrisReduction(rank); return pluginRef.getConfigManager().getConfigMining().getBlastMining().getDebrisReduction(rank);
} }
public static int getDropMultiplier(int rank) { public int getDropMultiplier(int rank) {
return pluginRef.getConfigManager().getConfigMining().getBlastMining().getDropMultiplier(rank); return pluginRef.getConfigManager().getConfigMining().getBlastMining().getDropMultiplier(rank);
} }
@ -48,14 +55,14 @@ public class MiningManager extends SkillManager {
if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_DEMOLITIONS_EXPERTISE)) if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_DEMOLITIONS_EXPERTISE))
return false; return false;
return getSkillLevel() >= BlastMining.getDemolitionExpertUnlockLevel() && Permissions.demolitionsExpertise(getPlayer()); return getSkillLevel() >= miningBehaviour.getDemolitionExpertUnlockLevel() && Permissions.demolitionsExpertise(getPlayer());
} }
public boolean canDetonate() { public boolean canDetonate() {
Player player = getPlayer(); Player player = getPlayer();
return canUseBlastMining() && player.isSneaking() return canUseBlastMining() && player.isSneaking()
&& Mining.getInstance().isDetonator(player.getInventory().getItemInMainHand()) && miningBehaviour.isDetonator(player.getInventory().getItemInMainHand())
&& Permissions.remoteDetonation(player); && Permissions.remoteDetonation(player);
} }
@ -68,7 +75,7 @@ public class MiningManager extends SkillManager {
if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_BIGGER_BOMBS)) if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.MINING_BIGGER_BOMBS))
return false; return false;
return getSkillLevel() >= BlastMining.getBiggerBombsUnlockLevel() && Permissions.biggerBombs(getPlayer()); return getSkillLevel() >= miningBehaviour.getBiggerBombsUnlockLevel() && Permissions.biggerBombs(getPlayer());
} }
public boolean canDoubleDrop() { public boolean canDoubleDrop() {
@ -76,14 +83,14 @@ public class MiningManager extends SkillManager {
} }
/** /**
* Process double drops & XP gain for Mining. * Process double drops & XP gain for miningBehaviour.
* *
* @param blockState The {@link BlockState} to check ability activation for * @param blockState The {@link BlockState} to check ability activation for
*/ */
public void miningBlockCheck(BlockState blockState) { public void miningBlockCheck(BlockState blockState) {
Player player = getPlayer(); Player player = getPlayer();
applyXpGain(Mining.getBlockXp(blockState), XPGainReason.PVE); applyXpGain(miningBehaviour.getBlockXp(blockState), XPGainReason.PVE);
if (mcMMOPlayer.getAbilityMode(skill.getSuperAbility())) { if (mcMMOPlayer.getAbilityMode(skill.getSuperAbility())) {
SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), pluginRef.getConfigManager().getConfigSuperAbilities().getSuperAbilityLimits().getToolDurabilityDamage()); SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), pluginRef.getConfigManager().getConfigSuperAbilities().getSuperAbilityLimits().getToolDurabilityDamage());
@ -108,7 +115,7 @@ public class MiningManager extends SkillManager {
*/ */
public void remoteDetonation() { public void remoteDetonation() {
Player player = getPlayer(); Player player = getPlayer();
Block targetBlock = player.getTargetBlock(BlockUtils.getTransparentBlocks(), BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE); Block targetBlock = player.getTargetBlock(BlockUtils.getTransparentBlocks(), miningBehaviour.MAXIMUM_REMOTE_DETONATION_DISTANCE);
//Blast mining cooldown check needs to be first so the player can be messaged //Blast mining cooldown check needs to be first so the player can be messaged
if (!blastMiningCooldownOver() || targetBlock.getType() != Material.TNT || !pluginRef.getEventManager().simulateBlockBreak(targetBlock, player, true)) { if (!blastMiningCooldownOver() || targetBlock.getType() != Material.TNT || !pluginRef.getEventManager().simulateBlockBreak(targetBlock, player, true)) {
@ -117,9 +124,9 @@ public class MiningManager extends SkillManager {
TNTPrimed tnt = player.getWorld().spawn(targetBlock.getLocation(), TNTPrimed.class); TNTPrimed tnt = player.getWorld().spawn(targetBlock.getLocation(), TNTPrimed.class);
//SkillUtils.sendSkillMessage(player, SuperAbilityType.BLAST_MINING.getAbilityPlayer(player)); //SkillUtils.sendSkillMessage(player, SuperAbilityType.BLAST_miningBehaviour.getAbilityPlayer(player));
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUPER_ABILITY, "Mining.Blast.Boom"); pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUPER_ABILITY, "miningBehaviour.Blast.Boom");
//player.sendMessage(pluginRef.getLocaleManager().getString("Mining.Blast.Boom")); //player.sendMessage(pluginRef.getLocaleManager().getString("miningBehaviour.Blast.Boom"));
tnt.setMetadata(MetadataConstants.TNT_TRACKING_METAKEY, mcMMOPlayer.getPlayerMetadata()); tnt.setMetadata(MetadataConstants.TNT_TRACKING_METAKEY, mcMMOPlayer.getPlayerMetadata());
tnt.setFuseTicks(0); tnt.setFuseTicks(0);
@ -127,7 +134,7 @@ public class MiningManager extends SkillManager {
mcMMOPlayer.setAbilityDATS(SuperAbilityType.BLAST_MINING, System.currentTimeMillis()); mcMMOPlayer.setAbilityDATS(SuperAbilityType.BLAST_MINING, System.currentTimeMillis());
mcMMOPlayer.setAbilityInformed(SuperAbilityType.BLAST_MINING, false); mcMMOPlayer.setAbilityInformed(SuperAbilityType.BLAST_MINING, false);
new AbilityCooldownTask(mcMMOPlayer, SuperAbilityType.BLAST_MINING).runTaskLater(pluginRef, SuperAbilityType.BLAST_MINING.getCooldown() * Misc.TICK_CONVERSION_FACTOR); new AbilityCooldownTask(pluginRef, mcMMOPlayer, SuperAbilityType.BLAST_MINING).runTaskLater(pluginRef, SuperAbilityType.BLAST_MINING.getCooldown() * Misc.TICK_CONVERSION_FACTOR);
} }
/** /**
@ -160,14 +167,14 @@ public class MiningManager extends SkillManager {
for (BlockState blockState : ores) { for (BlockState blockState : ores) {
if (Misc.getRandom().nextFloat() < (yield + oreBonus)) { if (Misc.getRandom().nextFloat() < (yield + oreBonus)) {
if (!pluginRef.getPlaceStore().isTrue(blockState)) { if (!pluginRef.getPlaceStore().isTrue(blockState)) {
xp += Mining.getBlockXp(blockState); xp += miningBehaviour.getBlockXp(blockState);
} }
Misc.dropItem(Misc.getBlockCenter(blockState), new ItemStack(blockState.getType())); // Initial block that would have been dropped Misc.dropItem(Misc.getBlockCenter(blockState), new ItemStack(blockState.getType())); // Initial block that would have been dropped
if (!pluginRef.getPlaceStore().isTrue(blockState)) { if (!pluginRef.getPlaceStore().isTrue(blockState)) {
for (int i = 1; i < dropMultiplier; i++) { for (int i = 1; i < dropMultiplier; i++) {
Mining.handleSilkTouchDrops(blockState); // Bonus drops - should drop the block & not the items miningBehaviour.handleSilkTouchDrops(blockState); // Bonus drops - should drop the block & not the items
} }
} }
} }
@ -240,7 +247,7 @@ public class MiningManager extends SkillManager {
* @return the Blast Mining tier * @return the Blast Mining tier
*/ */
public double getBlastRadiusModifier() { public double getBlastRadiusModifier() {
return BlastMining.getBlastRadiusModifier(getBlastMiningTier()); return miningBehaviour.getBlastRadiusModifier(getBlastMiningTier());
} }
/** /**
@ -249,7 +256,7 @@ public class MiningManager extends SkillManager {
* @return the Blast Mining tier * @return the Blast Mining tier
*/ */
public double getBlastDamageModifier() { public double getBlastDamageModifier() {
return BlastMining.getBlastDamageDecrease(getBlastMiningTier()); return miningBehaviour.getBlastDamageDecrease(getBlastMiningTier());
} }
private boolean blastMiningCooldownOver() { private boolean blastMiningCooldownOver() {

View File

@ -1,23 +0,0 @@
package com.gmail.nossr50.skills.repair;
import org.bukkit.Material;
public class Repair {
private static Repair instance;
private Material anvilMaterial;
public Repair() {
anvilMaterial = pluginRef.getConfigManager().getConfigRepair().getRepairGeneral().getRepairAnvilMaterial();
}
public static Repair getInstance() {
if (instance == null)
instance = new Repair();
return instance;
}
public Material getAnvilMaterial() {
return anvilMaterial;
}
}

View File

@ -1,22 +0,0 @@
package com.gmail.nossr50.skills.salvage;
import org.bukkit.Material;
public class Salvage {
public static Material anvilMaterial;
public static boolean arcaneSalvageDowngrades;
public static boolean arcaneSalvageEnchantLoss;
public Salvage() {
anvilMaterial = pluginRef.getConfigManager().getConfigSalvage().getGeneral().getSalvageAnvilMaterial();
arcaneSalvageDowngrades = pluginRef.getConfigManager().getConfigSalvage().getConfigArcaneSalvage().isDowngradesEnabled();
arcaneSalvageEnchantLoss = pluginRef.getConfigManager().getConfigSalvage().getConfigArcaneSalvage().isMayLoseEnchants();
}
protected static int calculateSalvageableAmount(short currentDurability, short maxDurability, int baseAmount) {
double percentDamaged = (maxDurability <= 0) ? 1D : (double) (maxDurability - currentDurability) / maxDurability;
return (int) Math.floor(baseAmount * percentDamaged);
}
}

View File

@ -4,6 +4,7 @@ import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.behaviours.SalvageBehaviour;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable; import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
@ -29,9 +30,11 @@ import java.util.Map.Entry;
public class SalvageManager extends SkillManager { public class SalvageManager extends SkillManager {
private boolean placedAnvil; private boolean placedAnvil;
private int lastClick; private int lastClick;
private SalvageBehaviour salvageBehaviour;
public SalvageManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) { public SalvageManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) {
super(pluginRef, mcMMOPlayer, PrimarySkillType.SALVAGE); super(pluginRef, mcMMOPlayer, PrimarySkillType.SALVAGE);
this.salvageBehaviour = pluginRef.getDynamicSettingsManager().getSkillBehaviourManager().getSalvageBehaviour();
} }
/** /**
@ -85,7 +88,7 @@ public class SalvageManager extends SkillManager {
return; return;
} }
int potentialSalvageYield = Salvage.calculateSalvageableAmount(item.getDurability(), salvageable.getMaximumDurability(), salvageable.getMaximumQuantity()); int potentialSalvageYield = salvageBehaviour.calculateSalvageableAmount(item.getDurability(), salvageable.getMaximumDurability(), salvageable.getMaximumQuantity());
if (potentialSalvageYield <= 0) { if (potentialSalvageYield <= 0) {
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Salvage.Skills.TooDamaged"); pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Salvage.Skills.TooDamaged");
@ -237,14 +240,14 @@ public class SalvageManager extends SkillManager {
} }
} }
if (!Salvage.arcaneSalvageEnchantLoss if (!salvageBehaviour.isArcaneSalvageEnchantLoss()
|| Permissions.hasSalvageEnchantBypassPerk(player) || Permissions.hasSalvageEnchantBypassPerk(player)
|| RandomChanceUtil.checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(getExtractFullEnchantChance(), getPlayer(), SubSkillType.SALVAGE_ARCANE_SALVAGE))) { || RandomChanceUtil.checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(getExtractFullEnchantChance(), getPlayer(), SubSkillType.SALVAGE_ARCANE_SALVAGE))) {
enchantMeta.addStoredEnchant(enchant.getKey(), enchantLevel, true); enchantMeta.addStoredEnchant(enchant.getKey(), enchantLevel, true);
} }
else if (enchantLevel > 1 else if (enchantLevel > 1
&& Salvage.arcaneSalvageDowngrades && salvageBehaviour.isArcaneSalvageDowngrades()
&& RandomChanceUtil.checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(getExtractPartialEnchantChance(), getPlayer(), SubSkillType.SALVAGE_ARCANE_SALVAGE))) { && RandomChanceUtil.checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(getExtractPartialEnchantChance(), getPlayer(), SubSkillType.SALVAGE_ARCANE_SALVAGE))) {
enchantMeta.addStoredEnchant(enchant.getKey(), enchantLevel - 1, true); enchantMeta.addStoredEnchant(enchant.getKey(), enchantLevel - 1, true);
downgraded = true; downgraded = true;

View File

@ -1,9 +0,0 @@
package com.gmail.nossr50.skills.smelting;
import org.bukkit.inventory.ItemStack;
public class Smelting {
protected static int getResourceXp(ItemStack smelting) {
return pluginRef.getDynamicSettingsManager().getExperienceManager().getFurnaceItemXP(smelting.getType());
}
}

View File

@ -20,71 +20,11 @@ public class SmeltingManager extends SkillManager {
super(pluginRef, mcMMOPlayer, PrimarySkillType.SMELTING); super(pluginRef, mcMMOPlayer, PrimarySkillType.SMELTING);
} }
/*public boolean canUseFluxMining(BlockState blockState) {
return getSkillLevel() >= Smelting.fluxMiningUnlockLevel
&& BlockUtils.affectedByFluxMining(blockState)
&& Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.SMELTING_FLUX_MINING)
&& !mcMMO.getPlaceStore().isTrue(blockState);
}*/
public boolean isSecondSmeltSuccessful() { public boolean isSecondSmeltSuccessful() {
return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.SMELTING_SECOND_SMELT) return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.SMELTING_SECOND_SMELT)
&& RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.SMELTING_SECOND_SMELT, getPlayer()); && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.SMELTING_SECOND_SMELT, getPlayer());
} }
/**
* Process the Flux Mining ability.
*
* @param blockState The {@link BlockState} to check ability activation for
* @return true if the ability was successful, false otherwise
*/
/*public boolean processFluxMining(BlockState blockState) {
Player player = getPlayer();
if (RandomChanceUtil.checkRandomChanceExecutionSuccess(getPlayer(), SubSkillType.SMELTING_FLUX_MINING, true)) {
ItemStack item = null;
switch (blockState.getType()) {
case IRON_ORE:
item = new ItemStack(Material.IRON_INGOT);
break;
case GOLD_ORE:
item = new ItemStack(Material.GOLD_INGOT);
break;
default:
break;
}
if (item == null) {
return false;
}
if (!EventUtils.simulateBlockBreak(blockState.getBlock(), player, true)) {
return false;
}
// We need to distribute Mining XP here, because the block break event gets cancelled
applyXpGain(Mining.getBlockXp(blockState), XPGainReason.PVE, XPGainSource.PASSIVE);
SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), MainConfig.getInstance().getAbilityToolDamage());
Misc.dropItems(Misc.getBlockCenter(blockState), item, isSecondSmeltSuccessful() ? 2 : 1);
blockState.setType(Material.AIR);
if (MainConfig.getInstance().getFluxPickaxeSoundEnabled()) {
SoundManager.sendSound(player, blockState.getLocation(), SoundType.FIZZ);
}
ParticleEffectUtils.playFluxEffect(blockState.getLocation());
return true;
}
return false;
}*/
/** /**
* Increases burn time for furnace fuel. * Increases burn time for furnace fuel.
* *
@ -108,7 +48,7 @@ public class SmeltingManager extends SkillManager {
} }
public ItemStack smeltProcessing(ItemStack smelting, ItemStack result) { public ItemStack smeltProcessing(ItemStack smelting, ItemStack result) {
applyXpGain(Smelting.getResourceXp(smelting), XPGainReason.PVE, XPGainSource.PASSIVE); applyXpGain(getResourceXp(smelting), XPGainReason.PVE, XPGainSource.PASSIVE);
if (isSecondSmeltSuccessful()) { if (isSecondSmeltSuccessful()) {
ItemStack newResult = result.clone(); ItemStack newResult = result.clone();
@ -120,6 +60,10 @@ public class SmeltingManager extends SkillManager {
return result; return result;
} }
public int getResourceXp(ItemStack smelting) {
return pluginRef.getDynamicSettingsManager().getExperienceManager().getFurnaceItemXP(smelting.getType());
}
public int vanillaXPBoost(int experience) { public int vanillaXPBoost(int experience) {
return experience * getVanillaXpMultiplier(); return experience * getVanillaXpMultiplier();
} }

View File

@ -1,11 +0,0 @@
/*
package com.gmail.nossr50.skills.swords;
public class Swords {
public static int bleedMaxTicks = AdvancedConfig.getInstance().getRuptureMaxTicks();
public static double counterAttackModifier = AdvancedConfig.getInstance().getCounterAttackModifier();
public static double serratedStrikesModifier = AdvancedConfig.getInstance().getSerratedStrikesModifier();
}
*/