Refactoring experience manager

This commit is contained in:
nossr50 2019-05-13 03:39:24 -07:00
parent d8841c6ae7
commit 3f6a33dea6
14 changed files with 71 additions and 54 deletions

View File

@ -195,7 +195,7 @@ public final class ExperienceAPI {
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addMultipliedXP(Player player, String skillType, int XP, String xpGainReason) {
getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * mcMMO.getDynamicSettingsManager().getExperienceMapManager().getGlobalXpMult()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * mcMMO.getDynamicSettingsManager().getExperienceManager().getGlobalXpMult()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
}
/**
@ -211,7 +211,7 @@ public final class ExperienceAPI {
*/
@Deprecated
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
addOfflineXP(playerName, getSkillType(skillType), (int) (XP * mcMMO.getDynamicSettingsManager().getExperienceMapManager().getGlobalXpMult()));
addOfflineXP(playerName, getSkillType(skillType), (int) (XP * mcMMO.getDynamicSettingsManager().getExperienceManager().getGlobalXpMult()));
}
/**
@ -262,11 +262,11 @@ public final class ExperienceAPI {
PrimarySkillType skill = getSkillType(skillType);
if (isUnshared) {
getPlayer(player).beginUnsharedXpGain(skill, (int) (XP / skill.getXpModifier() * mcMMO.getDynamicSettingsManager().getExperienceMapManager().getGlobalXpMult()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).beginUnsharedXpGain(skill, (int) (XP / skill.getXpModifier() * mcMMO.getDynamicSettingsManager().getExperienceManager().getGlobalXpMult()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
return;
}
getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * mcMMO.getDynamicSettingsManager().getExperienceMapManager().getGlobalXpMult()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * mcMMO.getDynamicSettingsManager().getExperienceManager().getGlobalXpMult()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
}
/**
@ -284,7 +284,7 @@ public final class ExperienceAPI {
public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
PrimarySkillType skill = getSkillType(skillType);
addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * mcMMO.getDynamicSettingsManager().getExperienceMapManager().getGlobalXpMult()));
addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * mcMMO.getDynamicSettingsManager().getExperienceManager().getGlobalXpMult()));
}
/**
@ -1000,8 +1000,8 @@ public final class ExperienceAPI {
public static void addXpFromBlocks(ArrayList<BlockState> blockStates, McMMOPlayer mcMMOPlayer) {
for (BlockState bs : blockStates) {
for (PrimarySkillType skillType : PrimarySkillType.values()) {
if (mcMMO.getDynamicSettingsManager().getExperienceMapManager().getBlockBreakXpValue(skillType, bs.getType()) > 0) {
mcMMOPlayer.applyXpGain(skillType, mcMMO.getDynamicSettingsManager().getExperienceMapManager().getBlockBreakXpValue(skillType, bs.getType()), XPGainReason.PVE, XPGainSource.SELF);
if (mcMMO.getDynamicSettingsManager().getExperienceManager().getBlockBreakXpValue(skillType, bs.getType()) > 0) {
mcMMOPlayer.applyXpGain(skillType, mcMMO.getDynamicSettingsManager().getExperienceManager().getBlockBreakXpValue(skillType, bs.getType()), XPGainReason.PVE, XPGainSource.SELF);
}
}
}
@ -1016,8 +1016,8 @@ public final class ExperienceAPI {
*/
public static void addXpFromBlocksBySkill(ArrayList<BlockState> blockStates, McMMOPlayer mcMMOPlayer, PrimarySkillType skillType) {
for (BlockState bs : blockStates) {
if (mcMMO.getDynamicSettingsManager().getExperienceMapManager().getBlockBreakXpValue(skillType, bs.getType()) > 0) {
mcMMOPlayer.applyXpGain(skillType, mcMMO.getDynamicSettingsManager().getExperienceMapManager().getBlockBreakXpValue(skillType, bs.getType()), XPGainReason.PVE, XPGainSource.SELF);
if (mcMMO.getDynamicSettingsManager().getExperienceManager().getBlockBreakXpValue(skillType, bs.getType()) > 0) {
mcMMOPlayer.applyXpGain(skillType, mcMMO.getDynamicSettingsManager().getExperienceManager().getBlockBreakXpValue(skillType, bs.getType()), XPGainReason.PVE, XPGainSource.SELF);
}
}
}
@ -1030,8 +1030,8 @@ public final class ExperienceAPI {
*/
public static void addXpFromBlock(BlockState blockState, McMMOPlayer mcMMOPlayer) {
for (PrimarySkillType skillType : PrimarySkillType.values()) {
if (mcMMO.getDynamicSettingsManager().getExperienceMapManager().getBlockBreakXpValue(skillType, blockState.getType()) > 0) {
mcMMOPlayer.applyXpGain(skillType, mcMMO.getDynamicSettingsManager().getExperienceMapManager().getBlockBreakXpValue(skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
if (mcMMO.getDynamicSettingsManager().getExperienceManager().getBlockBreakXpValue(skillType, blockState.getType()) > 0) {
mcMMOPlayer.applyXpGain(skillType, mcMMO.getDynamicSettingsManager().getExperienceManager().getBlockBreakXpValue(skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
}
}
}
@ -1044,8 +1044,8 @@ public final class ExperienceAPI {
* @param skillType target primary skill
*/
public static void addXpFromBlockBySkill(BlockState blockState, McMMOPlayer mcMMOPlayer, PrimarySkillType skillType) {
if (mcMMO.getDynamicSettingsManager().getExperienceMapManager().getBlockBreakXpValue(skillType, blockState.getType()) > 0) {
mcMMOPlayer.applyXpGain(skillType, mcMMO.getDynamicSettingsManager().getExperienceMapManager().getBlockBreakXpValue(skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
if (mcMMO.getDynamicSettingsManager().getExperienceManager().getBlockBreakXpValue(skillType, blockState.getType()) > 0) {
mcMMOPlayer.applyXpGain(skillType, mcMMO.getDynamicSettingsManager().getExperienceManager().getBlockBreakXpValue(skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
}
}

View File

@ -18,7 +18,7 @@ import java.util.ArrayList;
import java.util.List;
public class XprateCommand implements TabExecutor {
private final double ORIGINAL_XP_RATE = mcMMO.getDynamicSettingsManager().getExperienceMapManager().getGlobalXpMult();
private final double ORIGINAL_XP_RATE = mcMMO.getDynamicSettingsManager().getExperienceManager().getGlobalXpMult();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -48,7 +48,7 @@ public class XprateCommand implements TabExecutor {
mcMMO.p.toggleXpEventEnabled();
}
mcMMO.getDynamicSettingsManager().getExperienceMapManager().resetGlobalXpMult();
mcMMO.getDynamicSettingsManager().getExperienceManager().resetGlobalXpMult();
return true;
case 2:
@ -76,7 +76,7 @@ public class XprateCommand implements TabExecutor {
return true;
}
mcMMO.getDynamicSettingsManager().getExperienceMapManager().setGlobalXpMult(newXpRate);
mcMMO.getDynamicSettingsManager().getExperienceManager().setGlobalXpMult(newXpRate);
if (mcMMO.p.isXPEventEnabled()) {
if (AdvancedConfig.getInstance().useTitlesForXPEvent()) {

View File

@ -7,7 +7,7 @@ import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.repair.repairables.RepairableManager;
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
import com.gmail.nossr50.skills.salvage.salvageables.SalvageableManager;
import com.gmail.nossr50.util.experience.ExperienceMapManager;
import com.gmail.nossr50.util.experience.ExperienceManager;
import com.google.common.collect.Maps;
import org.bukkit.Material;
@ -33,7 +33,7 @@ public class DynamicSettingsManager {
/* Platform Ready Managers */
private BonusDropManager bonusDropManager;
private ExperienceMapManager experienceMapManager;
private ExperienceManager experienceManager;
/* Party Settings */
private HashMap<Material, Integer> partyItemWeights;
@ -67,11 +67,11 @@ public class DynamicSettingsManager {
* Misc managers
*/
private void initMiscManagers() {
experienceMapManager = new ExperienceMapManager();
experienceManager = new ExperienceManager();
//Set the global XP val
experienceMapManager.setGlobalXpMult(mcMMO.getConfigManager().getConfigExperience().getGlobalXPMultiplier());
experienceMapManager.buildBlockXPMaps(); //Block XP value maps
experienceMapManager.fillCombatXPMultiplierMap(mcMMO.getConfigManager().getConfigExperience().getCombatExperienceMap());
experienceManager.setGlobalXpMult(mcMMO.getConfigManager().getConfigExperience().getGlobalXPMultiplier());
experienceManager.buildBlockXPMaps(); //Block XP value maps
experienceManager.fillCombatXPMultiplierMap(mcMMO.getConfigManager().getConfigExperience().getCombatExperienceMap());
// potionManager = new PotionManager();
}
@ -127,8 +127,8 @@ public class DynamicSettingsManager {
return salvageableManager;
}
public ExperienceMapManager getExperienceMapManager() {
return experienceMapManager;
public ExperienceManager getExperienceManager() {
return experienceManager;
}
public BonusDropManager getBonusDropManager() {

View File

@ -775,7 +775,7 @@ public class McMMOPlayer {
return 0;
}
xp = (float) (xp / primarySkillType.getXpModifier() * mcMMO.getDynamicSettingsManager().getExperienceMapManager().getGlobalXpMult());
xp = (float) (xp / primarySkillType.getXpModifier() * mcMMO.getDynamicSettingsManager().getExperienceManager().getGlobalXpMult());
//Multiply by the players personal XP rate
return xp * personalXPModifiers.get(primarySkillType);

View File

@ -520,7 +520,7 @@ public class PlayerListener implements Listener {
}
if (plugin.isXPEventEnabled()) {
player.sendMessage(LocaleLoader.getString("XPRate.Event", mcMMO.getDynamicSettingsManager().getExperienceMapManager().getGlobalXpMult()));
player.sendMessage(LocaleLoader.getString("XPRate.Event", mcMMO.getDynamicSettingsManager().getExperienceManager().getGlobalXpMult()));
}
//TODO: Remove this warning

View File

@ -1,7 +1,6 @@
package com.gmail.nossr50.listeners;
import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
@ -119,7 +118,7 @@ public class SelfListener implements Listener {
float guaranteedMinimum = mcMMO.getConfigManager().getConfigLeveling().getGuaranteedMinimums() * rawXp;
float modifiedThreshold = (float) (threshold / primarySkillType.getXpModifier() * mcMMO.getDynamicSettingsManager().getExperienceMapManager().getGlobalXpMult());
float modifiedThreshold = (float) (threshold / primarySkillType.getXpModifier() * mcMMO.getDynamicSettingsManager().getExperienceManager().getGlobalXpMult());
float difference = (mcMMOPlayer.getProfile().getRegisteredXpGain(primarySkillType) - modifiedThreshold) / modifiedThreshold;
if (difference > 0) {

View File

@ -24,7 +24,7 @@ public class Excavation {
}
protected static int getBlockXP(BlockState blockState) {
int xp = mcMMO.getDynamicSettingsManager().getExperienceMapManager().getExcavationXp(blockState.getType());
int xp = mcMMO.getDynamicSettingsManager().getExperienceManager().getExcavationXp(blockState.getType());
return xp;
}

View File

@ -148,7 +148,7 @@ public class HerbalismManager extends SkillManager {
// }
// }
// else {
xp = mcMMO.getDynamicSettingsManager().getExperienceMapManager().getHerbalismXp(blockState.getType());
xp = mcMMO.getDynamicSettingsManager().getExperienceManager().getHerbalismXp(blockState.getType());
if (!oneBlockPlant) {
//Kelp is actually two blocks mixed together

View File

@ -32,7 +32,7 @@ public class Mining {
* @param blockState The {@link BlockState} to check ability activation for
*/
public static int getBlockXp(BlockState blockState) {
int xp = mcMMO.getDynamicSettingsManager().getExperienceMapManager().getMiningXp(blockState.getType());
int xp = mcMMO.getDynamicSettingsManager().getExperienceManager().getMiningXp(blockState.getType());
return xp;
}

View File

@ -106,7 +106,7 @@ public class TamingManager extends SkillManager {
* @param entity The LivingEntity to award XP for
*/
public void awardTamingXP(LivingEntity entity) {
applyXpGain(mcMMO.getDynamicSettingsManager().getExperienceMapManager().getTamingXp(entity.getType()), XPGainReason.PVE);
applyXpGain(mcMMO.getDynamicSettingsManager().getExperienceManager().getTamingXp(entity.getType()), XPGainReason.PVE);
}
/**

View File

@ -43,7 +43,7 @@ public final class Woodcutting {
return mcMMO.getModManager().getBlock(blockState).getXpGain();
}*/
return mcMMO.getDynamicSettingsManager().getExperienceMapManager().getWoodcuttingXp(blockState.getType());
return mcMMO.getDynamicSettingsManager().getExperienceManager().getWoodcuttingXp(blockState.getType());
}
/**

View File

@ -129,7 +129,7 @@ public final class BlockUtils {
* @return true if the block should affected by Green Terra, false otherwise
*/
public static boolean affectedByGreenTerra(BlockState blockState) {
return mcMMO.getDynamicSettingsManager().getExperienceMapManager().hasHerbalismXp(blockState.getType());
return mcMMO.getDynamicSettingsManager().getExperienceManager().hasHerbalismXp(blockState.getType());
}
/**
@ -139,7 +139,7 @@ public final class BlockUtils {
* @return true if the block should affected by Green Terra, false otherwise
*/
public static boolean affectedByGreenTerra(Material material) {
return mcMMO.getDynamicSettingsManager().getExperienceMapManager().hasHerbalismXp(material);
return mcMMO.getDynamicSettingsManager().getExperienceManager().hasHerbalismXp(material);
}
/**
@ -150,7 +150,7 @@ public final class BlockUtils {
* otherwise
*/
public static Boolean affectedBySuperBreaker(BlockState blockState) {
if (mcMMO.getDynamicSettingsManager().getExperienceMapManager().hasMiningXp(blockState.getType()))
if (mcMMO.getDynamicSettingsManager().getExperienceManager().hasMiningXp(blockState.getType()))
return true;
return isMineable(blockState);
@ -164,7 +164,7 @@ public final class BlockUtils {
* otherwise
*/
public static Boolean affectedBySuperBreaker(Material material) {
if (mcMMO.getDynamicSettingsManager().getExperienceMapManager().hasMiningXp(material))
if (mcMMO.getDynamicSettingsManager().getExperienceManager().hasMiningXp(material))
return true;
return isMineable(material);
@ -215,7 +215,7 @@ public final class BlockUtils {
* otherwise
*/
public static boolean affectedByGigaDrillBreaker(Material material) {
if (mcMMO.getDynamicSettingsManager().getExperienceMapManager().hasExcavationXp(material))
if (mcMMO.getDynamicSettingsManager().getExperienceManager().hasExcavationXp(material))
return true;
return isDiggable(material);
@ -229,7 +229,7 @@ public final class BlockUtils {
* otherwise
*/
public static boolean affectedByGigaDrillBreaker(BlockState blockState) {
if (mcMMO.getDynamicSettingsManager().getExperienceMapManager().hasExcavationXp(blockState.getType()))
if (mcMMO.getDynamicSettingsManager().getExperienceManager().hasExcavationXp(blockState.getType()))
return true;
return isDiggable(blockState);
@ -281,7 +281,7 @@ public final class BlockUtils {
* @return true if the block is a log, false otherwise
*/
public static boolean isLog(BlockState blockState) {
if (mcMMO.getDynamicSettingsManager().getExperienceMapManager().hasWoodcuttingXp(blockState.getType()))
if (mcMMO.getDynamicSettingsManager().getExperienceManager().hasWoodcuttingXp(blockState.getType()))
return true;
return isLoggingRelated(blockState);
@ -295,7 +295,7 @@ public final class BlockUtils {
* @return true if the block is a log, false otherwise
*/
public static boolean isLog(Material material) {
if (mcMMO.getDynamicSettingsManager().getExperienceMapManager().hasWoodcuttingXp(material))
if (mcMMO.getDynamicSettingsManager().getExperienceManager().hasWoodcuttingXp(material))
return true;
return isLoggingRelated(material);

View File

@ -10,9 +10,9 @@ import org.bukkit.entity.EntityType;
import java.util.HashMap;
/**
* This class handles the XP for block break related XP
* This class handles the XP maps for various skills
*/
public class ExperienceMapManager {
public class ExperienceManager {
private HashMap<PrimarySkillType, HashMap<Material, String>> skillMaterialXPMap;
private HashMap<String, Integer> miningFullyQualifiedBlockXpMap;
private HashMap<String, Integer> herbalismFullyQualifiedBlockXpMap;
@ -24,7 +24,7 @@ public class ExperienceMapManager {
private double globalXpMult;
public ExperienceMapManager() {
public ExperienceManager() {
initExperienceMaps();
registerDefaultValues();
@ -167,28 +167,47 @@ public class ExperienceMapManager {
globalXpMult = newGlobalXpMult;
}
/**
* Reset the Global XP multiplier to its original value
*/
public void resetGlobalXpMult() {
mcMMO.p.getLogger().info("Resetting the global XP multiplier " + globalXpMult + " -> " + getOriginalGlobalXpMult());
globalXpMult = getOriginalGlobalXpMult();
}
/**
* Set the mining block XP map to the provided one
* @param miningFullyQualifiedBlockXpMap the XP map to change to
*/
public void setMiningFullyQualifiedBlockXpMap(HashMap<String, Integer> miningFullyQualifiedBlockXpMap) {
mcMMO.p.getLogger().info("Registering Mining XP Values...");
mcMMO.p.getLogger().info("Changing Mining XP Values...");
this.miningFullyQualifiedBlockXpMap = miningFullyQualifiedBlockXpMap;
}
/**
* Set the mining block XP map to the provided one
* @param herbalismFullyQualifiedBlockXpMap the XP map to change to
*/
public void setHerbalismFullyQualifiedBlockXpMap(HashMap<String, Integer> herbalismFullyQualifiedBlockXpMap) {
mcMMO.p.getLogger().info("Registering Herbalism XP Values...");
mcMMO.p.getLogger().info("Changing Herbalism XP Values...");
this.herbalismFullyQualifiedBlockXpMap = herbalismFullyQualifiedBlockXpMap;
}
/**
* Set the mining block XP map to the provided one
* @param woodcuttingFullyQualifiedBlockXpMap the XP map to change to
*/
public void setWoodcuttingFullyQualifiedBlockXpMap(HashMap<String, Integer> woodcuttingFullyQualifiedBlockXpMap) {
mcMMO.p.getLogger().info("Registering Woodcutting XP Values...");
mcMMO.p.getLogger().info("Changin Woodcutting XP Values...");
this.woodcuttingFullyQualifiedBlockXpMap = woodcuttingFullyQualifiedBlockXpMap;
}
/**
* Set the mining block XP map to the provided one
* @param excavationFullyQualifiedBlockXpMap the XP map to change to
*/
public void setExcavationFullyQualifiedBlockXpMap(HashMap<String, Integer> excavationFullyQualifiedBlockXpMap) {
mcMMO.p.getLogger().info("Registering Excavation XP Values...");
mcMMO.p.getLogger().info("Changing Excavation XP Values...");
this.excavationFullyQualifiedBlockXpMap = excavationFullyQualifiedBlockXpMap;
}

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.util.skills;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.core.MetadataConstants;
import com.gmail.nossr50.datatypes.experience.SpecialXPKey;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
@ -553,21 +552,21 @@ public final class CombatUtils {
}*/
//else if (target instanceof Animals) {
if (target instanceof Animals) {
baseXPMultiplier = mcMMO.getDynamicSettingsManager().getExperienceMapManager().getSpecialCombatXP(SpecialXPKey.ANIMALS);
baseXPMultiplier = mcMMO.getDynamicSettingsManager().getExperienceManager().getSpecialCombatXP(SpecialXPKey.ANIMALS);
} else if (target instanceof Monster) {
EntityType type = target.getType();
baseXPMultiplier = mcMMO.getDynamicSettingsManager().getExperienceMapManager().getCombatXPMultiplier(type);
baseXPMultiplier = mcMMO.getDynamicSettingsManager().getExperienceManager().getCombatXPMultiplier(type);
} else {
EntityType type = target.getType();
if (mcMMO.getDynamicSettingsManager().getExperienceMapManager().hasCombatXP(type)) {
if (mcMMO.getDynamicSettingsManager().getExperienceManager().hasCombatXP(type)) {
//Exploit stuff
if (type == EntityType.IRON_GOLEM) {
if (!((IronGolem) target).isPlayerCreated()) {
baseXPMultiplier = mcMMO.getDynamicSettingsManager().getExperienceMapManager().getCombatXPMultiplier(type);
baseXPMultiplier = mcMMO.getDynamicSettingsManager().getExperienceManager().getCombatXPMultiplier(type);
}
} else {
baseXPMultiplier = mcMMO.getDynamicSettingsManager().getExperienceMapManager().getCombatXPMultiplier(type);
baseXPMultiplier = mcMMO.getDynamicSettingsManager().getExperienceManager().getCombatXPMultiplier(type);
}
} else {
baseXPMultiplier = 1.0f;