Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
fantahund committed Oct 21, 2023
1 parent c072bcd commit 3887fbc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/main/java/de/fanta/stats/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ static void serialize() {
} catch (IOException e) {
StatsClient.LOGGER.warn("Failed to write config!");
}
GUI.updateStats();
if (GUI.updater != null && GUI.updater.isAlive()) {
GUI.updateStats();
}
}

public static void deserialize() {
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/de/fanta/stats/client/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class GUI {
private static final HashMap<String, PlayerStatsEntry> otherStatsEntries = new HashMap<>();
private static final HashMap<String, PlayerStatsEntry> positionStatsEntries = new HashMap<>();
private static final HashMap<String, ItemStack> skullList = new HashMap<>();
private static String description = "";
public static Thread updater;

public GUI() {
Expand Down Expand Up @@ -78,8 +79,7 @@ private void renderStats(DrawContext drawContext) {

int distance = 14;
if (Config.headline) {
PlayerStatsProvider provider = StatsClient.getStatsKey(Config.statsKeyID);
drawContext.drawText(this.fontRenderer, "§l" + "----- " + (provider != null ? provider.getTitle() : Config.statsKeyID) + " -----", 5, (30 + result.height + 9 / 2), Color.white.getRGB(), true);
drawContext.drawText(this.fontRenderer, "§l" + "----- " + description + " -----", 5, (30 + result.height + 9 / 2), Color.white.getRGB(), true);
result.height += distance;
}

Expand Down Expand Up @@ -178,11 +178,14 @@ public static void updateStats() {
return;
}

PlayerStatsProvider provider = StatsClient.getStatsKey(Config.statsKeyID);
description = provider != null ? provider.getTitle() : Config.statsKeyID;

// - Get PositionScores
Collection<PlayerStatsEntry> newPositionStatsEntries = new ArrayList<>(StatsClient.getCubesideStats().getStatsFromPositionRange(Config.statsKeyID, 0, Config.places));
Collection<PlayerStatsEntry> newPositionStatsEntries = new ArrayList<>(StatsClient.getCubesideStats().getStatsFromPositionRange(Config.statsKeyID, 0, 30));
synchronized (skullList) {
for (PlayerStatsEntry statsPlayer : newPositionStatsEntries) {
if (!skullList.containsKey(statsPlayer.getName())) {
if (!skullList.containsKey(statsPlayer.getName()) && statsPlayer.getPosition() <= Config.places) {
skullList.put(statsPlayer.getName(), getCustomHead(statsPlayer.getName()));
}
}
Expand All @@ -191,8 +194,10 @@ public static void updateStats() {
synchronized (positionStatsEntries) {
positionStatsEntries.clear();
for (PlayerStatsEntry entry : newPositionStatsEntries) {
System.out.println(entry.getPosition() + "(" + entry.getDisplayPosition() + ") ." + entry.getName());
positionStatsEntries.put(entry.getName(), entry);
if (entry.getPosition() <= Config.places) {
System.out.println(entry.getPosition() + ": " + entry.getName());
positionStatsEntries.put(entry.getName(), entry);
}
}
}

Expand Down

0 comments on commit 3887fbc

Please sign in to comment.