Skip to content

Commit

Permalink
Skip writing players json when the server is empty and max players ha…
Browse files Browse the repository at this point in the history
…sn't changed
  • Loading branch information
jpenilla committed Sep 7, 2023
1 parent 5557cb1 commit 9784f8b
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class UpdatePlayers implements Runnable {
private final DirectoryProvider directoryProvider;
private final ServerAccess serverAccess;
private final ConfigManager configManager;
private boolean prevEmpty = false;
private int prevMaxPlayers = Integer.MIN_VALUE;

@Inject
private UpdatePlayers(
Expand Down Expand Up @@ -90,9 +92,16 @@ public void run() {
});
});

final int maxPlayers = this.serverAccess.maxPlayers();
if (players.isEmpty() && this.prevEmpty && maxPlayers == this.prevMaxPlayers) {
return;
}
this.prevEmpty = players.isEmpty();
this.prevMaxPlayers = maxPlayers;

final Map<String, Object> map = new HashMap<>();
map.put("players", players);
map.put("max", this.serverAccess.maxPlayers());
map.put("max", maxPlayers);

FileUtil.atomicWriteJsonAsync(this.directoryProvider.tilesDirectory().resolve("players.json"), map);
}
Expand Down

0 comments on commit 9784f8b

Please sign in to comment.