add update checks

This commit is contained in:
Jack
2024-07-23 02:26:56 -04:00
parent 36ddb10fe2
commit 20bf2d74fc
3 changed files with 45 additions and 2 deletions

View File

@@ -19,7 +19,7 @@ public class ConfigManager {
private final FileConfiguration configFile; private final FileConfiguration configFile;
private TimeZone timeZone; private TimeZone timeZone;
private boolean debug, timeEnabled, weatherEnabled, blockTimeSetCommand, blockWeatherCommand, disableBedsAtNight, disableBedsDuringThunder; 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; private String sunriseSunset, sunriseSunsetLatitude, sunriseSunsetLongitude, apiKey, weatherLatitude, weatherLongitude, disableBedsAtNightMessage, disableBedsDuringThunderMessage, sunriseCustomTime, sunsetCustomTime;
public ConfigManager(RealTimeWeather rtw) { public ConfigManager(RealTimeWeather rtw) {
@@ -71,6 +71,8 @@ public class ConfigManager {
setWeatherEnabled(false); setWeatherEnabled(false);
} }
setUpdateCheckInterval(configFile.getLong("updateCheckInterval"));
} }
public boolean debugEnabled() { public boolean debugEnabled() {
@@ -308,4 +310,13 @@ public class ConfigManager {
weatherLongitude = value; weatherLongitude = value;
rtw.debug("Longitude set to " + 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;
}
} }

View File

@@ -43,6 +43,15 @@ public final class RealTimeWeather extends JavaPlugin {
metrics.addCustomChart(new SimplePie("time_sync_enabled", () -> String.valueOf(config.isTimeEnabled()))); metrics.addCustomChart(new SimplePie("time_sync_enabled", () -> String.valueOf(config.isTimeEnabled())));
logger.info("Started!"); 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 @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() { public ConfigManager getConfigurator() {
return config; return config;
} }

View File

@@ -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 # You can find detailed instructions at: https://github.com/Jack1424/RealTimeWeather/wiki#editing-the-configuration-file
################################# TIME SYNC SETTINGS ################################################################# ################################# 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 # 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 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 # This will also provide error messages even when an error is caught and managed by RTM