add option to change sync intervals
This commit is contained in:
@@ -86,8 +86,11 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupTime() {
|
private void setupTime() {
|
||||||
|
long timeSyncInterval;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
timezone = ZoneId.of(Objects.requireNonNull(getConfig().getString("Timezone")));
|
timezone = ZoneId.of(Objects.requireNonNull(getConfig().getString("Timezone")));
|
||||||
|
timeSyncInterval = getConfig().getLong("TimeSyncInterval");
|
||||||
} catch (NullPointerException|ZoneRulesException e) {
|
} catch (NullPointerException|ZoneRulesException e) {
|
||||||
logger.severe("Error loading timezone. Check that the values in your configuration file are valid.");
|
logger.severe("Error loading timezone. Check that the values in your configuration file are valid.");
|
||||||
debug(e.getMessage());
|
debug(e.getMessage());
|
||||||
@@ -97,7 +100,7 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Enabling time zone sync (every second)");
|
debug("Enabling time zone sync...");
|
||||||
debug("Syncing time with " + timezone.toString());
|
debug("Syncing time with " + timezone.toString());
|
||||||
|
|
||||||
for (World world : getServer().getWorlds())
|
for (World world : getServer().getWorlds())
|
||||||
@@ -111,16 +114,21 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
if (world.getEnvironment().equals(World.Environment.NORMAL))
|
if (world.getEnvironment().equals(World.Environment.NORMAL))
|
||||||
world.setTime((1000 * cal.get(Calendar.HOUR_OF_DAY)) + (16 * cal.get(Calendar.MINUTE)) - 6000); // TODO: Time is one minute behind
|
world.setTime((1000 * cal.get(Calendar.HOUR_OF_DAY)) + (16 * cal.get(Calendar.MINUTE)) - 6000); // TODO: Time is one minute behind
|
||||||
}
|
}
|
||||||
}, 0L, 20L); // TODO: Does this really need to update every second?
|
}, 0L, timeSyncInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupWeather() {
|
private void setupWeather() {
|
||||||
|
long weatherSyncInterval;
|
||||||
|
|
||||||
String apiKey = getConfig().getString("APIKey");
|
String apiKey = getConfig().getString("APIKey");
|
||||||
String zipCode = getConfig().getString("ZipCode");
|
String zipCode = getConfig().getString("ZipCode");
|
||||||
String countryCode = getConfig().getString("CountryCode");
|
String countryCode = getConfig().getString("CountryCode");
|
||||||
|
|
||||||
String lat, lon;
|
String lat, lon;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
weatherSyncInterval = getConfig().getLong("WeatherSyncInterval");
|
||||||
|
|
||||||
HttpsURLConnection con = (HttpsURLConnection) new URL(String.format("https://api.openweathermap.org/geo/1.0/zip?zip=%s,%s&appid=%s", zipCode, countryCode, apiKey)).openConnection();
|
HttpsURLConnection con = (HttpsURLConnection) new URL(String.format("https://api.openweathermap.org/geo/1.0/zip?zip=%s,%s&appid=%s", zipCode, countryCode, apiKey)).openConnection();
|
||||||
con.setRequestMethod("GET");
|
con.setRequestMethod("GET");
|
||||||
con.connect();
|
con.connect();
|
||||||
@@ -192,7 +200,7 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
world.setStorm(rain);
|
world.setStorm(rain);
|
||||||
world.setThundering(thunder);
|
world.setThundering(thunder);
|
||||||
}
|
}
|
||||||
}, 0L, 6000L);
|
}, 0L, weatherSyncInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject makeWeatherRequest(URL url) throws IOException, ParseException {
|
private JSONObject makeWeatherRequest(URL url) throws IOException, ParseException {
|
||||||
|
@@ -4,6 +4,9 @@
|
|||||||
################################# TIME SYNC SETTINGS #################################################################
|
################################# TIME SYNC SETTINGS #################################################################
|
||||||
# Set to true to enable time syncing, or false to disable #
|
# Set to true to enable time syncing, or false to disable #
|
||||||
SyncTime: false
|
SyncTime: false
|
||||||
|
#
|
||||||
|
# You can change the time between time syncs from the default (5 seconds) below #
|
||||||
|
TimeSyncInterval: 100
|
||||||
# #
|
# #
|
||||||
# Enter the time zone that you want to sync your world(s) with #
|
# Enter the time zone that you want to sync your world(s) with #
|
||||||
# This location CAN be different from your chosen weather location #
|
# This location CAN be different from your chosen weather location #
|
||||||
@@ -15,6 +18,11 @@ Timezone: 'America/New_York'
|
|||||||
################################# WEATHER SYNC SETTINGS ##############################################################
|
################################# WEATHER SYNC SETTINGS ##############################################################
|
||||||
# Set to true to enable weather syncing, or false to disable #
|
# Set to true to enable weather syncing, or false to disable #
|
||||||
SyncWeather: false
|
SyncWeather: false
|
||||||
|
#
|
||||||
|
# You can change the time between weather syncs from the default (5 minutes) below #
|
||||||
|
# Due to OpenWeather's restrictions, setting this value below 2400 (2 minutes) will cause problems #
|
||||||
|
# You can find a handy tick calculator here: https://mapmaking.fr/tick/ #
|
||||||
|
WeatherSyncInterval: 6000
|
||||||
# #
|
# #
|
||||||
# In order to access the weather sync feature, create an account at https://openweathermap.org/ #
|
# In order to access the weather sync feature, create an account at https://openweathermap.org/ #
|
||||||
# Then, create an API key at https://openweathermap.org/appid and copy it #
|
# Then, create an API key at https://openweathermap.org/appid and copy it #
|
||||||
|
Reference in New Issue
Block a user