Skip to content

Commit 57dd6f6

Browse files
committed
Improved formatting of the help account experience info to make it less confusing.
1 parent 4ec0691 commit 57dd6f6

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/main/java/net/javadiscord/javabot/systems/help/commands/subcommands/HelpAccountSubcommand.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,23 @@ private String formatTransactionHistory(long userId) {
7373
}
7474

7575
private String formatExperience(Guild guild, HelpAccount account) {
76-
double current = account.getExperience() - account.getLastExperienceGoal(guild);
77-
Pair<Role, Double> role = account.getNextExperienceGoal(guild);
78-
double goal = role.second() - account.getLastExperienceGoal(guild);
79-
StringBuilder sb = new StringBuilder(String.format("%s: ", role.first().getAsMention()));
80-
if (goal > 0) {
81-
sb.append(String.format("%.2f XP / %.2f XP (%.2f%%)", current, goal, (current / goal) * 100))
82-
.append("\n")
83-
.append(StringUtils.buildProgressBar(current, goal, "\u2B1B", "\uD83D\uDFE5", 14));
76+
double currentXp = account.getExperience() - account.getLastExperienceGoal(guild);
77+
Pair<Role, Double> currentRoleAndXp = account.getCurrentExperienceGoal(guild);
78+
Pair<Role, Double> nextRoleAndXp = account.getNextExperienceGoal(guild);
79+
double goalXp = nextRoleAndXp.second() - account.getLastExperienceGoal(guild);
80+
StringBuilder sb = new StringBuilder();
81+
82+
// Show the current experience level on the first line.
83+
sb.append(String.format("%s\n", currentRoleAndXp.first().getAsMention()));
84+
85+
// Below, show the progress to the next level, or just the XP if they've reached the max level.
86+
if (goalXp > 0) {
87+
double percentToGoalXp = (currentXp / goalXp) * 100.0;
88+
sb.append(String.format("%.0f / %.0f XP (%.2f%%) until %s", currentXp, goalXp, percentToGoalXp, nextRoleAndXp.first().getAsMention()))
89+
.append('\n')
90+
.append(StringUtils.buildProgressBar(currentXp, goalXp, "\u2B1B", "\uD83D\uDFE5", 14));
8491
} else {
85-
sb.append(String.format("%.2f XP (MAX. LEVEL)", account.getExperience()));
92+
sb.append(String.format("%.0f XP (MAX. LEVEL)", account.getExperience()));
8693
}
8794
return sb.toString();
8895
}

0 commit comments

Comments
 (0)