From 20bf2d74fcb318a033f43a6d96518a1c72b4df89 Mon Sep 17 00:00:00 2001 From: Jack <55409055+Jack1424@users.noreply.github.com> Date: Tue, 23 Jul 2024 02:26:56 -0400 Subject: [PATCH] add update checks --- .../realtimeweather/ConfigManager.java | 13 +++++++++- .../realtimeweather/RealTimeWeather.java | 26 +++++++++++++++++++ src/main/resources/config.yml | 8 +++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/jack1424/realtimeweather/ConfigManager.java b/src/main/java/io/github/jack1424/realtimeweather/ConfigManager.java index 5a296b7..51f3970 100644 --- a/src/main/java/io/github/jack1424/realtimeweather/ConfigManager.java +++ b/src/main/java/io/github/jack1424/realtimeweather/ConfigManager.java @@ -19,7 +19,7 @@ public class ConfigManager { private final FileConfiguration configFile; private TimeZone timeZone; private boolean debug, timeEnabled, weatherEnabled, blockTimeSetCommand, blockWeatherCommand, disableBedsAtNight, disableBedsDuringThunder; - private long timeSyncInterval, weatherSyncInterval; + private long timeSyncInterval, weatherSyncInterval, updateCheckInterval; private String sunriseSunset, sunriseSunsetLatitude, sunriseSunsetLongitude, apiKey, weatherLatitude, weatherLongitude, disableBedsAtNightMessage, disableBedsDuringThunderMessage, sunriseCustomTime, sunsetCustomTime; public ConfigManager(RealTimeWeather rtw) { @@ -71,6 +71,8 @@ public class ConfigManager { setWeatherEnabled(false); } + + setUpdateCheckInterval(configFile.getLong("updateCheckInterval")); } public boolean debugEnabled() { @@ -308,4 +310,13 @@ public class ConfigManager { weatherLongitude = value; rtw.debug("Longitude set to " + value); } + + public void setUpdateCheckInterval(long value) { + updateCheckInterval = value; + rtw.debug("updateCheckInterval set to " + value); + } + + public long getUpdateCheckInterval() { + return updateCheckInterval; + } } diff --git a/src/main/java/io/github/jack1424/realtimeweather/RealTimeWeather.java b/src/main/java/io/github/jack1424/realtimeweather/RealTimeWeather.java index 7d4328e..8782bec 100644 --- a/src/main/java/io/github/jack1424/realtimeweather/RealTimeWeather.java +++ b/src/main/java/io/github/jack1424/realtimeweather/RealTimeWeather.java @@ -43,6 +43,15 @@ public final class RealTimeWeather extends JavaPlugin { metrics.addCustomChart(new SimplePie("time_sync_enabled", () -> String.valueOf(config.isTimeEnabled()))); logger.info("Started!"); + + logger.info("Checking for updates..."); + logger.info(getUpdateCheck()); + + long updateCheckInterval = config.getUpdateCheckInterval(); + if (config.getUpdateCheckInterval() > 0) + getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> { + logger.info(getUpdateCheck()); + }, updateCheckInterval, updateCheckInterval); } @Override @@ -168,6 +177,23 @@ public final class RealTimeWeather extends JavaPlugin { } } + public String getUpdateCheck() { + String currentVersion = this.getDescription().getVersion(); + String latestVersion; + try { + debug("Getting latest version..."); + latestVersion = RequestFunctions.getLatestVersion(); + } catch (Exception exception) { + debug(exception.getMessage()); + return "There was an error getting the latest version"; + } + + if (currentVersion.equals(latestVersion)) { + return String.format("RealTimeWeather (v%s) is up to date!", currentVersion); + } else + return String.format("RealTimeWeather (v%s) is outdated! v%s is the latest version.", currentVersion, latestVersion); + } + public ConfigManager getConfigurator() { return config; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 452c66e..ada6a06 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,4 +1,4 @@ -# RealTimeWeather Configuration File (v1.3.0) +# RealTimeWeather Configuration File (v1.4.0) # You can find detailed instructions at: https://github.com/Jack1424/RealTimeWeather/wiki#editing-the-configuration-file ################################# TIME SYNC SETTINGS ################################################################# @@ -72,6 +72,12 @@ WeatherLongitude: '0' # # ###################################################################################################################### +# By default, RealTimeWeather will check if an update is available every 24 hours (1734000 ticks) +# You can change the interval here (or set to 0 to disable update checks) +# If this is disabled, RealTimeWeather will still check for updates on startup +# You can find a handy tick calculator here: https://mapmaking.fr/tick/ +updateCheckInterval: 1734000 + # Set to true for various console messages when time and weather sync are executed # This is useful if the plugin is not working, and you want to find out what's wrong # This will also provide error messages even when an error is caught and managed by RTM