Cleanup some XP functions, remove unused scoreboard values, minor refactoring.

This commit is contained in:
GJ
2013-10-29 09:49:41 -04:00
parent cc2c9eb21d
commit 3be443c63c
9 changed files with 116 additions and 146 deletions

View File

@ -59,7 +59,7 @@ public class EventUtils {
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
profile.modifySkill(skill, profile.getSkillLevel(skill) - (isLevelUp ? levelsChanged : -levelsChanged));
profile.setSkillXpLevel(skill, profile.getSkillXpLevelRaw(skill) + xpRemoved);
profile.addExperience(skill, xpRemoved);
}
return !isCancelled;
@ -115,8 +115,7 @@ public class EventUtils {
boolean isCancelled = event.isCancelled();
if (!isCancelled) {
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
profile.setSkillXpLevel(skill, profile.getSkillXpLevelRaw(skill) + event.getRawXpGained());
UserManager.getPlayer(player).getProfile().addExperience(skill, event.getRawXpGained());
}
return !isCancelled;

View File

@ -13,8 +13,7 @@ import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.skills.SkillType;
public class FormulaManager {
private static String formulaFilePath = mcMMO.getFlatFileDirectory() + "formula.yml";
private static File formulaFile = new File(formulaFilePath);
private static File formulaFile = new File(mcMMO.getFlatFileDirectory() + "formula.yml");
// Experience needed to reach a level, cached values to improve conversion speed
private final Map<Integer, Integer> experienceNeededLinear = new HashMap<Integer, Integer>();
@ -115,7 +114,6 @@ public class FormulaManager {
double exponent = ExperienceConfig.getInstance().getExponent(formulaType);
switch (formulaType) {
case UNKNOWN:
case LINEAR:
if (!experienceNeededLinear.containsKey(level)) {
experience = (int) Math.floor(base + level * multiplier);
@ -146,21 +144,14 @@ public class FormulaManager {
return;
}
YamlConfiguration formulasFile = YamlConfiguration.loadConfiguration(formulaFile);
previousFormula = FormulaType.getFormulaType(formulasFile.getString("Previous_Formula", "UNKNOWN"));
previousFormula = FormulaType.getFormulaType(YamlConfiguration.loadConfiguration(formulaFile).getString("Previous_Formula", "UNKNOWN"));
}
/**
* Save formula file.
*/
public void saveFormula() {
if (formulaFile.exists()) {
formulaFile.delete();
}
YamlConfiguration formulasFile = new YamlConfiguration();
formulasFile.set("Previous_Formula", previousFormula.toString());
try {