diff --git a/Changelog.txt b/Changelog.txt index a1097eaa2..4f72fb770 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -25,7 +25,7 @@ Version 2.2.0 Acrobatic's Dodge XP increased from 120 -> 480 Fishing's always catch fish setting now defaults to true instead of false 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.Finished' Added new permission 'mcmmo.commands.reload' diff --git a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java index 5baff2727..569badc04 100644 --- a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java +++ b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java @@ -183,7 +183,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 * 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 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); 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; } - 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) { 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())); } /** diff --git a/src/main/java/com/gmail/nossr50/commands/XprateCommand.java b/src/main/java/com/gmail/nossr50/commands/XprateCommand.java index b2bc3bfc1..59b0182ef 100644 --- a/src/main/java/com/gmail/nossr50/commands/XprateCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/XprateCommand.java @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.List; 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 public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -49,7 +49,7 @@ public class XprateCommand implements TabExecutor { mcMMO.p.toggleXpEventEnabled(); } - ExperienceConfig.getInstance().setGlobalXPMultiplier(ORIGINAL_XP_RATE); + mcMMO.getConfigManager().getExperienceMapManager().resetGlobalXpMult(); return true; case 2: @@ -77,7 +77,7 @@ public class XprateCommand implements TabExecutor { return true; } - ExperienceConfig.getInstance().setGlobalXPMultiplier(newXpRate); + mcMMO.getConfigManager().getExperienceMapManager().setGlobalXpMult(newXpRate); if (mcMMO.p.isXPEventEnabled()) { if (AdvancedConfig.getInstance().useTitlesForXPEvent()) { diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index 21813dbf9..7e685abe0 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -337,7 +337,7 @@ public final class ConfigManager { experienceMapManager = new ExperienceMapManager(); //Set the global XP val experienceMapManager.setGlobalXpMult(getConfigExperience().getGlobalXPMultiplier()); - experienceMapManager.setExcavationXpMap(getConfigExperience().getExcavationExperienceMap()); + experienceMapManager.buildBlockXPMaps(); //Block XP value maps } /** diff --git a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java index 5870110e2..1e63b77ac 100644 --- a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java +++ b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java @@ -122,15 +122,6 @@ public class ExperienceConfig extends ConfigValidated { * 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 /*public void setExperienceGainsGlobalMultiplier(double value) { config.set(EXPERIENCE_FORMULA, MULTIPLIER, GLOBAL, value); diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index c470ff191..17b04069a 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -744,7 +744,7 @@ public class McMMOPlayer { return 0; } - xp = (float) (xp / primarySkillType.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()); + xp = (float) (xp / primarySkillType.getXpModifier() * mcMMO.getConfigManager().getExperienceMapManager().getGlobalXpMult()); /*if (MainConfig.getInstance().getToolModsEnabled()) { CustomTool tool = mcMMO.getModManager().getTool(player.getInventory().getItemInMainHand()); diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index dec19dcd3..fd06a136d 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -520,7 +520,7 @@ public class PlayerListener implements Listener { } 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 diff --git a/src/main/java/com/gmail/nossr50/listeners/SelfListener.java b/src/main/java/com/gmail/nossr50/listeners/SelfListener.java index acff5c282..6cc70d83e 100644 --- a/src/main/java/com/gmail/nossr50/listeners/SelfListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/SelfListener.java @@ -119,7 +119,7 @@ public class SelfListener implements Listener { 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; if (difference > 0) { diff --git a/src/main/java/com/gmail/nossr50/util/experience/ExperienceMapManager.java b/src/main/java/com/gmail/nossr50/util/experience/ExperienceMapManager.java index 37c4dfd9a..13d24c1ff 100644 --- a/src/main/java/com/gmail/nossr50/util/experience/ExperienceMapManager.java +++ b/src/main/java/com/gmail/nossr50/util/experience/ExperienceMapManager.java @@ -12,26 +12,73 @@ import java.util.HashMap; */ public class ExperienceMapManager implements Unload { private HashMap> skillMaterialXPMap; - private HashMap miningXpMap; - private HashMap herbalismXpMap; - private HashMap woodcuttingXpMap; - private HashMap excavationXpMap; + private HashMap miningFullyQualifiedBlockXpMap; + private HashMap herbalismFullyQualifiedBlockXpMap; + private HashMap woodcuttingFullyQualifiedBlockXpMap; + private HashMap excavationFullyQualifiedBlockXpMap; private double globalXpMult; public ExperienceMapManager() { - miningXpMap = new HashMap<>(); - herbalismXpMap = new HashMap<>(); - woodcuttingXpMap = new HashMap<>(); - excavationXpMap = new HashMap<>(); + miningFullyQualifiedBlockXpMap = new HashMap<>(); + herbalismFullyQualifiedBlockXpMap = new HashMap<>(); + woodcuttingFullyQualifiedBlockXpMap = new HashMap<>(); + excavationFullyQualifiedBlockXpMap = new HashMap<>(); //Register with unloader mcMMO.getConfigManager().registerUnloadable(this); } - public void buildMaterialXPMap(HashMap 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 userConfigMap, HashMap 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; } - public void setMiningXpMap(HashMap miningXpMap) { + public void resetGlobalXpMult() { + mcMMO.p.getLogger().info("Resetting the global XP multiplier "+globalXpMult+" -> "+getOriginalGlobalXpMult()); + globalXpMult = getOriginalGlobalXpMult(); + } + + public void setMiningFullyQualifiedBlockXpMap(HashMap miningFullyQualifiedBlockXpMap) { mcMMO.p.getLogger().info("Registering Mining XP Values..."); - this.miningXpMap = miningXpMap; + this.miningFullyQualifiedBlockXpMap = miningFullyQualifiedBlockXpMap; } - public void setHerbalismXpMap(HashMap herbalismXpMap) { + public void setHerbalismFullyQualifiedBlockXpMap(HashMap herbalismFullyQualifiedBlockXpMap) { mcMMO.p.getLogger().info("Registering Herbalism XP Values..."); - this.herbalismXpMap = herbalismXpMap; + this.herbalismFullyQualifiedBlockXpMap = herbalismFullyQualifiedBlockXpMap; } - public void setWoodcuttingXpMap(HashMap woodcuttingXpMap) { + public void setWoodcuttingFullyQualifiedBlockXpMap(HashMap woodcuttingFullyQualifiedBlockXpMap) { mcMMO.p.getLogger().info("Registering Woodcutting XP Values..."); - this.woodcuttingXpMap = woodcuttingXpMap; + this.woodcuttingFullyQualifiedBlockXpMap = woodcuttingFullyQualifiedBlockXpMap; } - public void setExcavationXpMap(HashMap excavationXpMap) { + public void setExcavationFullyQualifiedBlockXpMap(HashMap excavationFullyQualifiedBlockXpMap) { 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ public int getExcavationXp(Material material) { - return excavationXpMap.get(material); + return excavationFullyQualifiedBlockXpMap.get(material); } @Override public void unload() { - miningXpMap.clear(); - woodcuttingXpMap.clear(); - herbalismXpMap.clear(); - excavationXpMap.clear(); + miningFullyQualifiedBlockXpMap.clear(); + woodcuttingFullyQualifiedBlockXpMap.clear(); + herbalismFullyQualifiedBlockXpMap.clear(); + excavationFullyQualifiedBlockXpMap.clear(); } }