diff --git a/TODO.md b/TODO.md index ca384fb..50c63b3 100644 --- a/TODO.md +++ b/TODO.md @@ -2,4 +2,6 @@ - account for real sun movement, not just time - gh actions - readd metrics -- fix realtime \ No newline at end of file +- fix realtime +- cache cleaning +- prevent packets \ No newline at end of file diff --git a/src/main/java/pl/minecon724/realweather/RW.java b/src/main/java/pl/minecon724/realweather/RW.java index 6a90cba..e69fd15 100644 --- a/src/main/java/pl/minecon724/realweather/RW.java +++ b/src/main/java/pl/minecon724/realweather/RW.java @@ -1,23 +1,14 @@ package pl.minecon724.realweather; -import java.time.ZoneId; -import java.util.List; - import com.maxmind.geoip2.WebServiceClient; -import org.bukkit.Bukkit; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; import pl.minecon724.realweather.map.WorldMap; -import pl.minecon724.realweather.realtime.RTTask; -import pl.minecon724.realweather.weather.GetStateTask; +import pl.minecon724.realweather.realtime.RealTimeCommander; import pl.minecon724.realweather.weather.WeatherCommander; import pl.minecon724.realweather.weather.exceptions.DisabledException; -import pl.minecon724.realweather.weather.exceptions.ProviderException; -import pl.minecon724.realweather.weather.provider.OpenWeatherMapProvider; -import pl.minecon724.realweather.weather.provider.Provider; public class RW extends JavaPlugin { FileConfiguration config; @@ -40,24 +31,24 @@ public class RW extends JavaPlugin { weatherCommander.init( config.getConfigurationSection("weather") ); + weatherCommander.start(); } catch (DisabledException e) { getLogger().info("Weather module disabled"); - } // we leave ProviderException - - if (realtimeSec.getBoolean("enabled")) { - ZoneId zone; - try { - zone = ZoneId.of(realtimeSec.getString("timezone")); - } catch (Exception e) { - zone = ZoneId.systemDefault(); - } - new RTTask( - realtimeSec.getDouble("timeScale"), - zone, - realtimeSec.getStringList("worlds") - ).runTaskTimer(this, 0, realtimeSec.getLong("interval")); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + getServer().getPluginManager().disablePlugin(this); } - + + RealTimeCommander realTimeCommander = new RealTimeCommander(this); + try { + realTimeCommander.init( + config.getConfigurationSection("time") + ); + realTimeCommander.start(); + } catch (DisabledException e) { + getLogger().info("Time module disabled"); + } + long end = System.currentTimeMillis(); this.getLogger().info( String.format( this.getName() + " enabled! (%s ms)", Long.toString( end-start ) ) ); } diff --git a/src/main/java/pl/minecon724/realweather/map/Coordinates.java b/src/main/java/pl/minecon724/realweather/map/Coordinates.java new file mode 100644 index 0000000..35cf22a --- /dev/null +++ b/src/main/java/pl/minecon724/realweather/map/Coordinates.java @@ -0,0 +1,48 @@ +package pl.minecon724.realweather.map; + +import com.maxmind.geoip2.record.Location; + +public class Coordinates { + public double latitude, longitude; + + public Coordinates(double latitude, double longitude) { + this.latitude = latitude; + this.longitude = longitude; + } + + /** + * converts Coordinates to double array + * @return array in order of latitude, longitude + */ + public double[] toDoubleArray() { + return new double[] { + this.latitude, + this.longitude + }; + } + + public Coordinates clamp() { + this.latitude = Math.max(-90.0, Math.min(90.0, this.latitude)); + this.longitude = Math.max(-180.0, Math.min(180.0, this.longitude)); + + return this; + } + + public Coordinates wrap() { + this.latitude = wrapDouble(-90.0, 90.0, this.latitude); + this.longitude = wrapDouble(-180.0, 180.0, this.longitude); + + return this; + } + + private static double wrapDouble(double min, double max, double val) { + return min + (val - min) % (max - min); + } + + public static Coordinates fromGeoIpLocation(Location location) { + return new Coordinates( + location.getLatitude(), + location.getLongitude() + ); + } +} diff --git a/src/main/java/pl/minecon724/realweather/map/GeoLocator.java b/src/main/java/pl/minecon724/realweather/map/GeoLocator.java index af79592..3b2736a 100644 --- a/src/main/java/pl/minecon724/realweather/map/GeoLocator.java +++ b/src/main/java/pl/minecon724/realweather/map/GeoLocator.java @@ -2,26 +2,29 @@ package pl.minecon724.realweather.map; import java.io.IOException; import java.net.InetAddress; +import java.util.HashMap; +import java.util.Map; import com.maxmind.geoip2.WebServiceClient; import com.maxmind.geoip2.exception.GeoIp2Exception; -import com.maxmind.geoip2.record.Location; import pl.minecon724.realweather.map.exceptions.GeoIPException; public class GeoLocator { - private WebServiceClient client; + private static GeoLocator INSTANCE = null; + private WebServiceClient client; + private Map cache; + + public static void init(int accountId, String apiKey) { + INSTANCE = new GeoLocator( + new WebServiceClient.Builder(accountId, apiKey) + .host("geolite.info").build()); + } + public GeoLocator(WebServiceClient client) { this.client = client; - } - - public static GeoLocator fromConfig(int accountId, String apiKey) { - return new GeoLocator( - new WebServiceClient.Builder(accountId, apiKey) - .host("geolite.info").build() - ); - + this.cache = new HashMap<>(); } /** @@ -31,19 +34,35 @@ public class GeoLocator { * @throws GeoIp2Exception * @throws IOException */ - public double[] getLocation(InetAddress address) + public static Coordinates getCoordinates(InetAddress address) throws GeoIPException { - Location location; + GeoLocator instance = INSTANCE; + + Coordinates coordinates = null; + + coordinates = instance.lookup(address); + if (coordinates != null) + return coordinates; + try { - location = client.city(address).getLocation(); + coordinates = Coordinates.fromGeoIpLocation( + instance.client.city(address).getLocation() + ); } catch (IOException | GeoIp2Exception e) { throw new GeoIPException(e.getMessage()); } - return new double[] { - location.getLatitude(), - location.getLongitude() - }; + instance.store(address, coordinates); + + return coordinates; + } + + private Coordinates lookup(InetAddress address) { + return this.cache.get(address); + } + + private void store(InetAddress address, Coordinates coordinates) { + this.cache.put(address, coordinates); } } diff --git a/src/main/java/pl/minecon724/realweather/map/Globe.java b/src/main/java/pl/minecon724/realweather/map/Globe.java index 9976c35..64c6ff2 100644 --- a/src/main/java/pl/minecon724/realweather/map/Globe.java +++ b/src/main/java/pl/minecon724/realweather/map/Globe.java @@ -3,35 +3,24 @@ package pl.minecon724.realweather.map; import org.bukkit.Location; public class Globe { - double scaleLatitide, scaleLongitude; - boolean wrap; + private static double[] SCALE; + private static boolean WRAP; - public Globe(double scaleLatitude, - double scaleLongitude, - boolean wrap) { - this.scaleLatitide = scaleLatitude; - this.scaleLongitude = scaleLongitude; - this.wrap = wrap; - } - - double wrapDouble(double min, double max, double val) { - return min + (val - min) % (max - min); + public static void init(double scaleLatitude, double scaleLongitude, boolean wrap) { + SCALE = new double[] { scaleLatitude, scaleLongitude }; + WRAP = wrap; } - public double[] playerPosAsCoords(Location loc) { - double[] out = new double[] { - loc.getX() * scaleLongitude, - -loc.getZ() * scaleLatitide - }; + public static Coordinates toCoordiates(Location loc) { + Coordinates coordinates = new Coordinates( + -loc.getZ() * SCALE[0], + loc.getX() * SCALE[1]); - if (wrap) { - out[0] = Math.max(-180.0, Math.min(180.0, out[0])); - out[1] = Math.max(-90.0, Math.min(90.0, out[1])); - } else { - out[0] = wrapDouble(-180.0, 180.0, out[0]); - out[1] = wrapDouble(-90.0, 90.0, out[1]); - } + if (WRAP) + coordinates.wrap(); + else + coordinates.clamp(); - return out; + return coordinates; } } diff --git a/src/main/java/pl/minecon724/realweather/map/WorldMap.java b/src/main/java/pl/minecon724/realweather/map/WorldMap.java index d1f13ad..0bc99cd 100644 --- a/src/main/java/pl/minecon724/realweather/map/WorldMap.java +++ b/src/main/java/pl/minecon724/realweather/map/WorldMap.java @@ -8,18 +8,12 @@ import pl.minecon724.realweather.map.exceptions.GeoIPException; public class WorldMap { private final Type type; - private double[] point; - private GeoLocator geoLocator; - private Globe globe; + private Coordinates point; public WorldMap(Type type, - double[] point, - GeoLocator geoLocator, - Globe globe) { + Coordinates point) { this.type = type; this.point = point; - this.geoLocator = geoLocator; - this.globe = globe; } public static WorldMap fromConfig(ConfigurationSection config) @@ -33,43 +27,41 @@ public class WorldMap { throw new IllegalArgumentException("Invalid type"); } - double[] point = null; - GeoLocator geoLocator = null; - Globe globe = null; + Coordinates point = null; if (type == Type.POINT) { - point = new double[] { + point = new Coordinates( config.getDouble("point.latitude"), config.getDouble("point.longitude") - }; + ); } else if (type == Type.PLAYER) { - geoLocator = GeoLocator.fromConfig( + GeoLocator.init( config.getInt("player.geolite2_accountId"), config.getString("player.geolite2_api_key") ); } else if (type == Type.GLOBE) { - globe = new Globe( + Globe.init( config.getDouble("globe.scale_latitude"), config.getDouble("globe.scale_longitude"), config.getBoolean("globe.wrap") ); } - WorldMap worldMap = new WorldMap(type, point, geoLocator, globe); + WorldMap worldMap = new WorldMap(type, point); return worldMap; } /** - * get player position as coords + * get coordinates of player * @param player the player - * @return latitude, longitude + * @return Coordinates * @throws GeoIPException */ - public double[] getPosition(Player player) throws GeoIPException { + public Coordinates getCoordinates(Player player) throws GeoIPException { switch (this.type) { case POINT: @@ -78,10 +70,11 @@ public class WorldMap { if (player.getAddress().getAddress().isAnyLocalAddress()) throw new GeoIPException(player.getName() + "'s IP is local, check your proxy settings"); - return geoLocator.getLocation( - player.getAddress().getAddress()); + return GeoLocator.getCoordinates( + player.getAddress().getAddress() + ); case GLOBE: - return globe.playerPosAsCoords(player.getLocation()); + return Globe.toCoordiates(player.getLocation()); } // this wont happen because we cover each type diff --git a/src/main/java/pl/minecon724/realweather/realtime/RealTimeCommander.java b/src/main/java/pl/minecon724/realweather/realtime/RealTimeCommander.java new file mode 100644 index 0000000..44326f5 --- /dev/null +++ b/src/main/java/pl/minecon724/realweather/realtime/RealTimeCommander.java @@ -0,0 +1,68 @@ +package pl.minecon724.realweather.realtime; + +import java.time.ZoneId; +import java.util.List; + +import org.bukkit.World; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.event.world.WorldUnloadEvent; + +import pl.minecon724.realweather.RW; +import pl.minecon724.realweather.weather.exceptions.DisabledException; + +public class RealTimeCommander implements Listener { + RW plugin; + + List worldNames; + double scale; + ZoneId timezone; + + RealTimeTask task; + + public RealTimeCommander(RW plugin) { + this.plugin = plugin; + } + + public void init(ConfigurationSection config) + throws DisabledException { + + if (!config.getBoolean("enabled")) + throw new DisabledException(); + + try { + timezone = ZoneId.of(config.getString("timezone")); + } catch (Exception e) { + timezone = ZoneId.systemDefault(); + } + + worldNames = config.getStringList("worlds"); + + scale = config.getDouble("scale"); + + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + public void start() { + task = new RealTimeTask(scale, timezone); + + task.runTaskTimer(plugin, 0, 1); + } + + @EventHandler + public void onWorldLoad(WorldLoadEvent event) { + World world = event.getWorld(); + + if (worldNames.contains(world.getName())) + task.worlds.add(world); + } + + @EventHandler + public void onWorldUnload(WorldUnloadEvent event) { + World world = event.getWorld(); + + task.worlds.remove(world); + } +} diff --git a/src/main/java/pl/minecon724/realweather/realtime/RTTask.java b/src/main/java/pl/minecon724/realweather/realtime/RealTimeTask.java similarity index 70% rename from src/main/java/pl/minecon724/realweather/realtime/RTTask.java rename to src/main/java/pl/minecon724/realweather/realtime/RealTimeTask.java index 80ea609..68a4dea 100644 --- a/src/main/java/pl/minecon724/realweather/realtime/RTTask.java +++ b/src/main/java/pl/minecon724/realweather/realtime/RealTimeTask.java @@ -5,24 +5,17 @@ import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.scheduler.BukkitRunnable; -public class RTTask extends BukkitRunnable { +public class RealTimeTask extends BukkitRunnable { double timeScale; ZoneId timezone; - List worlds; + List worlds = new ArrayList<>(); - public RTTask(double timeScale, ZoneId timezone, List worlds) { + public RealTimeTask(double timeScale, ZoneId timezone) { this.timeScale = timeScale; this.timezone = timezone; - this.worlds = new ArrayList(); - for (String s : worlds) { - World world = Bukkit.getWorld(s); - if (world == null) continue; - this.worlds.add(world); - } } @Override diff --git a/src/main/java/pl/minecon724/realweather/weather/GetStateTask.java b/src/main/java/pl/minecon724/realweather/weather/GetStateTask.java index 4ba6bdb..eeb8568 100644 --- a/src/main/java/pl/minecon724/realweather/weather/GetStateTask.java +++ b/src/main/java/pl/minecon724/realweather/weather/GetStateTask.java @@ -1,19 +1,20 @@ package pl.minecon724.realweather.weather; -import java.util.List; +import java.util.HashMap; +import java.util.Map; import java.util.logging.Logger; import org.bukkit.Bukkit; -import org.bukkit.WeatherType; -import org.bukkit.World; import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; import org.bukkit.scheduler.BukkitRunnable; +import pl.minecon724.realweather.map.Coordinates; import pl.minecon724.realweather.map.WorldMap; import pl.minecon724.realweather.map.WorldMap.Type; import pl.minecon724.realweather.map.exceptions.GeoIPException; -import pl.minecon724.realweather.weather.WeatherState.ConditionSimple; import pl.minecon724.realweather.weather.WeatherState.State; +import pl.minecon724.realweather.weather.events.WeatherSyncEvent; import pl.minecon724.realweather.weather.provider.Provider; public class GetStateTask extends BukkitRunnable { @@ -22,16 +23,17 @@ public class GetStateTask extends BukkitRunnable { Provider provider; WorldMap worldMap; - List worlds; + + State storedState; + Map playerStoredState = new HashMap<>(); + PluginManager pluginManager = Bukkit.getPluginManager(); public GetStateTask( Provider provider, - WorldMap worldMap, - List worlds + WorldMap worldMap ) { this.provider = provider; this.worldMap = worldMap; - this.worlds = worlds; } // That's a lot of variables @@ -40,32 +42,44 @@ public class GetStateTask extends BukkitRunnable { public void run() { if (worldMap.getType() == Type.POINT) { - double[] position; + Coordinates coordinates; try { - position = worldMap.getPosition(null); + coordinates = worldMap.getCoordinates(null); } catch (GeoIPException e) { return; } - State state = provider.request_state(position); - - for (World world : worlds) { - if (world == null) return; - world.setThundering(state.getSimple() == ConditionSimple.THUNDER ? true : false); - world.setStorm(state.getSimple() == ConditionSimple.CLEAR ? false : true); + State state = provider.request_state(coordinates); + + if (!state.equals(storedState)) { + pluginManager.callEvent( + new WeatherSyncEvent(null, storedState, state) + ); + + storedState = state; } } else { for (Player player : Bukkit.getOnlinePlayers()) { - double[] position; + Coordinates coordinates; try { - position = worldMap.getPosition(player); + coordinates = worldMap.getCoordinates(player); } catch (GeoIPException e) { logger.info("GeoIP error for " + player.getName()); e.printStackTrace(); continue; } - State state = provider.request_state(position); - player.setPlayerWeather(state.getSimple() == ConditionSimple.CLEAR ? WeatherType.CLEAR : WeatherType.DOWNFALL); + State state = provider.request_state(coordinates); + + if (!state.equals(playerStoredState.get(player))) { + pluginManager.callEvent( + new WeatherSyncEvent( + player, + playerStoredState.get(player), + state) + ); + + playerStoredState.put(player, state); + } } } diff --git a/src/main/java/pl/minecon724/realweather/weather/Providers.java b/src/main/java/pl/minecon724/realweather/weather/Providers.java index 9983e03..70ec60f 100644 --- a/src/main/java/pl/minecon724/realweather/weather/Providers.java +++ b/src/main/java/pl/minecon724/realweather/weather/Providers.java @@ -2,7 +2,6 @@ package pl.minecon724.realweather.weather; import org.bukkit.configuration.ConfigurationSection; -import pl.minecon724.realweather.weather.exceptions.ProviderException; import pl.minecon724.realweather.weather.provider.OpenWeatherMapProvider; import pl.minecon724.realweather.weather.provider.Provider; @@ -15,8 +14,7 @@ public class Providers { * @throws ProviderException * @see Provider */ - public static Provider getByName(String name, ConfigurationSection config) - throws ProviderException { + public static Provider getByName(String name, ConfigurationSection config) { switch (name) { case "openweathermap": @@ -26,8 +24,7 @@ public class Providers { return null; } - public static OpenWeatherMapProvider openWeatherMap(ConfigurationSection config) - throws ProviderException { + public static OpenWeatherMapProvider openWeatherMap(ConfigurationSection config) { return new OpenWeatherMapProvider( config.getString("apiKey")); diff --git a/src/main/java/pl/minecon724/realweather/weather/WeatherChanger.java b/src/main/java/pl/minecon724/realweather/weather/WeatherChanger.java new file mode 100644 index 0000000..744239f --- /dev/null +++ b/src/main/java/pl/minecon724/realweather/weather/WeatherChanger.java @@ -0,0 +1,55 @@ +package pl.minecon724.realweather.weather; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.event.world.WorldUnloadEvent; + +import pl.minecon724.realweather.weather.WeatherState.State; +import pl.minecon724.realweather.weather.events.WeatherSyncEvent; + +public class WeatherChanger implements Listener { + private List worldNames; + private List worlds = new ArrayList<>(); + + public WeatherChanger(List worldNames) { + this.worldNames = worldNames; + } + + @EventHandler + public void onWorldLoad(WorldLoadEvent event) { + World world = event.getWorld(); + + if (worldNames.contains(world.getName())) + worlds.add(world); + } + + @EventHandler + public void onWorldUnload(WorldUnloadEvent event) { + World world = event.getWorld(); + + worlds.remove(world); + } + + @EventHandler + public void onWeatherSync(WeatherSyncEvent event) { + Player player = event.getPlayer(); + State state = event.getState(); + + if (player != null) { + player.sendMessage("local: " + state.getCondition().name() + " " + + state.getLevel().name() + " " + state.getSimple().name()); + } else { + Bukkit.getServer().broadcastMessage("global: " + state.getCondition().name() + " " + + state.getLevel().name() + " " + state.getSimple().name()); + } + + } + +} diff --git a/src/main/java/pl/minecon724/realweather/weather/WeatherCommander.java b/src/main/java/pl/minecon724/realweather/weather/WeatherCommander.java index d17c9b8..5c36de0 100644 --- a/src/main/java/pl/minecon724/realweather/weather/WeatherCommander.java +++ b/src/main/java/pl/minecon724/realweather/weather/WeatherCommander.java @@ -1,15 +1,12 @@ package pl.minecon724.realweather.weather; -import java.util.ArrayList; import java.util.List; -import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import pl.minecon724.realweather.RW; import pl.minecon724.realweather.map.WorldMap; import pl.minecon724.realweather.weather.exceptions.DisabledException; -import pl.minecon724.realweather.weather.exceptions.ProviderException; import pl.minecon724.realweather.weather.provider.Provider; public class WeatherCommander { @@ -17,7 +14,7 @@ public class WeatherCommander { RW plugin; boolean enabled; - List worlds; + List worldNames; String providerName; Provider provider; ConfigurationSection providerConfig; @@ -36,13 +33,13 @@ public class WeatherCommander { * @throws ProviderException if invalid provider config */ public void init(ConfigurationSection config) - throws DisabledException, ProviderException { + throws DisabledException, IllegalArgumentException { enabled = config.getBoolean("enabled"); if (!enabled) throw new DisabledException(); - worlds = config.getStringList("worlds"); + worldNames = config.getStringList("worlds"); providerName = config.getString("provider.choice"); @@ -51,13 +48,16 @@ public class WeatherCommander { .getConfigurationSection(providerName); provider = Providers.getByName(providerName, providerConfig); + if (provider == null) + throw new IllegalArgumentException("Invalid provider: " + providerName); provider.init(); + + plugin.getServer().getPluginManager().registerEvents( + new WeatherChanger(worldNames), plugin); } public void start() { - getStateTask = new GetStateTask(provider, - worldMap, - new ArrayList()); + getStateTask = new GetStateTask(provider, worldMap); getStateTask.runTaskTimerAsynchronously(plugin, 0, 1200); } diff --git a/src/main/java/pl/minecon724/realweather/weather/WeatherState.java b/src/main/java/pl/minecon724/realweather/weather/WeatherState.java index 738c86c..caa5cbd 100644 --- a/src/main/java/pl/minecon724/realweather/weather/WeatherState.java +++ b/src/main/java/pl/minecon724/realweather/weather/WeatherState.java @@ -59,5 +59,11 @@ public class WeatherState { public ConditionSimple getSimple() { return simple; } + + public boolean equals(State state) { + return (state != null + && this.getCondition() == state.getCondition() + && this.getLevel() == state.getLevel()); + } } } diff --git a/src/main/java/pl/minecon724/realweather/weather/events/WeatherSyncEvent.java b/src/main/java/pl/minecon724/realweather/weather/events/WeatherSyncEvent.java new file mode 100644 index 0000000..2dcafbf --- /dev/null +++ b/src/main/java/pl/minecon724/realweather/weather/events/WeatherSyncEvent.java @@ -0,0 +1,39 @@ +package pl.minecon724.realweather.weather.events; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +import pl.minecon724.realweather.weather.WeatherState.State; + +public class WeatherSyncEvent extends PlayerEvent { + private static final HandlerList HANDLERS = new HandlerList(); + + private State oldState; + private State state; + + public WeatherSyncEvent(Player player, State oldState, State state) { + super(player); + + this.oldState = oldState; + this.state = state; + } + + @Override + public HandlerList getHandlers() { + return HANDLERS; + } + + public static HandlerList getHandlerList() { + return HANDLERS; + } + + public State getOldState() { + return oldState; + } + + public State getState() { + return state; + } + +} diff --git a/src/main/java/pl/minecon724/realweather/weather/exceptions/ProviderException.java b/src/main/java/pl/minecon724/realweather/weather/exceptions/ProviderException.java deleted file mode 100644 index 27063af..0000000 --- a/src/main/java/pl/minecon724/realweather/weather/exceptions/ProviderException.java +++ /dev/null @@ -1,5 +0,0 @@ -package pl.minecon724.realweather.weather.exceptions; - -public class ProviderException extends Exception { - -} diff --git a/src/main/java/pl/minecon724/realweather/weather/provider/OpenWeatherMapProvider.java b/src/main/java/pl/minecon724/realweather/weather/provider/OpenWeatherMapProvider.java index a077d40..82b9d90 100644 --- a/src/main/java/pl/minecon724/realweather/weather/provider/OpenWeatherMapProvider.java +++ b/src/main/java/pl/minecon724/realweather/weather/provider/OpenWeatherMapProvider.java @@ -9,6 +9,7 @@ import java.nio.charset.Charset; import org.json.JSONObject; +import pl.minecon724.realweather.map.Coordinates; import pl.minecon724.realweather.weather.WeatherState.*; public class OpenWeatherMapProvider implements Provider { @@ -29,13 +30,13 @@ public class OpenWeatherMapProvider implements Provider { } } - public State request_state(double[] coords) { + public State request_state(Coordinates coordinates) { JSONObject json = new JSONObject(); try { URL url = new URL( endpoint + String.format("/data/2.5/weather?lat=%s&lon=%s&appid=%s", - Double.toString(coords[0]), Double.toString(coords[1]), apiKey + Double.toString(coordinates.latitude), Double.toString(coordinates.longitude), apiKey )); InputStream is = url.openStream(); diff --git a/src/main/java/pl/minecon724/realweather/weather/provider/Provider.java b/src/main/java/pl/minecon724/realweather/weather/provider/Provider.java index 7527300..91206e9 100644 --- a/src/main/java/pl/minecon724/realweather/weather/provider/Provider.java +++ b/src/main/java/pl/minecon724/realweather/weather/provider/Provider.java @@ -1,9 +1,10 @@ package pl.minecon724.realweather.weather.provider; +import pl.minecon724.realweather.map.Coordinates; import pl.minecon724.realweather.weather.WeatherState; public interface Provider { public void init(); - public WeatherState.State request_state(double[] coords); + public WeatherState.State request_state(Coordinates coordinates); public String getName(); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 905f94e..0923e2b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -44,7 +44,7 @@ map: # for example; if a player's position on map converts to 94 degrees (out of bounds), it becomes -86 degrees wrap: true -realtime: +time: # warning: this removes sleep enabled: false @@ -59,15 +59,9 @@ realtime: timezone: 'auto' # x day cycles / 24 hrs - timeScale: 1.0 + scale: 1.0 - # How often should we recalculate the time (in ticks) - # Very minimal impact on performance - interval: 1 - - # makes time visible to players not in sync with server - virtual: false - - # if above true, locks the server's time (in ticks) - # -1 to disable - lock: 0 + # TODO + # time based on... time? + # uses settings from map + real: false