This commit is contained in:
tyuXX 2025-04-01 22:23:22 +03:00
parent e8a4c9f75b
commit ddbb6d8211
39 changed files with 374 additions and 53 deletions

View file

@ -0,0 +1,59 @@
package org.gsdistance.grimmsServer.Stats;
import com.google.gson.Gson;
import org.bukkit.entity.Player;
import org.gsdistance.grimmsServer.Constructable.LeaderboardEntry;
import java.lang.reflect.Type;
import java.util.Map;
public class PlayerStatLeaderBoard {
public static final Map<String, Type> Stats = Map.of(
"total_kill_count", Integer.class,
"death_count", Integer.class,
"join_count", Integer.class,
"tPoint", Double.class,
"block_break_count", Long.class,
"money", Double.class
);
public static final Map<String, String> StatNames = Map.of(
"total_kill_count", "Kills",
"death_count", "Deaths",
"join_count", "Join Count",
"tPoint", "Total Points",
"block_break_count", "Blocks Broken",
"money", "Money"
);
public Map<String, LeaderboardEntry> leaderboard;
public PlayerStatLeaderBoard () {
this.leaderboard = Map.of(
"total_kill_count", new LeaderboardEntry("None", 0),
"death_count", new LeaderboardEntry("None", 0),
"join_count", new LeaderboardEntry("None", 0),
"tPoint", new LeaderboardEntry("None", 0),
"block_break_count", new LeaderboardEntry("None", 0),
"money", new LeaderboardEntry("None", 0)
);
}
public static PlayerStatLeaderBoard getPlayerStatLeaderBoard () {
return new Gson().fromJson((String) ServerStats.getServerStats().getStat("leaderboard"),PlayerStatLeaderBoard.class);
}
public void savePlayerStatLeaderBoard () {
ServerStats.getServerStats().setStat("leaderboard", new Gson().toJson(this));
}
public boolean checkPlayer(Player player) {
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
boolean pass = false;
for (String stat : leaderboard.keySet()) {
Number playerStatValue = (Number) playerStats.getStat(stat);
Number leaderboardStatValue = leaderboard.get(stat).getStatValue();
if (playerStatValue != null && playerStatValue.doubleValue() > leaderboardStatValue.doubleValue()) {
leaderboard.put(stat, new LeaderboardEntry(player.getName(), playerStatValue.intValue()));
savePlayerStatLeaderBoard();
pass = true;
}
}
return pass;
}
}

View file

@ -18,6 +18,7 @@ public class PlayerStats {
Stats.put("total_kill_count", PersistentDataType.INTEGER);
Stats.put("join_count", PersistentDataType.INTEGER);
Stats.put("tPoint", PersistentDataType.DOUBLE);
Stats.put("block_break_count", PersistentDataType.LONG);
}
public static final Dictionary<String,String> StatNames = new Hashtable<>();
static {
@ -26,6 +27,7 @@ public class PlayerStats {
StatNames.put("total_kill_count", "Total Kill Count");
StatNames.put("join_count", "Join Count");
StatNames.put("tPoint", "Total Points");
StatNames.put("block_break_count", "Block Break Count");
}
private final JavaPlugin plugin;

View file

@ -22,13 +22,15 @@ public class ServerStats {
static {
Stats.put("death_count", Integer.class);
Stats.put("join_count", Integer.class);
Stats.put("market", Market.class);
Stats.put("market", String.class);
Stats.put("leaderboard", String.class);
}
public static final Dictionary<String,String> StatNames = new Hashtable<>();
static {
StatNames.put("death_count", "Death Count");
StatNames.put("join_count", "Join Count");
StatNames.put("market", "Market");
StatNames.put("leaderboard", "Leaderboard");
}
private final JavaPlugin plugin;
@ -47,7 +49,8 @@ public class ServerStats {
private void loadStats() {
if (!statsFile.exists()) {
stats = new Hashtable<>();
stats.put("market", new Market()); // Initialize market stat
stats.put("market", new Gson().toJson(new Market())); // Initialize market stat
stats.put("leaderboard", new Gson().toJson(new PlayerStatLeaderBoard())); // Initialize leaderboard stat
saveStats();
return;
}
@ -55,12 +58,16 @@ public class ServerStats {
Type type = new TypeToken<Map<String, Object>>() {}.getType();
stats = new Gson().fromJson(reader, type);
if (!stats.containsKey("market")) {
stats.put("market", new Market()); // Ensure market stat is initialized
stats.put("market", new Gson().toJson(new Market())); // Initialize market stat
}
if (!stats.containsKey("leaderboard")) {
stats.put("leaderboard", new Gson().toJson(new PlayerStatLeaderBoard())); // Initialize leaderboard stat
}
} catch (IOException e) {
GrimmsServer.logger.log(Level.WARNING, "Failed to load server stats.\n" + Arrays.toString(e.getStackTrace()));
stats = new Hashtable<>();
stats.put("market", new Market()); // Initialize market stat
stats.put("market", new Gson().toJson(new Market())); // Initialize market stat
stats.put("leaderboard", new Gson().toJson(new PlayerStatLeaderBoard())); // Initialize leaderboard stat
}
}