Refactor leaderboard management: replace UserConfig-based implementation with new Leaderboard SQL class, update related classes to use LeaderboardManager, and fix query/logic for best time retrieval.

This commit is contained in:
2025-11-11 17:27:24 +01:00
committed by Chaoscaot
parent e6848b27a0
commit 9e9f405e30
4 changed files with 115 additions and 64 deletions
@@ -22,8 +22,8 @@ package de.steamwar.lobby.jumpandrun;
import de.steamwar.linkage.Linked;
import de.steamwar.lobby.LobbySystem;
import de.steamwar.lobby.listener.PlayerSpawn;
import de.steamwar.lobby.util.Leaderboard;
import de.steamwar.sql.UserConfig;
import de.steamwar.lobby.util.LeaderboardManager;
import de.steamwar.sql.SteamwarUser;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -58,7 +58,7 @@ public class JumpAndRun implements Listener {
private static final Map<Player, Long> CLICKED = new HashMap<>();
private static final Map<Player, Integer> CLICKED_COUNT = new HashMap<>();
private static final Leaderboard LEADERBOARD = new Leaderboard(LobbySystem.getEntityServer(false), JUMP_AND_RUN_CONFIG, new Location(Bukkit.getWorlds().get(0), 2338.5, 42.5, 1231.5), 5);
private static final LeaderboardManager LEADERBOARD = new LeaderboardManager(LobbySystem.getEntityServer(false), JUMP_AND_RUN_CONFIG, new Location(Bukkit.getWorlds().get(0), 2338.5, 42.5, 1231.5));
{
Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> {
@@ -161,18 +161,14 @@ public class JumpAndRun implements Listener {
}
private void updateJumpAndRunTime(Player player, long time) {
String jumpAndRunTimeConfig = UserConfig.getConfig(player.getUniqueId(), JUMP_AND_RUN_CONFIG);
if (jumpAndRunTimeConfig == null) {
UserConfig.updatePlayerConfig(player.getUniqueId(), JUMP_AND_RUN_CONFIG, time + "");
} else {
long jumpAndRunTime = Long.parseLong(jumpAndRunTimeConfig);
if (time < jumpAndRunTime) {
long best = LEADERBOARD.getPlayerTime(SteamwarUser.get(player.getUniqueId()));
if (time < best) {
if (best != Long.MAX_VALUE) {
SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", player), Locale.ROOT);
String parsed = format.format(new Date(jumpAndRunTime - time));
String parsed = format.format(new Date(best - time));
LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_PERSONAL_BEST", player, parsed);
UserConfig.updatePlayerConfig(player.getUniqueId(), JUMP_AND_RUN_CONFIG, time + "");
LEADERBOARD.update();
}
LEADERBOARD.updateBestTime(SteamwarUser.get(player.getUniqueId()), time);
}
}