Skip to content

Commit

Permalink
Wrap update checker in try
Browse files Browse the repository at this point in the history
To ensure safety in the future!
  • Loading branch information
srnyx committed Jan 13, 2025
1 parent 34bd44d commit a88d451
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/cc/aabss/eventutils/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ private void notifyUpdate(@NotNull String latestVersion) {
}

public void checkUpdate() {
if (!EventUtils.MOD.config.updateChecker || Versions.MC_VERSION == null || Versions.EU_VERSION == null || Versions.EU_VERSION_SEMANTIC == null) return;
try {
if (!EventUtils.MOD.config.updateChecker || Versions.MC_VERSION == null || Versions.EU_VERSION == null || Versions.EU_VERSION_SEMANTIC == null) return;

// Ensure client in-game
final MinecraftClient client = MinecraftClient.getInstance();
if (client.player == null) return;
// Ensure client in-game
final MinecraftClient client = MinecraftClient.getInstance();
if (client.player == null) return;

// Get latest version from Modrinth
try {
// Get latest version from Modrinth
final HttpClient httpClient = HttpClient.newHttpClient();
httpClient
.sendAsync(HttpRequest.newBuilder()
Expand All @@ -55,14 +55,15 @@ public void checkUpdate() {
return;
}

// Extract version
final String latestVersion = JsonParser.parseString(response.body()).getAsJsonArray()
.get(0).getAsJsonObject()
.get("version_number").getAsString();
if (latestVersion != null && !latestVersion.equals(Versions.MC_VERSION + "-" + Versions.EU_VERSION)) notifyUpdate(latestVersion);
//? if java: >=21
httpClient.close();
});
} catch (final URISyntaxException e) {
} catch (final Exception e) {
EventUtils.LOGGER.warn("Failed to check for updates", e);
}
}
Expand Down

0 comments on commit a88d451

Please sign in to comment.