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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user