Fixed and improved the GithubUpdater

This commit is contained in:
Bram 2024-07-09 12:00:58 +02:00
parent 7a313da975
commit cb4ac1031f
No known key found for this signature in database
GPG key ID: 13E608068F40E3CC
2 changed files with 12 additions and 11 deletions

View file

@ -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<EntityLibAPI<?>> getOptionalApi() {

View file

@ -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...");
}
public void checkForUpdates() {
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) {