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

@ -54,30 +54,30 @@ public final class AbilityAPI {
} }
public static void setBerserkCooldown(Player player, long cooldown) { public static void setBerserkCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.BERSERK, cooldown); UserManager.getPlayer(player).getProfile().setAbilityDATS(AbilityType.BERSERK, cooldown);
} }
public static void setGigaDrillBreakerCooldown(Player player, long cooldown) { public static void setGigaDrillBreakerCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.GIGA_DRILL_BREAKER, cooldown); UserManager.getPlayer(player).getProfile().setAbilityDATS(AbilityType.GIGA_DRILL_BREAKER, cooldown);
} }
public static void setGreenTerraCooldown(Player player, long cooldown) { public static void setGreenTerraCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.GREEN_TERRA, cooldown); UserManager.getPlayer(player).getProfile().setAbilityDATS(AbilityType.GREEN_TERRA, cooldown);
} }
public static void setSerratedStrikesCooldown(Player player, long cooldown) { public static void setSerratedStrikesCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.SERRATED_STRIKES, cooldown); UserManager.getPlayer(player).getProfile().setAbilityDATS(AbilityType.SERRATED_STRIKES, cooldown);
} }
public static void setSkullSplitterCooldown(Player player, long cooldown) { public static void setSkullSplitterCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.SKULL_SPLITTER, cooldown); UserManager.getPlayer(player).getProfile().setAbilityDATS(AbilityType.SKULL_SPLITTER, cooldown);
} }
public static void setSuperBreakerCooldown(Player player, long cooldown) { public static void setSuperBreakerCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.SUPER_BREAKER, cooldown); UserManager.getPlayer(player).getProfile().setAbilityDATS(AbilityType.SUPER_BREAKER, cooldown);
} }
public static void setTreeFellerCooldown(Player player, long cooldown) { public static void setTreeFellerCooldown(Player player, long cooldown) {
UserManager.getPlayer(player).getProfile().setSkillDATS(AbilityType.TREE_FELLER, cooldown); UserManager.getPlayer(player).getProfile().setAbilityDATS(AbilityType.TREE_FELLER, cooldown);
} }
} }

View File

@ -582,18 +582,7 @@ public final class ExperienceAPI {
private static void addOfflineXP(String playerName, SkillType skill, int XP) { private static void addOfflineXP(String playerName, SkillType skill, int XP) {
PlayerProfile profile = getOfflineProfile(playerName); PlayerProfile profile = getOfflineProfile(playerName);
if (skill.isChildSkill()) { profile.addExperience(skill, XP);
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
for (SkillType parentSkill : parentSkills) {
profile.setSkillXpLevel(parentSkill, profile.getSkillLevel(parentSkill) + (XP / parentSkills.size()));
}
profile.save();
return;
}
profile.setSkillXpLevel(skill, profile.getSkillXpLevel(skill) + XP);
profile.save(); profile.save();
} }

View File

@ -251,17 +251,17 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
writer.append(":"); writer.append(":");
writer.append(profile.getSkillLevel(SkillType.TAMING)).append(":"); writer.append(profile.getSkillLevel(SkillType.TAMING)).append(":");
writer.append(profile.getSkillXpLevel(SkillType.TAMING)).append(":"); writer.append(profile.getSkillXpLevel(SkillType.TAMING)).append(":");
writer.append((int) profile.getSkillDATS(AbilityType.BERSERK)).append(":"); writer.append((int) profile.getAbilityDATS(AbilityType.BERSERK)).append(":");
writer.append((int) profile.getSkillDATS(AbilityType.GIGA_DRILL_BREAKER)).append(":"); writer.append((int) profile.getAbilityDATS(AbilityType.GIGA_DRILL_BREAKER)).append(":");
writer.append((int) profile.getSkillDATS(AbilityType.TREE_FELLER)).append(":"); writer.append((int) profile.getAbilityDATS(AbilityType.TREE_FELLER)).append(":");
writer.append((int) profile.getSkillDATS(AbilityType.GREEN_TERRA)).append(":"); writer.append((int) profile.getAbilityDATS(AbilityType.GREEN_TERRA)).append(":");
writer.append((int) profile.getSkillDATS(AbilityType.SERRATED_STRIKES)).append(":"); writer.append((int) profile.getAbilityDATS(AbilityType.SERRATED_STRIKES)).append(":");
writer.append((int) profile.getSkillDATS(AbilityType.SKULL_SPLITTER)).append(":"); writer.append((int) profile.getAbilityDATS(AbilityType.SKULL_SPLITTER)).append(":");
writer.append((int) profile.getSkillDATS(AbilityType.SUPER_BREAKER)).append(":"); writer.append((int) profile.getAbilityDATS(AbilityType.SUPER_BREAKER)).append(":");
writer.append(":"); writer.append(":");
writer.append(profile.getSkillLevel(SkillType.FISHING)).append(":"); writer.append(profile.getSkillLevel(SkillType.FISHING)).append(":");
writer.append(profile.getSkillXpLevel(SkillType.FISHING)).append(":"); writer.append(profile.getSkillXpLevel(SkillType.FISHING)).append(":");
writer.append((int) profile.getSkillDATS(AbilityType.BLAST_MINING)).append(":"); writer.append((int) profile.getAbilityDATS(AbilityType.BLAST_MINING)).append(":");
writer.append(System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR).append(":"); writer.append(System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR).append(":");
MobHealthbarType mobHealthbarType = profile.getMobHealthbarType(); MobHealthbarType mobHealthbarType = profile.getMobHealthbarType();
writer.append(mobHealthbarType == null ? Config.getInstance().getMobHealthbarDefault().toString() : mobHealthbarType.toString()).append(":"); writer.append(mobHealthbarType == null ? Config.getInstance().getMobHealthbarDefault().toString() : mobHealthbarType.toString()).append(":");

View File

@ -139,14 +139,14 @@ public final class SQLDatabaseManager implements DatabaseManager {
+ ", herbalism = ?, excavation = ?, swords = ?" + ", herbalism = ?, excavation = ?, swords = ?"
+ ", axes = ?, blast_mining = ? WHERE user_id = ?", + ", axes = ?, blast_mining = ? WHERE user_id = ?",
userId, userId,
profile.getSkillDATS(AbilityType.SUPER_BREAKER), profile.getAbilityDATS(AbilityType.SUPER_BREAKER),
profile.getSkillDATS(AbilityType.TREE_FELLER), profile.getAbilityDATS(AbilityType.TREE_FELLER),
profile.getSkillDATS(AbilityType.BERSERK), profile.getAbilityDATS(AbilityType.BERSERK),
profile.getSkillDATS(AbilityType.GREEN_TERRA), profile.getAbilityDATS(AbilityType.GREEN_TERRA),
profile.getSkillDATS(AbilityType.GIGA_DRILL_BREAKER), profile.getAbilityDATS(AbilityType.GIGA_DRILL_BREAKER),
profile.getSkillDATS(AbilityType.SERRATED_STRIKES), profile.getAbilityDATS(AbilityType.SERRATED_STRIKES),
profile.getSkillDATS(AbilityType.SKULL_SPLITTER), profile.getAbilityDATS(AbilityType.SKULL_SPLITTER),
profile.getSkillDATS(AbilityType.BLAST_MINING)); profile.getAbilityDATS(AbilityType.BLAST_MINING));
success &= saveIntegers( success &= saveIntegers(
"UPDATE " + tablePrefix + "skills SET " "UPDATE " + tablePrefix + "skills SET "
+ " taming = ?, mining = ?, repair = ?, woodcutting = ?" + " taming = ?, mining = ?, repair = ?, woodcutting = ?"

View File

@ -538,31 +538,29 @@ public class McMMOPlayer {
* @param skillType The skill to check * @param skillType The skill to check
*/ */
private void checkXp(SkillType skillType) { private void checkXp(SkillType skillType) {
if (profile.getSkillXpLevelRaw(skillType) < profile.getXpToLevel(skillType)) {
return;
}
int levelsGained = 0; int levelsGained = 0;
float xpRemoved = 0; float xpRemoved = 0;
if (profile.getSkillXpLevelRaw(skillType) >= profile.getXpToLevel(skillType)) { while (profile.getSkillXpLevelRaw(skillType) >= profile.getXpToLevel(skillType)) {
while (profile.getSkillXpLevelRaw(skillType) >= profile.getXpToLevel(skillType)) { if (hasReachedLevelCap(skillType)) {
if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Config.getInstance().getPowerLevelCap() >= getPowerLevel() + 1)) { profile.setSkillXpLevel(skillType, 0);
int xp = profile.getXpToLevel(skillType); break;
xpRemoved += xp;
profile.removeXp(skillType, xp);
levelsGained++;
profile.skillUp(skillType, 1);
}
else {
profile.addLevels(skillType, 0); // This seems kinda pointless... why do we have this again?
}
} }
if (!EventUtils.handleLevelChangeEvent(player, skillType, levelsGained, xpRemoved, true)) { xpRemoved += profile.levelUp(skillType);
return; levelsGained++;
}
player.playSound(player.getLocation(), Sound.LEVEL_UP, Misc.LEVELUP_VOLUME, Misc.LEVELUP_PITCH);
player.sendMessage(LocaleLoader.getString(StringUtils.getCapitalized(skillType.toString()) + ".Skillup", levelsGained, profile.getSkillLevel(skillType)));
} }
if (!EventUtils.handleLevelChangeEvent(player, skillType, levelsGained, xpRemoved, true)) {
return;
}
player.playSound(player.getLocation(), Sound.LEVEL_UP, Misc.LEVELUP_VOLUME, Misc.LEVELUP_PITCH);
player.sendMessage(LocaleLoader.getString(StringUtils.getCapitalized(skillType.toString()) + ".Skillup", levelsGained, profile.getSkillLevel(skillType)));
} }
/* /*
@ -749,7 +747,7 @@ public class McMMOPlayer {
SkillUtils.sendSkillMessage(player, ability.getAbilityPlayer(player)); SkillUtils.sendSkillMessage(player, ability.getAbilityPlayer(player));
// Enable the ability // Enable the ability
profile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR)); profile.setAbilityDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
setAbilityMode(ability, true); setAbilityMode(ability, true);
if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) { if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) {
@ -815,7 +813,11 @@ public class McMMOPlayer {
* @return the number of seconds remaining before the cooldown expires * @return the number of seconds remaining before the cooldown expires
*/ */
public int calculateTimeRemaining(AbilityType ability) { public int calculateTimeRemaining(AbilityType ability) {
long deactivatedTimestamp = profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR; long deactivatedTimestamp = profile.getAbilityDATS(ability) * Misc.TIME_CONVERSION_FACTOR;
return (int) (((deactivatedTimestamp + (PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR); return (int) (((deactivatedTimestamp + (PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR);
} }
private boolean hasReachedLevelCap(SkillType skill) {
return (skill.getMaxLevel() < profile.getSkillLevel(skill) + 1) || (Config.getInstance().getPowerLevelCap() < getPowerLevel() + 1);
}
} }

View File

@ -4,8 +4,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.bukkit.scoreboard.Scoreboard;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
@ -23,20 +21,19 @@ public class PlayerProfile {
/* HUDs */ /* HUDs */
private MobHealthbarType mobHealthbarType; private MobHealthbarType mobHealthbarType;
private Scoreboard playerStatsScoreboard;
/* Skill Data */ /* Skill Data */
private final Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); // Skill & Level private final Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); // Skill & Level
private final Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP private final Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP
private final Map<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown private final Map<AbilityType, Integer> abilityDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
public PlayerProfile(String playerName) { public PlayerProfile(String playerName) {
this.playerName = playerName; this.playerName = playerName;
mobHealthbarType = Config.getInstance().getMobHealthbarDefault(); mobHealthbarType = Config.getInstance().getMobHealthbarDefault();
for (AbilityType abilityType : AbilityType.values()) { for (AbilityType abilityType : AbilityType.NORMAL_ABILITIES) {
skillsDATS.put(abilityType, 0); abilityDATS.put(abilityType, 0);
} }
for (SkillType skillType : SkillType.NON_CHILD_SKILLS) { for (SkillType skillType : SkillType.NON_CHILD_SKILLS) {
@ -54,13 +51,12 @@ public class PlayerProfile {
* Calling this constructor is considered loading the profile. * Calling this constructor is considered loading the profile.
*/ */
public PlayerProfile(String playerName, Map<SkillType, Integer> argSkills, Map<SkillType, Float> argSkillsXp, Map<AbilityType, Integer> argSkillsDats, MobHealthbarType mobHealthbarType) { public PlayerProfile(String playerName, Map<SkillType, Integer> argSkills, Map<SkillType, Float> argSkillsXp, Map<AbilityType, Integer> argSkillsDats, MobHealthbarType mobHealthbarType) {
this(playerName); this.playerName = playerName;
this.mobHealthbarType = mobHealthbarType; this.mobHealthbarType = mobHealthbarType;
this.skills.putAll(argSkills); skills.putAll(argSkills);
this.skillsXp.putAll(argSkillsXp); skillsXp.putAll(argSkillsXp);
this.skillsDATS.putAll(argSkillsDats); abilityDATS.putAll(argSkillsDats);
loaded = true; loaded = true;
} }
@ -71,6 +67,7 @@ public class PlayerProfile {
} }
changed = !mcMMO.getDatabaseManager().saveUser(this); changed = !mcMMO.getDatabaseManager().saveUser(this);
if (changed) { if (changed) {
mcMMO.p.getLogger().warning("PlayerProfile for " + playerName + " failed to save"); mcMMO.p.getLogger().warning("PlayerProfile for " + playerName + " failed to save");
} }
@ -96,54 +93,40 @@ public class PlayerProfile {
this.mobHealthbarType = mobHealthbarType; this.mobHealthbarType = mobHealthbarType;
} }
/*
* Scoreboards
*/
public Scoreboard getPlayerStatsScoreboard() {
return playerStatsScoreboard;
}
public void setPlayerStatsScoreboard(Scoreboard statsScoreboard) {
this.playerStatsScoreboard = statsScoreboard;
}
/* /*
* Cooldowns * Cooldowns
*/ */
/** /**
* Get the current DATS of a skill. * Get the current deactivation timestamp of an ability.
* *
* @param abilityType Ability to get the DATS for * @param ability The {@link AbilityType} to get the DATS for
* @return the DATS for the ability * @return the deactivation timestamp for the ability
*/ */
public long getSkillDATS(AbilityType abilityType) { public long getAbilityDATS(AbilityType ability) {
return skillsDATS.get(abilityType); return abilityDATS.get(ability);
} }
/** /**
* Set the current DATS of a skill. * Set the current deactivation timestamp of an ability.
* *
* @param abilityType Ability to set the DATS for * @param ability The {@link AbilityType} to set the DATS for
* @param DATS the DATS of the ability * @param DATS the DATS of the ability
*/ */
public void setSkillDATS(AbilityType abilityType, long DATS) { public void setAbilityDATS(AbilityType ability, long DATS) {
int wearsOff = (int) (DATS * .001D);
changed = true; changed = true;
skillsDATS.put(abilityType, wearsOff); abilityDATS.put(ability, (int) (DATS * .001D));
} }
/** /**
* Reset all skill cooldowns. * Reset all ability cooldowns.
*/ */
public void resetCooldowns() { public void resetCooldowns() {
changed = true; changed = true;
for (AbilityType ability : skillsDATS.keySet()) { for (AbilityType ability : abilityDATS.keySet()) {
skillsDATS.put(ability, 0); abilityDATS.put(ability, 0);
} }
} }
@ -151,96 +134,102 @@ public class PlayerProfile {
* Xp Functions * Xp Functions
*/ */
public int getSkillLevel(SkillType skillType) { public int getSkillLevel(SkillType skill) {
return skillType.isChildSkill() ? getChildSkillLevel(skillType) : skills.get(skillType); return skill.isChildSkill() ? getChildSkillLevel(skill) : skills.get(skill);
} }
public float getSkillXpLevelRaw(SkillType skillType) { public float getSkillXpLevelRaw(SkillType skill) {
return skillsXp.get(skillType); return skillsXp.get(skill);
} }
public int getSkillXpLevel(SkillType skillType) { public int getSkillXpLevel(SkillType skill) {
return (int) Math.floor(getSkillXpLevelRaw(skillType)); return (int) Math.floor(getSkillXpLevelRaw(skill));
} }
public void setSkillXpLevel(SkillType skillType, float newValue) { public void setSkillXpLevel(SkillType skill, float xpLevel) {
if (skillType.isChildSkill()) { if (skill.isChildSkill()) {
return; return;
} }
changed = true; changed = true;
skillsXp.put(skillType, newValue); skillsXp.put(skill, xpLevel);
} }
public void skillUp(SkillType skillType, int newValue) { public float levelUp(SkillType skill) {
skills.put(skillType, skills.get(skillType) + newValue); float xpRemoved = getXpToLevel(skill);
changed = true;
skills.put(skill, skills.get(skill) + 1);
skillsXp.put(skill, skillsXp.get(skill) - xpRemoved);
return xpRemoved;
} }
/** /**
* Remove Xp from a skill. * Remove Xp from a skill.
* *
* @param skillType Type of skill to modify * @param skill Type of skill to modify
* @param xp Amount of xp to remove * @param xp Amount of xp to remove
*/ */
public void removeXp(SkillType skillType, int xp) { public void removeXp(SkillType skill, int xp) {
if (skillType.isChildSkill()) { if (skill.isChildSkill()) {
return; return;
} }
changed = true; changed = true;
skillsXp.put(skillType, skillsXp.get(skillType) - xp); skillsXp.put(skill, skillsXp.get(skill) - xp);
} }
/** /**
* Modify a skill level. * Modify a skill level.
* *
* @param skillType Type of skill to modify * @param skill Type of skill to modify
* @param newValue New level value for the skill * @param level New level value for the skill
*/ */
public void modifySkill(SkillType skillType, int newValue) { public void modifySkill(SkillType skill, int level) {
if (skillType.isChildSkill()) { if (skill.isChildSkill()) {
return; return;
} }
changed = true; changed = true;
skills.put(skillType, newValue); skills.put(skill, level);
skillsXp.put(skillType, 0F); skillsXp.put(skill, 0F);
} }
/** /**
* Add levels to a skill. * Add levels to a skill.
* *
* @param skillType Type of skill to add levels to * @param skill Type of skill to add levels to
* @param levels Number of levels to add * @param levels Number of levels to add
*/ */
public void addLevels(SkillType skillType, int levels) { public void addLevels(SkillType skill, int levels) {
if (skillType.isChildSkill()) { modifySkill(skill, skills.get(skill) + levels);
return;
}
changed = true;
skills.put(skillType, skills.get(skillType) + levels);
skillsXp.put(skillType, 0F);
} }
/** /**
* Add Experience to a skill. * Add Experience to a skill.
* *
* @param skillType Type of skill to add experience to * @param skill Type of skill to add experience to
* @param experience Number of experience to add * @param experience Number of experience to add
*/ */
public void addExperience(SkillType skillType, int experience) { public void addExperience(SkillType skill, float experience) {
if (skillType.isChildSkill()) {
return;
}
changed = true; changed = true;
skillsXp.put(skillType, skillsXp.get(skillType) + experience); if (skill.isChildSkill()) {
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
float dividedXP = (experience / parentSkills.size());
for (SkillType parentSkill : parentSkills) {
skillsXp.put(parentSkill, skillsXp.get(parentSkill) + dividedXP);
}
}
else {
skillsXp.put(skill, skillsXp.get(skill) + experience);
}
} }
/** /**

View File

@ -108,7 +108,7 @@ public class MiningManager extends SkillManager {
tnt.setFuseTicks(0); tnt.setFuseTicks(0);
targetBlock.setType(Material.AIR); targetBlock.setType(Material.AIR);
getProfile().setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis()); getProfile().setAbilityDATS(AbilityType.BLAST_MINING, System.currentTimeMillis());
mcMMOPlayer.setAbilityInformed(AbilityType.BLAST_MINING, false); mcMMOPlayer.setAbilityInformed(AbilityType.BLAST_MINING, false);
new AbilityCooldownTask(mcMMOPlayer, AbilityType.BLAST_MINING).runTaskLaterAsynchronously(mcMMO.p, AbilityType.BLAST_MINING.getCooldown() * Misc.TICK_CONVERSION_FACTOR); new AbilityCooldownTask(mcMMOPlayer, AbilityType.BLAST_MINING).runTaskLaterAsynchronously(mcMMO.p, AbilityType.BLAST_MINING.getCooldown() * Misc.TICK_CONVERSION_FACTOR);
} }

View File

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

View File

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