mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Hire an Excavation manager.
This commit is contained in:
parent
4392e6b9ab
commit
f388948f04
@ -29,7 +29,8 @@ import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
|||||||
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
||||||
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
||||||
import com.gmail.nossr50.runnables.StickyPistonTracker;
|
import com.gmail.nossr50.runnables.StickyPistonTracker;
|
||||||
import com.gmail.nossr50.skills.excavation.Excavation;
|
import com.gmail.nossr50.skills.SkillManagerStore;
|
||||||
|
import com.gmail.nossr50.skills.excavation.ExcavationManager;
|
||||||
import com.gmail.nossr50.skills.herbalism.Herbalism;
|
import com.gmail.nossr50.skills.herbalism.Herbalism;
|
||||||
import com.gmail.nossr50.skills.mining.Mining;
|
import com.gmail.nossr50.skills.mining.Mining;
|
||||||
import com.gmail.nossr50.skills.repair.Repair;
|
import com.gmail.nossr50.skills.repair.Repair;
|
||||||
@ -202,10 +203,11 @@ public class BlockListener implements Listener {
|
|||||||
|
|
||||||
/* EXCAVATION */
|
/* EXCAVATION */
|
||||||
else if (BlockChecks.affectedByGigaDrillBreaker(blockState) && ItemChecks.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(blockState)) {
|
else if (BlockChecks.affectedByGigaDrillBreaker(blockState) && ItemChecks.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(blockState)) {
|
||||||
Excavation.excavationBlockCheck(blockState, player);
|
ExcavationManager excavationManager = SkillManagerStore.getInstance().getExcavationManager(player.getName());
|
||||||
|
excavationManager.excavationBlockCheck(blockState);
|
||||||
|
|
||||||
if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
|
if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
|
||||||
Excavation.gigaDrillBreaker(blockState, player);
|
excavationManager.gigaDrillBreaker(blockState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
|||||||
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
|
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
|
||||||
import com.gmail.nossr50.skills.archery.ArcheryManager;
|
import com.gmail.nossr50.skills.archery.ArcheryManager;
|
||||||
import com.gmail.nossr50.skills.axes.AxeManager;
|
import com.gmail.nossr50.skills.axes.AxeManager;
|
||||||
|
import com.gmail.nossr50.skills.excavation.ExcavationManager;
|
||||||
import com.gmail.nossr50.skills.mining.MiningManager;
|
import com.gmail.nossr50.skills.mining.MiningManager;
|
||||||
import com.gmail.nossr50.skills.smelting.SmeltingManager;
|
import com.gmail.nossr50.skills.smelting.SmeltingManager;
|
||||||
import com.gmail.nossr50.skills.swords.SwordsManager;
|
import com.gmail.nossr50.skills.swords.SwordsManager;
|
||||||
@ -18,6 +19,7 @@ public class SkillManagerStore {
|
|||||||
private HashMap<String, AcrobaticsManager> acrobaticsManagers = new HashMap<String, AcrobaticsManager>();
|
private HashMap<String, AcrobaticsManager> acrobaticsManagers = new HashMap<String, AcrobaticsManager>();
|
||||||
private HashMap<String, ArcheryManager> archeryManagers = new HashMap<String, ArcheryManager>();
|
private HashMap<String, ArcheryManager> archeryManagers = new HashMap<String, ArcheryManager>();
|
||||||
private HashMap<String, AxeManager> axeManagers = new HashMap<String, AxeManager>();
|
private HashMap<String, AxeManager> axeManagers = new HashMap<String, AxeManager>();
|
||||||
|
private HashMap<String, ExcavationManager> excavationManagers = new HashMap<String, ExcavationManager>();
|
||||||
private HashMap<String, MiningManager> miningManagers = new HashMap<String, MiningManager>();
|
private HashMap<String, MiningManager> miningManagers = new HashMap<String, MiningManager>();
|
||||||
private HashMap<String, SmeltingManager> smeltingManagers = new HashMap<String, SmeltingManager>();
|
private HashMap<String, SmeltingManager> smeltingManagers = new HashMap<String, SmeltingManager>();
|
||||||
private HashMap<String, SwordsManager> swordsManagers = new HashMap<String, SwordsManager>();
|
private HashMap<String, SwordsManager> swordsManagers = new HashMap<String, SwordsManager>();
|
||||||
@ -56,6 +58,14 @@ public class SkillManagerStore {
|
|||||||
return axeManagers.get(playerName);
|
return axeManagers.get(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExcavationManager getExcavationManager(String playerName) {
|
||||||
|
if (!excavationManagers.containsKey(playerName)) {
|
||||||
|
excavationManagers.put(playerName, new ExcavationManager(Users.getPlayer(playerName)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return excavationManagers.get(playerName);
|
||||||
|
}
|
||||||
|
|
||||||
public MiningManager getMiningManager(String playerName) {
|
public MiningManager getMiningManager(String playerName) {
|
||||||
if (!miningManagers.containsKey(playerName)) {
|
if (!miningManagers.containsKey(playerName)) {
|
||||||
miningManagers.put(playerName, new MiningManager(Users.getPlayer(playerName)));
|
miningManagers.put(playerName, new MiningManager(Users.getPlayer(playerName)));
|
||||||
|
@ -3,75 +3,23 @@ package com.gmail.nossr50.skills.excavation;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.config.TreasuresConfig;
|
import com.gmail.nossr50.config.TreasuresConfig;
|
||||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
|
||||||
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
|
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
|
||||||
import com.gmail.nossr50.mods.ModChecks;
|
import com.gmail.nossr50.mods.ModChecks;
|
||||||
import com.gmail.nossr50.skills.utilities.PerksUtils;
|
|
||||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||||
import com.gmail.nossr50.util.Misc;
|
|
||||||
import com.gmail.nossr50.util.Permissions;
|
|
||||||
import com.gmail.nossr50.util.Users;
|
|
||||||
|
|
||||||
public class Excavation {
|
public class Excavation {
|
||||||
|
|
||||||
/**
|
|
||||||
* Process treasure drops & XP gain for Excavation.
|
|
||||||
*
|
|
||||||
* @param blockState The {@link BlockState} to check ability activation for
|
|
||||||
* @param player The {@link Player} using this ability
|
|
||||||
*/
|
|
||||||
public static void excavationBlockCheck(BlockState blockState, Player player) {
|
|
||||||
McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
|
|
||||||
int xp = Config.getInstance().getXp(SkillType.EXCAVATION, blockState.getType());
|
|
||||||
|
|
||||||
if (xp == 0 && ModChecks.isCustomExcavationBlock(blockState)) {
|
|
||||||
xp = ModChecks.getCustomBlock(blockState).getXpGain();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Permissions.excavationTreasureHunter(player)) {
|
|
||||||
List<ExcavationTreasure> treasures = getTreasures(blockState);
|
|
||||||
|
|
||||||
if (!treasures.isEmpty()) {
|
|
||||||
int skillLevel = mcMMOPlayer.getProfile().getSkillLevel(SkillType.EXCAVATION);
|
|
||||||
int activationChance = PerksUtils.handleLuckyPerks(player, SkillType.EXCAVATION);
|
|
||||||
Location location = blockState.getLocation();
|
|
||||||
|
|
||||||
for (ExcavationTreasure treasure : treasures) {
|
|
||||||
if (skillLevel >= treasure.getDropLevel() && Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) {
|
|
||||||
xp += treasure.getXp();
|
|
||||||
Misc.dropItem(location, treasure.getDrop());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mcMMOPlayer.beginXpGain(SkillType.EXCAVATION, xp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process the Giga Drill Breaker ability.
|
|
||||||
*
|
|
||||||
* @param blockState The {@link BlockState} to check ability activation for
|
|
||||||
* @param player The {@link Player} using this ability
|
|
||||||
*/
|
|
||||||
public static void gigaDrillBreaker(BlockState blockState, Player player) {
|
|
||||||
Excavation.excavationBlockCheck(blockState, player);
|
|
||||||
Excavation.excavationBlockCheck(blockState, player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of possible {@link ExcavationTreasure|ExcavationTreasures} obtained from a given block.
|
* Get the list of possible {@link ExcavationTreasure|ExcavationTreasures} obtained from a given block.
|
||||||
*
|
*
|
||||||
* @param blockState The {@link BlockState} of the block to check.
|
* @param blockState The {@link BlockState} of the block to check.
|
||||||
* @return the list of treasures that could be found
|
* @return the list of treasures that could be found
|
||||||
*/
|
*/
|
||||||
private static List<ExcavationTreasure> getTreasures(BlockState blockState) {
|
protected static List<ExcavationTreasure> getTreasures(BlockState blockState) {
|
||||||
switch (blockState.getType()) {
|
switch (blockState.getType()) {
|
||||||
case DIRT:
|
case DIRT:
|
||||||
return TreasuresConfig.getInstance().excavationFromDirt;
|
return TreasuresConfig.getInstance().excavationFromDirt;
|
||||||
@ -98,4 +46,14 @@ public class Excavation {
|
|||||||
return new ArrayList<ExcavationTreasure>();
|
return new ArrayList<ExcavationTreasure>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static int getBlockXP(BlockState blockState) {
|
||||||
|
int xp = Config.getInstance().getXp(SkillType.EXCAVATION, blockState.getType());
|
||||||
|
|
||||||
|
if (xp == 0 && ModChecks.isCustomExcavationBlock(blockState)) {
|
||||||
|
xp = ModChecks.getCustomBlock(blockState).getXpGain();
|
||||||
|
}
|
||||||
|
|
||||||
|
return xp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.gmail.nossr50.skills.excavation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||||
|
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
|
||||||
|
import com.gmail.nossr50.skills.SkillManager;
|
||||||
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||||
|
import com.gmail.nossr50.util.Misc;
|
||||||
|
import com.gmail.nossr50.util.Permissions;
|
||||||
|
|
||||||
|
public class ExcavationManager extends SkillManager {
|
||||||
|
public ExcavationManager(McMMOPlayer mcMMOPlayer) {
|
||||||
|
super(mcMMOPlayer, SkillType.EXCAVATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process treasure drops & XP gain for Excavation.
|
||||||
|
*
|
||||||
|
* @param blockState The {@link BlockState} to check ability activation for
|
||||||
|
* @param player The {@link Player} using this ability
|
||||||
|
*/
|
||||||
|
public void excavationBlockCheck(BlockState blockState) {
|
||||||
|
int xp = Excavation.getBlockXP(blockState);
|
||||||
|
|
||||||
|
if (Permissions.excavationTreasureHunter(getPlayer())) {
|
||||||
|
List<ExcavationTreasure> treasures = Excavation.getTreasures(blockState);
|
||||||
|
|
||||||
|
if (!treasures.isEmpty()) {
|
||||||
|
int skillLevel = getSkillLevel();
|
||||||
|
Location location = blockState.getLocation();
|
||||||
|
|
||||||
|
for (ExcavationTreasure treasure : treasures) {
|
||||||
|
if (skillLevel >= treasure.getDropLevel() && Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) {
|
||||||
|
xp += treasure.getXp();
|
||||||
|
Misc.dropItem(location, treasure.getDrop());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
applyXpGain(xp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the Giga Drill Breaker ability.
|
||||||
|
*
|
||||||
|
* @param blockState The {@link BlockState} to check ability activation for
|
||||||
|
* @param player The {@link Player} using this ability
|
||||||
|
*/
|
||||||
|
public void gigaDrillBreaker(BlockState blockState) {
|
||||||
|
excavationBlockCheck(blockState);
|
||||||
|
excavationBlockCheck(blockState);
|
||||||
|
}
|
||||||
|
}
|
@ -97,12 +97,7 @@ public final class CombatTools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ItemChecks.isAxe(heldItem)) {
|
else if (ItemChecks.isAxe(heldItem)) {
|
||||||
if (targetIsPlayer || targetIsTamedPet) {
|
if (((targetIsPlayer || targetIsTamedPet) && !SkillType.AXES.getPVPEnabled()) || (!targetIsPlayer && !targetIsTamedPet && !SkillType.AXES.getPVEEnabled())) {
|
||||||
if (!SkillType.AXES.getPVPEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!SkillType.AXES.getPVEEnabled()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user