Skip to content

Commit

Permalink
Fix win percent
Browse files Browse the repository at this point in the history
  • Loading branch information
zax71 committed Mar 2, 2024
1 parent 7feecda commit 09e9330
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.command.builder.Command;
import net.minestom.server.entity.Player;
import net.minestom.server.utils.MathUtils;

import static net.endercube.Common.utils.ComponentUtils.getTitle;
import static net.endercube.spleef.minigame.SpleefMinigame.database;
Expand Down Expand Up @@ -46,11 +47,11 @@ public StatsCommand() {
}));
}

private int getWinPercent(Player player) {
private float getWinPercent(Player player) {
// Stop divide by 0 errors
if (database.getLostGames(player) == 0) {
return 100;
if (database.getAllGames(player) == 0) {
return 0;
}
return database.getWonGames(player) / database.getLostGames(player) * 100;
return MathUtils.round(((float) database.getWonGames(player) / (float) database.getAllGames(player)) * 100, 1);
}
}

0 comments on commit 09e9330

Please sign in to comment.