From cb4ac1031f60f577991999fbfa378835380b7332 Mon Sep 17 00:00:00 2001 From: Bram Date: Tue, 9 Jul 2024 12:00:58 +0200 Subject: [PATCH] Fixed and improved the GithubUpdater --- .../main/java/me/tofaa/entitylib/EntityLib.java | 9 +-------- .../me/tofaa/entitylib/utils/GithubUpdater.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/me/tofaa/entitylib/EntityLib.java b/api/src/main/java/me/tofaa/entitylib/EntityLib.java index d67b487..c71a4c3 100644 --- a/api/src/main/java/me/tofaa/entitylib/EntityLib.java +++ b/api/src/main/java/me/tofaa/entitylib/EntityLib.java @@ -5,7 +5,6 @@ import me.tofaa.entitylib.utils.ELVersions; import me.tofaa.entitylib.utils.GithubUpdater; import java.util.Optional; -import java.util.logging.Level; public final class EntityLib { @@ -19,13 +18,7 @@ public final class EntityLib { platform.setupApi(settings); api = platform.getAPI(); - if (api.getSettings().shouldCheckForUpdate()) { - if (api.getSettings().isDebugMode()) { - platform.getLogger().log(Level.INFO, "Checking for updates..."); - } - - new GithubUpdater("Tofaa2", "EntityLib").checkForUpdates(); - } + new GithubUpdater("Tofaa2", "EntityLib"); } public static Optional> getOptionalApi() { diff --git a/api/src/main/java/me/tofaa/entitylib/utils/GithubUpdater.java b/api/src/main/java/me/tofaa/entitylib/utils/GithubUpdater.java index 71add2a..a753dec 100644 --- a/api/src/main/java/me/tofaa/entitylib/utils/GithubUpdater.java +++ b/api/src/main/java/me/tofaa/entitylib/utils/GithubUpdater.java @@ -27,15 +27,23 @@ public final class GithubUpdater { this.repo = repo; this.currentVersion = ELVersions.CURRENT; this.logger = EntityLib.getPlatform().getLogger(); + + if (EntityLib.getApi().getSettings().shouldCheckForUpdate()) { + if (EntityLib.getApi().getSettings().isDebugMode()) { + logger.log(Level.INFO, "Checking for updates..."); + } + + checkForUpdates(); + } } - public void checkForUpdates() { + private void checkForUpdates() { CompletableFuture.runAsync(() -> { try { PEVersion latestVersion = getLatestVersion(); if (currentVersion.isOlderThan(latestVersion)) { - logger.log(Level.WARNING, "You are using an outdated version of EntityLib. Please take a look at the Github releases page."); - } else if (currentVersion.isNewerThan(latestVersion)) { + logger.log(Level.WARNING, "You are using an outdated version of EntityLib. Version: " + latestVersion + " is now available."); + } else if (currentVersion.equals(latestVersion)) { logger.log(Level.INFO, "No EntityLib updates found."); } } catch (Exception ex) {