diff --git a/.idea/modules.xml b/.idea/modules.xml
index 4f03be1..fceb931 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/realweather.iml b/.idea/realweather.iml
new file mode 100644
index 0000000..a589521
--- /dev/null
+++ b/.idea/realweather.iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+ SPIGOT
+
+ 1
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 556bedd..10e6151 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,7 +46,7 @@
eu.m724
wtapi
- 0.8.3
+ 0.9.2
eu.m724
diff --git a/src/main/java/eu/m724/realweather/RealWeatherPlugin.java b/src/main/java/eu/m724/realweather/RealWeatherPlugin.java
index f8c53f3..088413f 100644
--- a/src/main/java/eu/m724/realweather/RealWeatherPlugin.java
+++ b/src/main/java/eu/m724/realweather/RealWeatherPlugin.java
@@ -7,6 +7,7 @@ import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.logging.Logger;
+import eu.m724.wtapi.provider.exception.NoSuchProviderException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
@@ -26,7 +27,6 @@ import eu.m724.realweather.updater.UpdaterConfig;
import eu.m724.realweather.weather.PlayerWeatherCache;
import eu.m724.realweather.weather.WeatherConfig;
import eu.m724.realweather.weather.WeatherMaster;
-import eu.m724.wtapi.provider.exception.NoSuchProviderException;
import eu.m724.wtapi.provider.exception.ProviderException;
// TODO unmess this too
@@ -110,8 +110,8 @@ public class RealWeatherPlugin extends JavaPlugin {
updater = PluginUpdater.build(this, this.getFile());
//updater.init();
} catch (UserError | NoSuchProviderException e) {
- logger.severe("There are errors in your config:");
- logger.severe(e.getMessage());
+ logger.severe("There's an error in your config:");
+ logger.severe(" " + e.getMessage());
getServer().getPluginManager().disablePlugin(this);
return;
diff --git a/src/main/java/eu/m724/realweather/commands/GeoCommand.java b/src/main/java/eu/m724/realweather/commands/GeoCommand.java
index bdda541..82fe36c 100644
--- a/src/main/java/eu/m724/realweather/commands/GeoCommand.java
+++ b/src/main/java/eu/m724/realweather/commands/GeoCommand.java
@@ -1,8 +1,5 @@
package eu.m724.realweather.commands;
-import net.md_5.bungee.api.chat.*;
-import net.md_5.bungee.api.chat.hover.content.Content;
-import net.md_5.bungee.api.chat.hover.content.Text;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -11,13 +8,11 @@ import org.bukkit.entity.Player;
import eu.m724.realweather.GlobalConstants;
import eu.m724.realweather.mapper.Mapper;
-import eu.m724.realweather.weather.PlayerWeatherCache;
import eu.m724.wtapi.object.Coordinates;
-import eu.m724.wtapi.object.Weather;
import net.md_5.bungee.api.ChatColor;
public class GeoCommand implements CommandExecutor {
- private final PlayerWeatherCache playerWeatherCache = GlobalConstants.getPlayerWeatherCache();
+ //private final PlayerWeatherCache playerWeatherCache = GlobalConstants.getPlayerWeatherCache();
private final Mapper mapper = GlobalConstants.getMapper();
@Override
@@ -29,14 +24,16 @@ public class GeoCommand implements CommandExecutor {
Location location = player.getLocation();
Coordinates coordinates = mapper.locationToCoordinates(location);
- Weather weather = playerWeatherCache.getWeather(player);
- String address = formatAddress(weather);
+ //Weather weather = playerWeatherCache.getWeather(player);
+ //String address = formatAddress(weather);
colorize(player, "");
- colorize(player, "&6Geolocation: &b%f&7, %b%f &7(lat, lon)", coordinates.latitude, coordinates.longitude);
- colorize(player, "&7Position: &3%f&8, %3%f &8(x, z)", location.getX(), location.getZ());
- colorize(player, "&7City: &3%s", address);
+ colorize(player, "&6Geolocation: &b%f&7, &b%f &7(lat, lon)", coordinates.latitude(), coordinates.longitude());
+ colorize(player, "&7In-game Position: &3%f&8, &3%f &8(x, z)", location.getX(), location.getZ());
+ //colorize(player, "&7City: &3%s", address);
colorize(player, "");
+ } else {
+ sender.sendMessage("You can't run this command without arguments as console");
}
} else if (args.length >= 3) {
colorize(sender, "&cInvalid arguments, &7make sure it's &a\"/geo lat,lon\" &7or &a\"/geo x z\" &7or just &a\"/geo\"");
@@ -55,12 +52,10 @@ public class GeoCommand implements CommandExecutor {
Coordinates coordinates = mapper.locationToCoordinates(location);
colorize(sender, "");
- colorize(sender, "&6Position: &b%f&7, %b%f &7(x, z)", location.getX(), location.getZ());
- colorize(sender, "&7Geolocation: &3%f&8, %3%f &8(lat, lon)", coordinates.latitude, coordinates.longitude);
- colorize(sender, "&7Input interpreted as position, because you separated with a space");
+ colorize(sender, "&6In-game Position: &b%f&7, &b%f &7(x, z)", location.getX(), location.getZ());
+ colorize(sender, "&7Geolocation: &3%f&8, &3%f &8(lat, lon)", coordinates.latitude(), coordinates.longitude());
+ colorize(sender, "&7Input interpreted as position, because you separated it with a space");
colorize(sender, "");
-
- return true;
} else {
double latitude, longitude;
@@ -77,8 +72,8 @@ public class GeoCommand implements CommandExecutor {
Location location = mapper.coordinatesToLocation(null, coordinates);
colorize(sender, "");
- colorize(sender, "&6Position: &b%f&7, %b%f &7(x, z)", location.getX(), location.getZ());
- colorize(sender, "&7Geolocation: &3%f&8, %3%f &8(lat, lon)", coordinates.latitude, coordinates.longitude);
+ colorize(sender, "&6In-game Position: &b%f&7, &b%f &7(x, z)", location.getX(), location.getZ());
+ colorize(sender, "&7Geolocation: &3%f&8, &3%f &8(lat, lon)", coordinates.latitude(), coordinates.longitude());
colorize(sender, "&7Input interpreted as geolocation, because you separated with a comma");
colorize(sender, "");
}
@@ -89,18 +84,4 @@ public class GeoCommand implements CommandExecutor {
private void colorize(CommandSender sender, String text, Object... format) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', text.formatted(format)));
}
-
- private String formatAddress(Weather weather) {
- if (weather == null) return "Not retrieved yet";
- Coordinates coordinates = weather.coordinates;
-
- if (coordinates.country == null && coordinates.city == null)
- return "Unknown";
- else if (coordinates.city == null)
- return "Somewhere in " + coordinates.country;
- else if (coordinates.country == null)
- return coordinates.city;
- return coordinates.city + ", " + coordinates.country;
- }
-
}
diff --git a/src/main/java/eu/m724/realweather/commands/LocalTimeCommand.java b/src/main/java/eu/m724/realweather/commands/LocalTimeCommand.java
index 310de58..7c894f5 100644
--- a/src/main/java/eu/m724/realweather/commands/LocalTimeCommand.java
+++ b/src/main/java/eu/m724/realweather/commands/LocalTimeCommand.java
@@ -49,7 +49,7 @@ public class LocalTimeCommand implements CommandExecutor {
if (timeConfig.dynamic() && player != null && player.hasPermission("realweather.dynamic")) {
Coordinates coordinates = mapper.locationToCoordinates(player.getLocation());
- long offsetTime = timeConverter.calculateZoneOffset(coordinates.longitude);
+ long offsetTime = timeConverter.calculateZoneOffset(coordinates.longitude());
long offsetTimeTicks = timeConverter.millisToTicks(offsetTime);
boolean negative = offsetTime < 0;
diff --git a/src/main/java/eu/m724/realweather/commands/LocalWeatherCommand.java b/src/main/java/eu/m724/realweather/commands/LocalWeatherCommand.java
index 1439b36..d810c20 100644
--- a/src/main/java/eu/m724/realweather/commands/LocalWeatherCommand.java
+++ b/src/main/java/eu/m724/realweather/commands/LocalWeatherCommand.java
@@ -3,6 +3,8 @@ package eu.m724.realweather.commands;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.Command;
@@ -28,25 +30,24 @@ public class LocalWeatherCommand implements CommandExecutor {
if (weather != null) {
long lastUpdate = playerWeatherCache.getLastUpdate(player);
- colorize(sender, "\n&e" + weather.description);
-
- if (weather.rainSeverity != null)
- colorize(sender, "&6Rain: &b%s", weather.rainSeverity.toString());
- if (weather.drizzleSeverity != null)
- colorize(sender, "&6Drizzle: &b%s", weather.drizzleSeverity.toString());
- if (weather.sleetSeverity != null)
- colorize(sender, "&6Sleet: &b%s", weather.sleetSeverity.toString());
- if (weather.snowSeverity != null)
- colorize(sender, "&6Snow: &b%s", weather.snowSeverity.toString());
- if (weather.thunderstormSeverity != null)
- colorize(sender, "&6Thunderstorm: &b%s", weather.thunderstormSeverity.toString());
- if (weather.shower)
- colorize(sender, "&6Shower");
- colorize(sender, "&6Cloudiness: &b%f&7%%", weather.cloudiness * 100);
- colorize(sender, "&6Humidity: &b%f&7%%", weather.humidity * 100);
- colorize(sender, "&6Temperature: &b%f&7°C (feels like %f°C)", weather.temperature - 273.15, weather.temperatureApparent - 273.15);
- colorize(sender, "&6Wind: &b%f&7m/s (gust %fm/s)", weather.windSpeed, weather.windGust);
+ colorize(sender, "&6Weather for: &b%f&7, &b%f &7(lat, lon)\n", weather.coordinates().latitude(), weather.coordinates().longitude());
+
+ List states = new ArrayList<>(3);
+
+ if (weather.raining()) states.add("Raining");
+ if (weather.thundering()) states.add("Thundering");
+ if (weather.thundering()) states.add("Snowing");
+
+ if (!states.isEmpty()) {
+ colorize(sender, "&6" + String.join(", ", states));
+ }
+
+ colorize(sender, "&6Temperature: &b%.1f&7°C (feels like %.1f°C)", weather.temperatureCelsius(), weather.temperatureApparentCelsius());
+
+ colorize(sender, "&6Cloud cover (cloudiness): &b%.0f&7%%", weather.cloudCoverPercentage() * 100);
+ colorize(sender, "&6Relative humidity: &b%.0f&7%%", weather.relativeHumidityPercentage() * 100);
+
colorize(sender, "&6Last update: &b%s UTC\n", formatTime(lastUpdate));
} else {
diff --git a/src/main/java/eu/m724/realweather/mapper/Mapper.java b/src/main/java/eu/m724/realweather/mapper/Mapper.java
index 06b772d..01c8fbe 100644
--- a/src/main/java/eu/m724/realweather/mapper/Mapper.java
+++ b/src/main/java/eu/m724/realweather/mapper/Mapper.java
@@ -69,8 +69,8 @@ public class Mapper {
* @return the location in {@code world}
*/
public Location coordinatesToLocation(World world, Coordinates coordinates) {
- double x = coordinates.longitude * config.scaleLongitude;
- double z = -coordinates.latitude * config.scaleLatitude;
+ double x = coordinates.longitude() * config.scaleLongitude;
+ double z = -coordinates.latitude() * config.scaleLatitude;
return new Location(world, x, 0, z);
}
diff --git a/src/main/java/eu/m724/realweather/thunder/StrikeTask.java b/src/main/java/eu/m724/realweather/thunder/StrikeTask.java
new file mode 100644
index 0000000..6e14e2c
--- /dev/null
+++ b/src/main/java/eu/m724/realweather/thunder/StrikeTask.java
@@ -0,0 +1,34 @@
+package eu.m724.realweather.thunder;
+
+import eu.m724.realweather.DebugLogger;
+import eu.m724.realweather.GlobalConstants;
+import eu.m724.realweather.mapper.Mapper;
+import eu.m724.wtapi.provider.thunder.TimedStrike;
+import org.bukkit.Location;
+import org.bukkit.scheduler.BukkitRunnable;
+
+public class StrikeTask extends BukkitRunnable {
+ private final Mapper mapper = GlobalConstants.getMapper();
+ private final TimedStrike strike;
+
+ public StrikeTask(TimedStrike strike) {
+ this.strike = strike;
+ }
+
+ @Override
+ public void run() {
+ DebugLogger.info("strike: %f %f", 2, strike.coordinates().latitude(), strike.coordinates().longitude());
+
+ mapper.getWorlds().forEach(w -> {
+ Location location = mapper.coordinatesToLocation(w, strike.coordinates());
+ DebugLogger.info("in %s that converts to: %d %d", 2, w.getName(), location.getBlockX(), location.getBlockZ());
+
+ // World#isLoaded, Chunk#isLoaded and probably others using Chunk, load the chunk and always return true
+ if (w.isChunkLoaded(location.getBlockX() / 16, location.getBlockZ() / 16)) {
+ location.setY(w.getHighestBlockYAt(location) + 1);
+ w.strikeLightning(location);
+ DebugLogger.info("spawned lightning in %s on y level %d", 2, w.getName(), location.getBlockY());
+ }
+ });
+ }
+}
diff --git a/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java b/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java
index eb3b815..ef6ad6a 100644
--- a/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java
+++ b/src/main/java/eu/m724/realweather/thunder/ThunderMaster.java
@@ -1,16 +1,21 @@
package eu.m724.realweather.thunder;
import eu.m724.realweather.Configs;
+import eu.m724.realweather.GlobalConstants;
+import eu.m724.realweather.mapper.Mapper;
+import eu.m724.wtapi.provider.exception.NoSuchProviderException;
import org.bukkit.plugin.Plugin;
import eu.m724.realweather.DebugLogger;
import eu.m724.wtapi.provider.Providers;
-import eu.m724.wtapi.provider.exception.NoSuchProviderException;
import eu.m724.wtapi.provider.exception.ProviderException;
import eu.m724.wtapi.provider.thunder.ThunderProvider;
public class ThunderMaster {
+ private final Plugin plugin = GlobalConstants.getPlugin();
private final ThunderConfig config = Configs.thunderConfig();
+ private final Mapper mapper = GlobalConstants.getMapper();
+
private ThunderProvider provider;
/**
@@ -23,11 +28,11 @@ public class ThunderMaster {
return;
provider = Providers.getThunderProvider(config.provider(), null);
- provider.init();
- ThunderTask thunderTask = new ThunderTask(provider);
- thunderTask.init();
- thunderTask.runTaskTimer(plugin, 0, config.refreshPeriod());
+ provider.registerStrikeConsumer(strike -> new StrikeTask(strike).runTaskLaterAsynchronously(plugin, 0));
+
+ provider.start();
+ DebugLogger.info("thunderprovider started", 3);
DebugLogger.info("thunder loaded", 1);
}
diff --git a/src/main/java/eu/m724/realweather/thunder/ThunderTask.java b/src/main/java/eu/m724/realweather/thunder/ThunderTask.java
deleted file mode 100644
index 553ec1c..0000000
--- a/src/main/java/eu/m724/realweather/thunder/ThunderTask.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package eu.m724.realweather.thunder;
-
-import java.util.ArrayList;
-
-import org.bukkit.Location;
-import org.bukkit.scheduler.BukkitRunnable;
-
-import eu.m724.realweather.DebugLogger;
-import eu.m724.realweather.GlobalConstants;
-import eu.m724.realweather.mapper.Mapper;
-import eu.m724.wtapi.provider.thunder.ThunderProvider;
-import eu.m724.wtapi.provider.thunder.impl.blitzortung.TimedStrike;
-
-class ThunderTask extends BukkitRunnable {
- private final ThunderProvider thunderProvider;
- private final Mapper mapper = GlobalConstants.getMapper();
- private final ArrayList strikes = new ArrayList<>();
-
- public ThunderTask(ThunderProvider thunderProvider) {
- this.thunderProvider = thunderProvider;
- }
-
- public void init() {
- thunderProvider.registerStrikeHandler(coords -> {
- strikes.add(new TimedStrike(System.currentTimeMillis() + thunderProvider.getDelay(), coords));
- });
- thunderProvider.start();
- DebugLogger.info("thunderprovider started", 3);
- }
-
- @Override
- public void run() {
- DebugLogger.info("thundertask running", 3);
- thunderProvider.tick();
-
- while (!strikes.isEmpty()) {
- TimedStrike strike = strikes.removeFirst();
-
- DebugLogger.info("strike: %f %f", 2, strike.coordinates.latitude, strike.coordinates.longitude);
-
- mapper.getWorlds().forEach(w -> {
- Location location = mapper.coordinatesToLocation(w, strike.coordinates);
- DebugLogger.info("in %s that converts to: %d %d", 2, w.getName(), location.getBlockX(), location.getBlockZ());
-
- // World#isLoaded, Chunk#isLoaded and probably others using Chunk, load the chunk and always return true
- if (w.isChunkLoaded(location.getBlockX() / 16, location.getBlockZ() / 16)) {
- location.setY(w.getHighestBlockYAt(location) + 1);
- w.strikeLightning(location);
- DebugLogger.info("spawned lightning in %s on y level %d", 2, w.getName(), location.getBlockY());
- }
-
- });
- }
-
- }
-
-}
diff --git a/src/main/java/eu/m724/realweather/time/AsyncPlayerTimeTask.java b/src/main/java/eu/m724/realweather/time/AsyncPlayerTimeTask.java
index 8d15735..e35729b 100644
--- a/src/main/java/eu/m724/realweather/time/AsyncPlayerTimeTask.java
+++ b/src/main/java/eu/m724/realweather/time/AsyncPlayerTimeTask.java
@@ -27,7 +27,7 @@ public class AsyncPlayerTimeTask extends BukkitRunnable {
Coordinates coordinates = mapper.locationToCoordinates(player.getLocation());
- long time = timeConverter.calculateZoneOffset(coordinates.longitude);
+ long time = timeConverter.calculateZoneOffset(coordinates.longitude());
long ticks = timeConverter.millisToTicks(time);
player.setPlayerTime(ticks, true);
diff --git a/src/main/java/eu/m724/realweather/time/SyncTimeUpdateTask.java b/src/main/java/eu/m724/realweather/time/SyncTimeUpdateTask.java
index 95e43b4..fd6d1a1 100644
--- a/src/main/java/eu/m724/realweather/time/SyncTimeUpdateTask.java
+++ b/src/main/java/eu/m724/realweather/time/SyncTimeUpdateTask.java
@@ -17,7 +17,7 @@ public class SyncTimeUpdateTask extends BukkitRunnable {
SyncTimeUpdateTask(TimeConverter timeConverter, boolean dynamic) {
this.timeConverter = timeConverter;
- this.zoneOffset = !dynamic ? timeConverter.calculateZoneOffset(mapper.getPoint().longitude) : 0;
+ this.zoneOffset = !dynamic ? timeConverter.calculateZoneOffset(mapper.getPoint().longitude()) : 0;
}
@Override
diff --git a/src/main/java/eu/m724/realweather/weather/DynamicWeatherRetriever.java b/src/main/java/eu/m724/realweather/weather/DynamicWeatherRetriever.java
index de5cd42..5118cd0 100644
--- a/src/main/java/eu/m724/realweather/weather/DynamicWeatherRetriever.java
+++ b/src/main/java/eu/m724/realweather/weather/DynamicWeatherRetriever.java
@@ -1,15 +1,15 @@
package eu.m724.realweather.weather;
+import java.time.ZoneOffset;
import java.util.*;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionException;
+import eu.m724.wtapi.provider.weather.WeatherQueryResult;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
-import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
@@ -91,7 +91,7 @@ public class DynamicWeatherRetriever extends BukkitRunnable implements Listener
if (now > nextUpdate) {
coordinates = makeCoordinates(server.getOnlinePlayers());
// calculate acceptable request rate based on weather provider quota and active players
- float hourly = weatherProvider.getQuotaHourly() / (float)(weatherProvider.getBulkLimit() * coordinates.coordinatesCount());
+ float hourly = (float) weatherProvider.getQuota().getHourlyQuota() / coordinates.coordinatesCount();
nextUpdate = now + Math.max(60000, (long) (3600000 / hourly));
DebugLogger.info("Next update in %d", 3, nextUpdate);
} else { // immediate update for those that need it right now
@@ -102,28 +102,38 @@ public class DynamicWeatherRetriever extends BukkitRunnable implements Listener
}
Coordinates[] coordinatesArray = coordinates.coordinatesPlayersMap().keySet().toArray(Coordinates[]::new);
- // TODO change to Collection in wtapi? but some ordered kind
- CompletableFuture weathersFuture =
- weatherProvider.getWeatherBulk(coordinatesArray);
+ if (coordinatesArray.length == 0) {
+ DebugLogger.info("nothing to update, dynamic retriever done", 3);
+ return;
+ }
- try {
- Weather[] weathers = weathersFuture.join();
- for (int i=0; i weathersFuture =
+ weatherProvider.getWeather(coordinatesArray);
- AsyncWeatherUpdateEvent event =
- new AsyncWeatherUpdateEvent(player, weather);
+ WeatherQueryResult result = weathersFuture.join();
- server.getPluginManager().callEvent(event);
- }
+ if (result.exception() != null) {
+ DebugLogger.info("An error occurred trying to retrieve weather data", 0);
+
+ if (DebugLogger.getDebugLevel() > 0) {
+ result.exception().printStackTrace();
+ }
+
+ return;
+ }
+
+ Weather[] weathers = result.weathers();
+
+ for (int i=0; i 0)
- e.printStackTrace();
}
DebugLogger.info("dynamic retriever done", 3);
diff --git a/src/main/java/eu/m724/realweather/weather/StaticWeatherRetriever.java b/src/main/java/eu/m724/realweather/weather/StaticWeatherRetriever.java
index 4790fd9..b2d60b7 100644
--- a/src/main/java/eu/m724/realweather/weather/StaticWeatherRetriever.java
+++ b/src/main/java/eu/m724/realweather/weather/StaticWeatherRetriever.java
@@ -7,12 +7,10 @@ import eu.m724.realweather.mapper.Mapper;
import eu.m724.wtapi.object.Coordinates;
import eu.m724.wtapi.object.Weather;
import eu.m724.wtapi.provider.weather.WeatherProvider;
+import eu.m724.wtapi.provider.weather.WeatherQueryResult;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionException;
-
public class StaticWeatherRetriever extends BukkitRunnable {
private final Plugin plugin = GlobalConstants.getPlugin();
private final Mapper mapper = GlobalConstants.getMapper();
@@ -26,22 +24,25 @@ public class StaticWeatherRetriever extends BukkitRunnable {
@Override
public void run() {
Coordinates point = mapper.getPoint();
- CompletableFuture weatherFuture = weatherProvider.getWeather(point);
- try {
- Weather weather = weatherFuture.join();
+ WeatherQueryResult result = weatherProvider.getWeather(point).join();
- AsyncWeatherUpdateEvent event =
- new AsyncWeatherUpdateEvent(null, weather);
-
- plugin.getServer().getPluginManager().callEvent(event);
- } catch (CompletionException e) { // TODO handle finer exceptions
+ if (result.exception() != null) {
DebugLogger.info("An error occurred trying to retrieve weather data", 0);
if (DebugLogger.getDebugLevel() > 0)
- e.printStackTrace();
+ result.exception().printStackTrace();
+
+ return;
}
+ Weather weather = result.weathers()[0];
+
+ AsyncWeatherUpdateEvent event =
+ new AsyncWeatherUpdateEvent(null, weather);
+
+ plugin.getServer().getPluginManager().callEvent(event);
+
DebugLogger.info("static weather retriever is done", 3);
}
}
diff --git a/src/main/java/eu/m724/realweather/weather/WeatherChanger.java b/src/main/java/eu/m724/realweather/weather/WeatherChanger.java
index 3c7676c..36456ed 100644
--- a/src/main/java/eu/m724/realweather/weather/WeatherChanger.java
+++ b/src/main/java/eu/m724/realweather/weather/WeatherChanger.java
@@ -23,7 +23,7 @@ public class WeatherChanger implements Listener {
if (player != null) { // dynamic mode
DebugLogger.info("Changing weather for player %s", 2, player.getName());
- if (weather.isThundering() || weather.isSnowing() || weather.isRaining()) {
+ if (weather.thundering() || weather.snowing() || weather.raining()) {
player.setPlayerWeather(WeatherType.DOWNFALL);
} else {
player.setPlayerWeather(WeatherType.CLEAR);
@@ -32,11 +32,11 @@ public class WeatherChanger implements Listener {
DebugLogger.info("Changing weather static", 3);
mapper.getWorlds().forEach(w -> {
DebugLogger.info("Changing weather static in world %s", 2, w.getName());
- if (weather.isThundering()) {
+ if (weather.thundering()) {
w.setClearWeatherDuration(0);
w.setWeatherDuration(120000);
w.setThunderDuration(120000);
- } else if (weather.isRaining() || weather.isSnowing()) {
+ } else if (weather.raining() || weather.snowing()) {
w.setClearWeatherDuration(0);
w.setWeatherDuration(120000);
w.setThunderDuration(0);
diff --git a/src/main/java/eu/m724/realweather/weather/WeatherMaster.java b/src/main/java/eu/m724/realweather/weather/WeatherMaster.java
index 6b9b71f..13b13f1 100644
--- a/src/main/java/eu/m724/realweather/weather/WeatherMaster.java
+++ b/src/main/java/eu/m724/realweather/weather/WeatherMaster.java
@@ -1,6 +1,7 @@
package eu.m724.realweather.weather;
import eu.m724.realweather.Configs;
+import eu.m724.wtapi.provider.exception.NoSuchProviderException;
import org.bukkit.GameRule;
import org.bukkit.plugin.Plugin;
@@ -8,7 +9,6 @@ import eu.m724.realweather.DebugLogger;
import eu.m724.realweather.GlobalConstants;
import eu.m724.realweather.mapper.Mapper;
import eu.m724.wtapi.provider.Providers;
-import eu.m724.wtapi.provider.exception.NoSuchProviderException;
import eu.m724.wtapi.provider.exception.ProviderException;
import eu.m724.wtapi.provider.weather.WeatherProvider;
@@ -32,7 +32,7 @@ public class WeatherMaster {
if (config.dynamic()) {
DynamicWeatherRetriever retriever = new DynamicWeatherRetriever(provider);
- retriever.runTaskTimerAsynchronously(plugin,0, 1000);
+ retriever.runTaskTimerAsynchronously(plugin,0, 200);
plugin.getServer().getPluginManager().registerEvents(retriever, plugin);
} else {
StaticWeatherRetriever retriever = new StaticWeatherRetriever(provider);
diff --git a/src/main/resources/modules/weather.yml b/src/main/resources/modules/weather.yml
index 9ca0ebc..84a2ed4 100644
--- a/src/main/resources/modules/weather.yml
+++ b/src/main/resources/modules/weather.yml
@@ -9,10 +9,9 @@
enabled: false
-# Currently only OpenWeatherMap
-provider: openweathermap
-# put your OpenWeatherMap api key
-apiKey: REPLACE ME
+# Currently only OpenMeteo
+provider: openmeteo
+# No API key needed
# How this plugin affects your world:
# - static (false): weather is the same across the world
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index c032403..8560a2c 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -9,7 +9,7 @@ load: STARTUP
main: eu.m724.realweather.RealWeatherPlugin
libraries:
-- org.java-websocket:Java-WebSocket:1.5.7
+- org.java-websocket:Java-WebSocket:1.6.0
commands:
rwadmin: