After 3 minutes of sleeping the thread hits line 338 and will continually check UPDATE_PLAYER_JOIN_FLAG
. Once a player joins it will perform the update check and then after 3 minutes return to line 338.
|
public static final Thread UPDATE_CHECKER = new Thread(() -> { |
|
LOGGER.info("Update checker started"); |
|
|
|
HttpClient client = HttpClient.newHttpClient(); |
|
HttpRequest request = HttpRequest.newBuilder(URI.create(VERSION_DOCUMENT)).GET().build(); |
|
|
|
while (true) { |
|
try { |
|
Thread.sleep(60000 * 3); |
|
while (!UPDATE_PLAYER_JOIN_FLAG.get()); // Loop until player joins |
|
UPDATE_PLAYER_JOIN_FLAG.set(false); // Consume |
|
LOGGER.info("Checking for updates"); |
|
int version = Integer.parseInt(client.send(request, HttpResponse.BodyHandlers.ofString()).body().replace("\n", "")); |
|
|
|
if (version != currentVersion) { |
|
LOGGER.info("Update found!"); |
|
UPDATE_FLAG.computeIfAbsent(Dist.CLIENT, dist -> new AtomicBoolean(true)).set(true); |
|
UPDATE_FLAG.computeIfAbsent(Dist.DEDICATED_SERVER, dist -> new AtomicBoolean(true)).set(true); |
|
currentVersion = version; |
|
} |
|
} |