mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-26 18:47:57 +01:00
Create fully qualified name : integer maps from user configs, wiring up some global xp settings
This commit is contained in:
parent
faed690602
commit
6932abc9d8
@ -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'
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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()) {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -12,26 +12,73 @@ import java.util.HashMap;
|
||||
*/
|
||||
public class ExperienceMapManager implements Unload {
|
||||
private HashMap<PrimarySkillType, HashMap<Material, String>> skillMaterialXPMap;
|
||||
private HashMap<String, Integer> miningXpMap;
|
||||
private HashMap<String, Integer> herbalismXpMap;
|
||||
private HashMap<String, Integer> woodcuttingXpMap;
|
||||
private HashMap<String, Integer> excavationXpMap;
|
||||
private HashMap<String, Integer> miningFullyQualifiedBlockXpMap;
|
||||
private HashMap<String, Integer> herbalismFullyQualifiedBlockXpMap;
|
||||
private HashMap<String, Integer> woodcuttingFullyQualifiedBlockXpMap;
|
||||
private HashMap<String, Integer> 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<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;
|
||||
}
|
||||
|
||||
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...");
|
||||
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...");
|
||||
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...");
|
||||
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...");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user