Create fully qualified name : integer maps from user configs, wiring up some global xp settings

This commit is contained in:
nossr50 2019-04-30 00:42:09 -07:00
parent faed690602
commit 6932abc9d8
9 changed files with 95 additions and 52 deletions

View File

@ -25,7 +25,7 @@ Version 2.2.0
Acrobatic's Dodge XP increased from 120 -> 480 Acrobatic's Dodge XP increased from 120 -> 480
Fishing's always catch fish setting now defaults to true instead of false Fishing's always catch fish setting now defaults to true instead of false
Optimized code related to Fishing Optimized code related to Fishing
Added a new command "mcmmoreload" to reload config values Added a new command 'mcmmoreload' to reload config values
Added new locale string 'Commands.Reload.Start' Added new locale string 'Commands.Reload.Start'
Added new locale string 'Commands.Reload.Finished' Added new locale string 'Commands.Reload.Finished'
Added new permission 'mcmmo.commands.reload' Added new permission 'mcmmo.commands.reload'

View File

@ -183,7 +183,7 @@ public final class ExperienceAPI {
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid * @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/ */
public static void addMultipliedXP(Player player, String skillType, int XP, String xpGainReason) { public static void addMultipliedXP(Player player, String skillType, int XP, String xpGainReason) {
getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM); getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * mcMMO.getConfigManager().getExperienceMapManager().getGlobalXpMult()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
} }
/** /**
@ -199,7 +199,7 @@ public final class ExperienceAPI {
*/ */
@Deprecated @Deprecated
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) { public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
addOfflineXP(playerName, getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier())); addOfflineXP(playerName, getSkillType(skillType), (int) (XP * mcMMO.getConfigManager().getExperienceMapManager().getGlobalXpMult()));
} }
/** /**
@ -250,11 +250,11 @@ public final class ExperienceAPI {
PrimarySkillType skill = getSkillType(skillType); PrimarySkillType skill = getSkillType(skillType);
if (isUnshared) { if (isUnshared) {
getPlayer(player).beginUnsharedXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM); getPlayer(player).beginUnsharedXpGain(skill, (int) (XP / skill.getXpModifier() * mcMMO.getConfigManager().getExperienceMapManager().getGlobalXpMult()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
return; return;
} }
getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM); getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * mcMMO.getConfigManager().getExperienceMapManager().getGlobalXpMult()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
} }
/** /**
@ -272,7 +272,7 @@ public final class ExperienceAPI {
public static void addModifiedXPOffline(String playerName, String skillType, int XP) { public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
PrimarySkillType skill = getSkillType(skillType); PrimarySkillType skill = getSkillType(skillType);
addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier())); addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * mcMMO.getConfigManager().getExperienceMapManager().getGlobalXpMult()));
} }
/** /**

View File

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

View File

@ -337,7 +337,7 @@ public final class ConfigManager {
experienceMapManager = new ExperienceMapManager(); experienceMapManager = new ExperienceMapManager();
//Set the global XP val //Set the global XP val
experienceMapManager.setGlobalXpMult(getConfigExperience().getGlobalXPMultiplier()); experienceMapManager.setGlobalXpMult(getConfigExperience().getGlobalXPMultiplier());
experienceMapManager.setExcavationXpMap(getConfigExperience().getExcavationExperienceMap()); experienceMapManager.buildBlockXPMaps(); //Block XP value maps
} }
/** /**

View File

@ -122,15 +122,6 @@ public class ExperienceConfig extends ConfigValidated {
* FORMULA SETTINGS * FORMULA SETTINGS
*/ */
/* Global modifier */
public double getExperienceGainsGlobalMultiplier() {
return getDoubleValue(EXPERIENCE_FORMULA, MULTIPLIER, GLOBAL);
}
public void setGlobalXPMultiplier(double newXpMultiplier) {
getUserRootNode().getNode(EXPERIENCE_FORMULA, MULTIPLIER, GLOBAL).setValue(newXpMultiplier);
}
//TODO: Rewrite this //TODO: Rewrite this
/*public void setExperienceGainsGlobalMultiplier(double value) { /*public void setExperienceGainsGlobalMultiplier(double value) {
config.set(EXPERIENCE_FORMULA, MULTIPLIER, GLOBAL, value); config.set(EXPERIENCE_FORMULA, MULTIPLIER, GLOBAL, value);

View File

@ -744,7 +744,7 @@ public class McMMOPlayer {
return 0; return 0;
} }
xp = (float) (xp / primarySkillType.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()); xp = (float) (xp / primarySkillType.getXpModifier() * mcMMO.getConfigManager().getExperienceMapManager().getGlobalXpMult());
/*if (MainConfig.getInstance().getToolModsEnabled()) { /*if (MainConfig.getInstance().getToolModsEnabled()) {
CustomTool tool = mcMMO.getModManager().getTool(player.getInventory().getItemInMainHand()); CustomTool tool = mcMMO.getModManager().getTool(player.getInventory().getItemInMainHand());

View File

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

View File

@ -119,7 +119,7 @@ public class SelfListener implements Listener {
float guaranteedMinimum = ExperienceConfig.getInstance().getDiminishedReturnsCap() * rawXp; float guaranteedMinimum = ExperienceConfig.getInstance().getDiminishedReturnsCap() * rawXp;
float modifiedThreshold = (float) (threshold / primarySkillType.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()); float modifiedThreshold = (float) (threshold / primarySkillType.getXpModifier() * mcMMO.getConfigManager().getExperienceMapManager().getGlobalXpMult());
float difference = (mcMMOPlayer.getProfile().getRegisteredXpGain(primarySkillType) - modifiedThreshold) / modifiedThreshold; float difference = (mcMMOPlayer.getProfile().getRegisteredXpGain(primarySkillType) - modifiedThreshold) / modifiedThreshold;
if (difference > 0) { if (difference > 0) {

View File

@ -12,26 +12,73 @@ import java.util.HashMap;
*/ */
public class ExperienceMapManager implements Unload { public class ExperienceMapManager implements Unload {
private HashMap<PrimarySkillType, HashMap<Material, String>> skillMaterialXPMap; private HashMap<PrimarySkillType, HashMap<Material, String>> skillMaterialXPMap;
private HashMap<String, Integer> miningXpMap; private HashMap<String, Integer> miningFullyQualifiedBlockXpMap;
private HashMap<String, Integer> herbalismXpMap; private HashMap<String, Integer> herbalismFullyQualifiedBlockXpMap;
private HashMap<String, Integer> woodcuttingXpMap; private HashMap<String, Integer> woodcuttingFullyQualifiedBlockXpMap;
private HashMap<String, Integer> excavationXpMap; private HashMap<String, Integer> excavationFullyQualifiedBlockXpMap;
private double globalXpMult; private double globalXpMult;
public ExperienceMapManager() { public ExperienceMapManager() {
miningXpMap = new HashMap<>(); miningFullyQualifiedBlockXpMap = new HashMap<>();
herbalismXpMap = new HashMap<>(); herbalismFullyQualifiedBlockXpMap = new HashMap<>();
woodcuttingXpMap = new HashMap<>(); woodcuttingFullyQualifiedBlockXpMap = new HashMap<>();
excavationXpMap = new HashMap<>(); excavationFullyQualifiedBlockXpMap = new HashMap<>();
//Register with unloader //Register with unloader
mcMMO.getConfigManager().registerUnloadable(this); mcMMO.getConfigManager().registerUnloadable(this);
} }
public void buildMaterialXPMap(HashMap<String, Integer> xpMap, PrimarySkillType primarySkillType) /**
{ * Builds fully qualified name to xp value maps of blocks for XP lookups
* This method servers two purposes
* 1) It adds user config values to a hash table
* 2) It converts user config values into their fully qualified names
*
* This is done to avoid namespace conflicts, which don't happen in Bukkit but could easily happen in Sponge
*
*/
public void buildBlockXPMaps() {
buildMiningBlockXPMap();
buildHerbalismBlockXPMap();
buildWoodcuttingBlockXPMap();
buildExcavationBlockXPMap();
}
private void fillBlockXPMap(HashMap<String, Integer> userConfigMap, HashMap<String, Integer> fullyQualifiedBlockXPMap)
{
for(String string : userConfigMap.keySet()) {
//matchMaterial can match fully qualified names and names without domain
Material matchingMaterial = Material.matchMaterial(string);
if (matchingMaterial != null) {
//Map the fully qualified name
fullyQualifiedBlockXPMap.put(matchingMaterial.getKey().getKey(), userConfigMap.get(string));
} else {
mcMMO.p.getLogger().info("Could not find a match for the block named '"+string+"' among vanilla block registers");
}
}
}
private void buildMiningBlockXPMap() {
mcMMO.p.getLogger().info("Mapping block break XP values for Mining...");
fillBlockXPMap(mcMMO.getConfigManager().getConfigExperience().getMiningExperienceMap(), miningFullyQualifiedBlockXpMap);
}
private void buildHerbalismBlockXPMap() {
mcMMO.p.getLogger().info("Mapping block break XP values for Herbalism...");
fillBlockXPMap(mcMMO.getConfigManager().getConfigExperience().getHerbalismXPMap(), herbalismFullyQualifiedBlockXpMap);
}
private void buildWoodcuttingBlockXPMap() {
mcMMO.p.getLogger().info("Mapping block break XP values for Woodcutting...");
fillBlockXPMap(mcMMO.getConfigManager().getConfigExperience().getWoodcuttingExperienceMap(), woodcuttingFullyQualifiedBlockXpMap);
}
private void buildExcavationBlockXPMap() {
mcMMO.p.getLogger().info("Mapping block break XP values for Excavation...");
fillBlockXPMap(mcMMO.getConfigManager().getConfigExperience().getExcavationExperienceMap(), excavationFullyQualifiedBlockXpMap);
} }
/** /**
@ -43,24 +90,29 @@ public class ExperienceMapManager implements Unload {
globalXpMult = newGlobalXpMult; globalXpMult = newGlobalXpMult;
} }
public void setMiningXpMap(HashMap<String, Integer> miningXpMap) { public void resetGlobalXpMult() {
mcMMO.p.getLogger().info("Resetting the global XP multiplier "+globalXpMult+" -> "+getOriginalGlobalXpMult());
globalXpMult = getOriginalGlobalXpMult();
}
public void setMiningFullyQualifiedBlockXpMap(HashMap<String, Integer> miningFullyQualifiedBlockXpMap) {
mcMMO.p.getLogger().info("Registering Mining XP Values..."); mcMMO.p.getLogger().info("Registering Mining XP Values...");
this.miningXpMap = miningXpMap; this.miningFullyQualifiedBlockXpMap = miningFullyQualifiedBlockXpMap;
} }
public void setHerbalismXpMap(HashMap<String, Integer> herbalismXpMap) { public void setHerbalismFullyQualifiedBlockXpMap(HashMap<String, Integer> herbalismFullyQualifiedBlockXpMap) {
mcMMO.p.getLogger().info("Registering Herbalism XP Values..."); mcMMO.p.getLogger().info("Registering Herbalism XP Values...");
this.herbalismXpMap = herbalismXpMap; this.herbalismFullyQualifiedBlockXpMap = herbalismFullyQualifiedBlockXpMap;
} }
public void setWoodcuttingXpMap(HashMap<String, Integer> woodcuttingXpMap) { public void setWoodcuttingFullyQualifiedBlockXpMap(HashMap<String, Integer> woodcuttingFullyQualifiedBlockXpMap) {
mcMMO.p.getLogger().info("Registering Woodcutting XP Values..."); mcMMO.p.getLogger().info("Registering Woodcutting XP Values...");
this.woodcuttingXpMap = woodcuttingXpMap; this.woodcuttingFullyQualifiedBlockXpMap = woodcuttingFullyQualifiedBlockXpMap;
} }
public void setExcavationXpMap(HashMap<String, Integer> excavationXpMap) { public void setExcavationFullyQualifiedBlockXpMap(HashMap<String, Integer> excavationFullyQualifiedBlockXpMap) {
mcMMO.p.getLogger().info("Registering Excavation XP Values..."); mcMMO.p.getLogger().info("Registering Excavation XP Values...");
this.excavationXpMap = excavationXpMap; this.excavationFullyQualifiedBlockXpMap = excavationFullyQualifiedBlockXpMap;
} }
/** /**
@ -89,7 +141,7 @@ public class ExperienceMapManager implements Unload {
* @return true if the block has valid xp registers * @return true if the block has valid xp registers
*/ */
public boolean hasMiningXp(Material material) { public boolean hasMiningXp(Material material) {
return miningXpMap.get(material.getKey().getKey()) != null; return miningFullyQualifiedBlockXpMap.get(material.getKey().getKey()) != null;
} }
/** /**
@ -99,7 +151,7 @@ public class ExperienceMapManager implements Unload {
* @return true if the block has valid xp registers * @return true if the block has valid xp registers
*/ */
public boolean hasHerbalismXp(Material material) { public boolean hasHerbalismXp(Material material) {
return herbalismXpMap.get(material) != null; return herbalismFullyQualifiedBlockXpMap.get(material) != null;
} }
/** /**
@ -109,7 +161,7 @@ public class ExperienceMapManager implements Unload {
* @return true if the block has valid xp registers * @return true if the block has valid xp registers
*/ */
public boolean hasWoodcuttingXp(Material material) { public boolean hasWoodcuttingXp(Material material) {
return woodcuttingXpMap.get(material) != null; return woodcuttingFullyQualifiedBlockXpMap.get(material) != null;
} }
/** /**
@ -119,7 +171,7 @@ public class ExperienceMapManager implements Unload {
* @return true if the block has valid xp registers * @return true if the block has valid xp registers
*/ */
public boolean hasExcavationXp(Material material) { public boolean hasExcavationXp(Material material) {
return excavationXpMap.get(material) != null; return excavationFullyQualifiedBlockXpMap.get(material) != null;
} }
/** /**
@ -129,7 +181,7 @@ public class ExperienceMapManager implements Unload {
* @return the raw XP value before any modifiers are applied * @return the raw XP value before any modifiers are applied
*/ */
public int getMiningXp(Material material) { public int getMiningXp(Material material) {
return miningXpMap.get(material); return miningFullyQualifiedBlockXpMap.get(material);
} }
/** /**
@ -139,7 +191,7 @@ public class ExperienceMapManager implements Unload {
* @return the raw XP value before any modifiers are applied * @return the raw XP value before any modifiers are applied
*/ */
public int getHerbalismXp(Material material) { public int getHerbalismXp(Material material) {
return herbalismXpMap.get(material); return herbalismFullyQualifiedBlockXpMap.get(material);
} }
/** /**
@ -149,7 +201,7 @@ public class ExperienceMapManager implements Unload {
* @return the raw XP value before any modifiers are applied * @return the raw XP value before any modifiers are applied
*/ */
public int getWoodcuttingXp(Material material) { public int getWoodcuttingXp(Material material) {
return woodcuttingXpMap.get(material); return woodcuttingFullyQualifiedBlockXpMap.get(material);
} }
/** /**
@ -159,14 +211,14 @@ public class ExperienceMapManager implements Unload {
* @return the raw XP value before any modifiers are applied * @return the raw XP value before any modifiers are applied
*/ */
public int getExcavationXp(Material material) { public int getExcavationXp(Material material) {
return excavationXpMap.get(material); return excavationFullyQualifiedBlockXpMap.get(material);
} }
@Override @Override
public void unload() { public void unload() {
miningXpMap.clear(); miningFullyQualifiedBlockXpMap.clear();
woodcuttingXpMap.clear(); woodcuttingFullyQualifiedBlockXpMap.clear();
herbalismXpMap.clear(); herbalismFullyQualifiedBlockXpMap.clear();
excavationXpMap.clear(); excavationFullyQualifiedBlockXpMap.clear();
} }
} }