Add + Wire DiminishingReturn config values

Removed the experience multiplier from the xp conversion task, it just
seems like something very unecessary
This commit is contained in:
nossr50 2019-05-13 02:55:20 -07:00
parent 6425cd18b8
commit 2e3f9b4a96
17 changed files with 146 additions and 55 deletions

View File

@ -138,7 +138,7 @@ Version 2.2.0
Update_Check, Prefer_Beta, Ability_Activation_Level_Gate, Max_Tries_At_Same_Location, Prevent_AFK_Leveling, Items_Pickup_Disabled_Full_Inventory
Removed the following config settings for being unwanted
Config_Update_Overwrite, Tool_Mods_Enabled, Armor_Mods_Enabled, Block_Mods_Enabled, Entity_Mods_Enabled,
Config_Update_Overwrite, Tool_Mods_Enabled, Armor_Mods_Enabled, Block_Mods_Enabled, Entity_Mods_Enabled, ExperienceConversionMultiplier
API Changes
Config settings can now be found in the ConfigManager (getter for it in mcMMO.java)
@ -150,6 +150,7 @@ Version 2.2.0
Added API method to check if player parties are size capped
Added API method to grab the level cap of a skill by its PrimarySkillType ENUM definition
Added API method to check if a skill was being level capped
Added 'UndefinedSkillBehaviour' for trying to use a method that has no behaviour defined for the provided skill
Version 2.1.58
Fixed the wrong locale string being used for Mining Double Drops

View File

@ -1092,7 +1092,7 @@ public final class ExperienceAPI {
PrimarySkillType skill = PrimarySkillType.getSkill(skillType);
if (skill == null) {
throw new InvalidSkillException();
throw new InvalidSkillException(skillType);
}
return skill;

View File

@ -3,7 +3,7 @@ package com.gmail.nossr50.api.exceptions;
public class InvalidSkillException extends RuntimeException {
private static final long serialVersionUID = 942705284195791157L;
public InvalidSkillException() {
super("That is not a valid skill.");
public InvalidSkillException(String s) {
super(s+" does not match a valid skill.");
}
}

View File

@ -0,0 +1,9 @@
package com.gmail.nossr50.api.exceptions;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
public class UndefinedSkillBehaviour extends RuntimeException {
public UndefinedSkillBehaviour(PrimarySkillType primarySkillType) {
super("Undefined behaviour for skill! - "+primarySkillType.toString());
}
}

View File

@ -50,7 +50,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
import com.google.common.collect.Maps;
import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializerCollection;
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers;

View File

@ -122,33 +122,6 @@ public class ExperienceConfig extends ConfigValidated {
config.set(EXPERIENCE_FORMULA, MULTIPLIER, GLOBAL, value);
}*/
/* Custom XP perk */
public double getCustomXpPerkBoost() {
return getDoubleValue(EXPERIENCE_FORMULA, CUSTOM_XP_PERK, BOOST);
}
/* Diminished Returns */
public float getDiminishedReturnsCap() {
return (float) getDoubleValue(DIMISHED_RETURNS, GUARANTEED_MINIMUM_PERCENTAGE);
}
public boolean getDiminishedReturnsEnabled() {
return getBooleanValue(DIMINISHED_RETURNS, ENABLED);
}
public int getDiminishedReturnsThreshold(PrimarySkillType skill) {
return getIntValue(DIMINISHED_RETURNS, THRESHOLD, StringUtils.getCapitalized(skill.toString()));
}
public int getDiminishedReturnsTimeInterval() {
return getIntValue(DIMINISHED_RETURNS, TIME_INTERVAL);
}
/* Conversion */
public double getExpModifier() {
return getDoubleValue(CONVERSION, EXP + MODIFIER);
}
/*
* XP SETTINGS
*/

View File

@ -64,7 +64,7 @@ public class CustomXPPerkSerializer implements TypeSerializer<CustomXPPerk> {
return primarySkillType;
}
throw new InvalidSkillException();
throw new InvalidSkillException(string);
}
/*

View File

@ -1,10 +1,14 @@
package com.gmail.nossr50.config.hocon.playerleveling;
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
import java.util.HashMap;
@ConfigSerializable
public class ConfigLeveling {
@ -27,10 +31,37 @@ public class ConfigLeveling {
@Setting(value = "Experience-Formula")
private ConfigExperienceFormula configExperienceFormula = new ConfigExperienceFormula();
@Setting(value = "Diminished-Returns", comment = "Penalize players for gaining XP too quickly in a given time period.")
private ConfigLevelingDiminishedReturns configLevelingDiminishedReturns = new ConfigLevelingDiminishedReturns();
/*
* GETTER BOILERPLATE
*/
public float getGuaranteedMinimums() {
return configLevelingDiminishedReturns.getGuaranteedMinimums();
}
public boolean isDiminishedReturnsEnabled() {
return configLevelingDiminishedReturns.isDiminishedReturnsEnabled();
}
public int getDimishedReturnTimeInterval() {
return configLevelingDiminishedReturns.getDimishedReturnTimeInterval();
}
public HashMap<PrimarySkillType, Integer> getSkillThresholds() {
return configLevelingDiminishedReturns.getSkillThresholds();
}
public int getSkillThreshold(PrimarySkillType primarySkillType) {
return configLevelingDiminishedReturns.getSkillThreshold(primarySkillType);
}
public ConfigLevelingDiminishedReturns getConfigLevelingDiminishedReturns() {
return configLevelingDiminishedReturns;
}
public double getSkillXpFormulaModifier(PrimarySkillType primarySkillType) {
return getConfigExperienceFormula().getSkillXpFormulaModifier(primarySkillType);
}
@ -152,6 +183,7 @@ public class ConfigLeveling {
case SALVAGE:
return configSectionLevelCaps.getConfigSectionSkillLevelCaps().getSalvage().getLevelCap();
default:
mcMMO.p.getLogger().severe("No defined level cap for "+primarySkillType.toString()+" - Contact the mcMMO dev team!");
return Integer.MAX_VALUE;
}
}
@ -189,6 +221,7 @@ public class ConfigLeveling {
case SALVAGE:
return configSectionLevelCaps.getConfigSectionSkillLevelCaps().getSalvage().isLevelCapEnabled();
default:
mcMMO.p.getLogger().severe("No defined level cap for "+primarySkillType.toString()+" - Contact the mcMMO dev team!");
return false;
}
}

View File

@ -0,0 +1,86 @@
package com.gmail.nossr50.config.hocon.playerleveling;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
import java.util.HashMap;
import static com.gmail.nossr50.datatypes.skills.PrimarySkillType.*;
@ConfigSerializable
public class ConfigLevelingDiminishedReturns {
/*
Diminished_Returns:
#This is the minimum amount of XP a player will earn after reaching the timed threshold (this is to prevent punishing a player too hard for earning XP)
## A value of 1 would mean that a player gets FULL XP, which defeats the purpose of diminished returns, the default value is 0.05 (5% minimum XP)
### Set this value to 0 to turn it off
Guaranteed_Minimum_Percentage: 0.05
Enabled: false
*/
private static final HashMap<PrimarySkillType, Integer> SKILL_THRESHOLDS_DEFAULT;
public static final float GURANTEED_MIN_DEFAULT = 0.05f;
static {
SKILL_THRESHOLDS_DEFAULT = new HashMap<>();
SKILL_THRESHOLDS_DEFAULT.put(ACROBATICS, 10000);
SKILL_THRESHOLDS_DEFAULT.put(ALCHEMY, 10000);
SKILL_THRESHOLDS_DEFAULT.put(ARCHERY, 10000);
SKILL_THRESHOLDS_DEFAULT.put(AXES, 10000);
SKILL_THRESHOLDS_DEFAULT.put(EXCAVATION, 10000);
SKILL_THRESHOLDS_DEFAULT.put(FISHING, 10000);
SKILL_THRESHOLDS_DEFAULT.put(HERBALISM, 10000);
SKILL_THRESHOLDS_DEFAULT.put(MINING, 10000);
SKILL_THRESHOLDS_DEFAULT.put(REPAIR, 10000);
SKILL_THRESHOLDS_DEFAULT.put(SWORDS, 10000);
SKILL_THRESHOLDS_DEFAULT.put(TAMING, 10000);
SKILL_THRESHOLDS_DEFAULT.put(UNARMED, 10000);
SKILL_THRESHOLDS_DEFAULT.put(WOODCUTTING, 10000);
}
private static final boolean DIMINISHED_RETURNS_DEFAULT = false;
private static final int DIMINISHED_TIME_DEFAULT = 10;
@Setting(value = "Enabled", comment = "Setting this to true will enable Diminished Returns on XP Gains." +
"\nDefault value: "+DIMINISHED_RETURNS_DEFAULT)
private boolean diminishedReturnsEnabled = DIMINISHED_RETURNS_DEFAULT;
@Setting(value = "Time-Interval-In-Minutes", comment = "The period of time in which to measure a players XP gain and reduce gains above a threshold during that time" +
"\nPlayers will be able to gain up to the threshold of XP in this time period before having their XP drastically reduced" +
"\nDefault value: "+DIMINISHED_TIME_DEFAULT)
private int dimishedReturnTimeInterval = DIMINISHED_TIME_DEFAULT;
@Setting(value = "Skill-Thresholds", comment = "The amount of XP that a player can gain without penalty in the defined time interval." +
"\nDefault value: 10000 for each skill, undefined skills will default to this value")
private HashMap<PrimarySkillType, Integer> skillThresholds = SKILL_THRESHOLDS_DEFAULT;
@Setting(value = "Guaranteed-Minimum", comment = "The multiplier applied to an XP gain when a player has reached diminishing returns to guarantee that some XP is still gained." +
"\nPlayers will gain (raw XP * guaranteedMinimum) if they are under sever enough diminishing return penalty (ie their XP would normally fall below this value)" +
"\nDefault value: ")
private float guaranteedMinimums = GURANTEED_MIN_DEFAULT;
public int getSkillThreshold(PrimarySkillType primarySkillType) {
if(skillThresholds.get(primarySkillType) == null)
return 10000;
return skillThresholds.get(primarySkillType);
}
public float getGuaranteedMinimums() {
return guaranteedMinimums;
}
public boolean isDiminishedReturnsEnabled() {
return diminishedReturnsEnabled;
}
public int getDimishedReturnTimeInterval() {
return dimishedReturnTimeInterval;
}
public HashMap<PrimarySkillType, Integer> getSkillThresholds() {
return skillThresholds;
}
}

View File

@ -5,12 +5,7 @@ import com.gmail.nossr50.config.ConfigConstants;
import com.gmail.nossr50.config.UnsafeValueValidation;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.mcMMO;
import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import org.bukkit.Material;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

View File

@ -5,12 +5,6 @@ import com.gmail.nossr50.config.ConfigConstants;
import com.gmail.nossr50.config.UnsafeValueValidation;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.StringUtils;
import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import org.bukkit.Material;
import org.bukkit.Tag;
import java.util.ArrayList;
import java.util.HashMap;

View File

@ -46,6 +46,7 @@ public class BonusDropManager {
for (String material : materials) {
Material m = Material.matchMaterial(material);
if (m == null) {
//TODO: reduce to info level?
mcMMO.p.getLogger().severe("Error registering Bonus Drop -- Invalid Minecraft Name ID: " + material);
continue;
}

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.datatypes.experience;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
@ -18,7 +19,7 @@ public class SkillXpGain implements Delayed {
}
private static long getDuration() {
return TimeUnit.MINUTES.toMillis(ExperienceConfig.getInstance().getDiminishedReturnsTimeInterval());
return TimeUnit.MINUTES.toMillis(mcMMO.getConfigManager().getConfigLeveling().getDimishedReturnTimeInterval());
}
public PrimarySkillType getSkill() {

View File

@ -99,9 +99,9 @@ public class SelfListener implements Listener {
}
}
int threshold = ExperienceConfig.getInstance().getDiminishedReturnsThreshold(primarySkillType);
int threshold = mcMMO.getConfigManager().getConfigLeveling().getSkillThreshold(primarySkillType);
if (threshold <= 0 || !ExperienceConfig.getInstance().getDiminishedReturnsEnabled()) {
if (threshold <= 0 || !mcMMO.getConfigManager().getConfigLeveling().getConfigLevelingDiminishedReturns().isDiminishedReturnsEnabled()) {
// Diminished returns is turned off
return;
}
@ -117,7 +117,7 @@ public class SelfListener implements Listener {
final float rawXp = event.getRawXpGained();
float guaranteedMinimum = ExperienceConfig.getInstance().getDiminishedReturnsCap() * rawXp;
float guaranteedMinimum = mcMMO.getConfigManager().getConfigLeveling().getGuaranteedMinimums() * rawXp;
float modifiedThreshold = (float) (threshold / primarySkillType.getXpModifier() * mcMMO.getDynamicSettingsManager().getExperienceMapManager().getGlobalXpMult());
float difference = (mcMMOPlayer.getProfile().getRegisteredXpGain(primarySkillType) - modifiedThreshold) / modifiedThreshold;

View File

@ -51,7 +51,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
public class mcMMO extends JavaPlugin {
public static mcMMO p;
@ -564,7 +563,7 @@ public class mcMMO extends JavaPlugin {
new PowerLevelUpdatingTask().runTaskTimer(this, 2 * Misc.TICK_CONVERSION_FACTOR, 2 * Misc.TICK_CONVERSION_FACTOR);
// Clear the registered XP data so players can earn XP again
if (ExperienceConfig.getInstance().getDiminishedReturnsEnabled()) {
if (mcMMO.getConfigManager().getConfigExperience().get) {
new ClearRegisteredXPGainTask().runTaskTimer(this, 60, 60);
}

View File

@ -66,7 +66,7 @@ public class FormulaConversionTask extends BukkitRunnable {
continue;
}
int[] newExperienceValues = mcMMO.getFormulaManager().calculateNewLevel(primarySkillType, (int) Math.floor(totalOldXP / ExperienceConfig.getInstance().getExpModifier()), formulaType);
int[] newExperienceValues = mcMMO.getFormulaManager().calculateNewLevel(primarySkillType, (int) Math.floor(totalOldXP / 1.0), formulaType);
int newLevel = newExperienceValues[0];
int newXPlevel = newExperienceValues[1];

View File

@ -1,6 +1,6 @@
package com.gmail.nossr50.util.experience;
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
import com.gmail.nossr50.api.exceptions.UndefinedSkillBehaviour;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import org.bukkit.Material;
@ -193,11 +193,11 @@ public class ExperienceMapManager {
* @param primarySkillType target skill
* @param material target material
* @return XP value for breaking this block for said skill
* @throws InvalidSkillException for skills that don't give block break experience
* @throws UndefinedSkillBehaviour for skills that don't give block break experience
* @deprecated its faster to use direct calls to get XP, for example getMiningXP(Material material) instead of using this method
*/
@Deprecated
public float getBlockBreakXpValue(PrimarySkillType primarySkillType, Material material) throws InvalidSkillException {
public float getBlockBreakXpValue(PrimarySkillType primarySkillType, Material material) throws UndefinedSkillBehaviour {
switch (primarySkillType) {
case MINING:
return getMiningXp(material);
@ -208,7 +208,7 @@ public class ExperienceMapManager {
case WOODCUTTING:
return getWoodcuttingXp(material);
default:
throw new InvalidSkillException();
throw new UndefinedSkillBehaviour(primarySkillType);
}
}