Still some work to do, but now the convert XP command is less clunky

This commit is contained in:
nossr50 2019-05-30 16:12:32 -07:00
parent 84b9b255aa
commit 1532791c3f
6 changed files with 31 additions and 42 deletions

View File

@ -16,31 +16,31 @@ public class ConvertExperienceCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (args.length) { switch (args.length) {
case 2: case 2:
FormulaType previousType = mcMMO.getFormulaManager().getPreviousFormulaType();
FormulaType newType = FormulaType.getFormulaType(args[1].toUpperCase());
if (newType == FormulaType.UNKNOWN) {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Invalid"));
return true;
}
if (previousType == newType) { for(FormulaType formulaType : FormulaType.values()) {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Same", newType.toString())); if(formulaType.toString().equalsIgnoreCase(args[1])) {
return true; FormulaType previousType = formulaType;
}
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Start", previousType.toString(), newType.toString())); sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Start", previousType.toString(), mcMMO.getConfigManager().getConfigLeveling().getFormulaType().toString()));
UserManager.saveAll(); UserManager.saveAll();
UserManager.clearAll(); UserManager.clearAll();
new FormulaConversionTask(sender, newType).runTaskLater(mcMMO.p, 1); new FormulaConversionTask(sender, previousType).runTaskLater(mcMMO.p, 1);
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) { for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
} }
return true; return true;
}
}
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Invalid"));
return true;
default: default:
return false; return false;

View File

@ -28,18 +28,6 @@ public class ConfigSectionPartyLevel {
PARTY_FEATURE_MAP_DEFAULT.put(PartyFeature.CHAT, PARTY_CHAT_DEFAULT); PARTY_FEATURE_MAP_DEFAULT.put(PartyFeature.CHAT, PARTY_CHAT_DEFAULT);
} }
/*
int base = ExperienceConfig.getInstance().getBase(FormulaType.EXPONENTIAL);
double multiplier = ExperienceConfig.getInstance().getMultiplier(FormulaType.EXPONENTIAL);
double exponent = ExperienceConfig.getInstance().getExponent(FormulaType.EXPONENTIAL);
if (!experienceNeededExponential.containsKey(level)) {
experience = (int) Math.floor((multiplier * Math.pow(level, exponent) + base));
experience *= mcMMO.getConfigManager().getConfigParty().getPartyXP().getPartyLevel().getPartyXpCurveMultiplier();
experienceNeededExponential.put(level, experience);
}
*/
@Setting(value = "Party-Leveling-Requires-Nearby-Party-Members", @Setting(value = "Party-Leveling-Requires-Nearby-Party-Members",
comment = "If leveling your Party requires being near another party member." + comment = "If leveling your Party requires being near another party member." +
"\nDefault value: " + PARTY_LEVELING_NEEDS_NERBY_MEMBERS_DEFAULT) "\nDefault value: " + PARTY_LEVELING_NEEDS_NERBY_MEMBERS_DEFAULT)

View File

@ -205,8 +205,6 @@ public class mcMMO extends JavaPlugin {
if (getScoreboardSettings().getScoreboardsEnabled()) if (getScoreboardSettings().getScoreboardsEnabled())
ScoreboardManager.teardownAll(); ScoreboardManager.teardownAll();
formulaManager.saveFormula();
/*holidayManager.saveAnniversaryFiles();*/
placeStore.saveAll(); // Save our metadata placeStore.saveAll(); // Save our metadata
placeStore.cleanUp(); // Cleanup empty metadata stores placeStore.cleanUp(); // Cleanup empty metadata stores
} catch (Exception e) { } catch (Exception e) {

View File

@ -49,7 +49,7 @@ public class FormulaConversionTask extends BukkitRunnable {
Misc.printProgress(convertedUsers, DatabaseManager.progressInterval, startMillis); Misc.printProgress(convertedUsers, DatabaseManager.progressInterval, startMillis);
} }
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Finish", previousFormula.toString())); sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Finish", mcMMO.getConfigManager().getConfigLeveling().getConfigExperienceFormula().toString()));
} }
private void editValues(PlayerProfile profile) { private void editValues(PlayerProfile profile) {
@ -64,7 +64,7 @@ public class FormulaConversionTask extends BukkitRunnable {
continue; continue;
} }
int[] newExperienceValues = mcMMO.getFormulaManager().calculateNewLevel(primarySkillType, (int) Math.floor(totalOldXP / 1.0), previousFormula); int[] newExperienceValues = mcMMO.getFormulaManager().calculateNewLevel(primarySkillType, (int) Math.floor(totalOldXP / 1.0));
int newLevel = newExperienceValues[0]; int newLevel = newExperienceValues[0];
int newXPlevel = newExperienceValues[1]; int newXPlevel = newExperienceValues[1];

View File

@ -59,16 +59,15 @@ public class FormulaManager {
* *
* @param primarySkillType skill where new levels and experience are calculated for * @param primarySkillType skill where new levels and experience are calculated for
* @param experience total amount of experience * @param experience total amount of experience
* @param formulaType The new {@link FormulaType}
* @return the amount of levels and experience * @return the amount of levels and experience
*/ */
public int[] calculateNewLevel(PrimarySkillType primarySkillType, int experience, FormulaType formulaType) { public int[] calculateNewLevel(PrimarySkillType primarySkillType, int experience) {
int newLevel = 0; int newLevel = 0;
int remainder = 0; int remainder = 0;
int maxLevel = mcMMO.getConfigManager().getConfigLeveling().getLevelCap(primarySkillType); int maxLevel = mcMMO.getConfigManager().getConfigLeveling().getLevelCap(primarySkillType);
while (experience > 0 && newLevel < maxLevel) { while (experience > 0 && newLevel < maxLevel) {
int experienceToNextLevel = getXPtoNextLevel(newLevel, formulaType); int experienceToNextLevel = getXPtoNextLevel(newLevel, currentFormula);
if (experience - experienceToNextLevel < 0) { if (experience - experienceToNextLevel < 0) {
remainder = experience; remainder = experience;
@ -198,4 +197,8 @@ public class FormulaManager {
return calculateXPNeeded(level, FormulaType.LINEAR); return calculateXPNeeded(level, FormulaType.LINEAR);
} }
} }
public void setCurrentFormula(FormulaType currentFormula) {
this.currentFormula = currentFormula;
}
} }

View File

@ -605,8 +605,8 @@ Commands.mcconvert.Database.Finish=[[GRAY]]Database migration complete; the {1}
Commands.mmoshowdb=The currently used database is [[GREEN]]{0} Commands.mmoshowdb=The currently used database is [[GREEN]]{0}
Commands.mcconvert.Experience.Invalid=Unknown formula type! Valid types are: [[GREEN]]LINEAR [[RED]]and [[GREEN]]EXPONENTIAL. Commands.mcconvert.Experience.Invalid=Unknown formula type! Valid types are: [[GREEN]]LINEAR [[RED]]and [[GREEN]]EXPONENTIAL.
Commands.mcconvert.Experience.Same=Already using formula type {0} Commands.mcconvert.Experience.Same=Already using formula type {0}
Commands.mcconvert.Experience.Start=[[GRAY]]Starting conversion from {0} to {1} curve Commands.mcconvert.Experience.Start=[[GRAY]]Starting conversion from {0} to {1} experience formula
Commands.mcconvert.Experience.Finish=[[GRAY]]Formula conversion complete; now using {0} XP curve. Commands.mcconvert.Experience.Finish=[[GRAY]]Formula conversion complete; now using {0} XP exp
Commands.ModDescription=[[GREEN]]- Read brief mod description Commands.ModDescription=[[GREEN]]- Read brief mod description
Commands.NoConsole=This command does not support console usage. Commands.NoConsole=This command does not support console usage.
Commands.Notifications.Off=Ability notifications toggled [[RED]]off Commands.Notifications.Off=Ability notifications toggled [[RED]]off