Skip to content

Commit

Permalink
Bugfix leaderboard being read-only and not being updated when new
Browse files Browse the repository at this point in the history
  • Loading branch information
Ale32bit committed Jan 19, 2025
1 parent 156beae commit 4ddac96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/main/java/me/alexdevs/solstice/modules/afk/AfkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private void tryInsertLeaderboard(ServerPlayerEntity player, int activeTime) {

// if in list, update
var entry = leaderboard.stream().filter(e -> e.uuid().equals(player.getUuid())).findFirst();
if(entry.isPresent()) {
if (entry.isPresent()) {
entry.get().activeTime(activeTime);
entry.get().name(player.getGameProfile().getName());
leaderboard.sort((o1, o2) -> Integer.compare(o2.activeTime(), o1.activeTime()));
Expand All @@ -134,10 +134,14 @@ private void tryInsertLeaderboard(ServerPlayerEntity player, int activeTime) {

// if not in list, insert
var smallest = leaderboard.stream().min(Comparator.comparingInt(LeaderboardEntry::activeTime));
if(smallest.isPresent() && smallest.get().activeTime() < activeTime) {
leaderboard.remove(smallest.get());
if (smallest.isPresent()) {
if (smallest.get().activeTime() < activeTime) {
leaderboard.remove(smallest.get());
leaderboard.add(new LeaderboardEntry(player.getGameProfile().getName(), player.getUuid(), activeTime));
leaderboard.sort((o1, o2) -> Integer.compare(o2.activeTime(), o1.activeTime()));
}
} else {
leaderboard.add(new LeaderboardEntry(player.getGameProfile().getName(), player.getUuid(), activeTime));
leaderboard.sort((o1, o2) -> Integer.compare(o2.activeTime(), o1.activeTime()));
}
}

Expand Down Expand Up @@ -212,7 +216,7 @@ public int getActiveTime(UUID playerUuid) {

private void calculateLeaderboard() {
var serverData = getServerData();
if(!serverData.forceCalculateLeaderboard)
if (!serverData.forceCalculateLeaderboard)
return;

serverData.forceCalculateLeaderboard = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package me.alexdevs.solstice.modules.afk.data;

import java.util.ArrayList;
import java.util.List;

public class AfkServerData {
public boolean forceCalculateLeaderboard = true;
public List<LeaderboardEntry> leaderboard = List.of();
public List<LeaderboardEntry> leaderboard = new ArrayList<>();
}

0 comments on commit 4ddac96

Please sign in to comment.