add update checks
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user