From 4e3f04ee79a40b42155c53e8209f0e132cc87786 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sat, 11 Jun 2022 14:49:25 +0000 Subject: [PATCH] preparing for 0.4 --- pom.xml | 2 +- .../minecon724/realweather/GetStateTask.java | 2 +- .../java/pl/minecon724/realweather/RW.java | 20 +++++++++++ .../commands/RealWeatherCommand.java | 15 ++++++++ .../realweather/realtime/RTTask.java | 36 +++++++++++++++++++ src/main/resources/config.yml | 13 +++++++ src/main/resources/plugin.yml | 6 +++- 7 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 src/main/java/pl/minecon724/realweather/commands/RealWeatherCommand.java create mode 100644 src/main/java/pl/minecon724/realweather/realtime/RTTask.java diff --git a/pom.xml b/pom.xml index 1147d22..759d3ce 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 pl.minecon724 realweather - 0.3.0 + 0.4.0 17 diff --git a/src/main/java/pl/minecon724/realweather/GetStateTask.java b/src/main/java/pl/minecon724/realweather/GetStateTask.java index c4556ea..6b2183b 100644 --- a/src/main/java/pl/minecon724/realweather/GetStateTask.java +++ b/src/main/java/pl/minecon724/realweather/GetStateTask.java @@ -126,7 +126,7 @@ public class GetStateTask extends BukkitRunnable { coords = mapUtils.playerPosAsCoords(p.getLocation(), scaleLat, scaleLon, onExceed); lon = coords[0]; lat = coords[1]; - logger.info( String.format( "%s's location is %f, %f", p.getName(), lat, lon )); + if (debug) logger.info( String.format( "%s's location is %f, %f", p.getName(), lat, lon )); state = provider.request_state(lat, lon); if (debug) logger.info( String.format( "Provider returned state %s %s for %f, %f", state.condition.name(), state.level.name(), lat, lon diff --git a/src/main/java/pl/minecon724/realweather/RW.java b/src/main/java/pl/minecon724/realweather/RW.java index 542b58e..8458480 100644 --- a/src/main/java/pl/minecon724/realweather/RW.java +++ b/src/main/java/pl/minecon724/realweather/RW.java @@ -1,5 +1,6 @@ package pl.minecon724.realweather; +import java.time.ZoneId; import java.util.List; import com.maxmind.geoip2.WebServiceClient; @@ -9,7 +10,9 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; +import pl.minecon724.realweather.commands.RealWeatherCommand; import pl.minecon724.realweather.provider.OpenWeatherMapProvider; +import pl.minecon724.realweather.realtime.RTTask; import pl.minecon724.realweather.thirdparty.Metrics; public class RW extends JavaPlugin { @@ -28,6 +31,7 @@ public class RW extends JavaPlugin { ConfigurationSection providerSec = config.getConfigurationSection("provider"); ConfigurationSection settingsSec = config.getConfigurationSection("settings"); ConfigurationSection messagesSec = config.getConfigurationSection("messages"); + ConfigurationSection realtimeSec = config.getConfigurationSection("realtime"); String source = weatherSec.getString("source"); ConfigurationSection point = weatherSec.getConfigurationSection("point"); @@ -61,6 +65,8 @@ public class RW extends JavaPlugin { client = new WebServiceClient.Builder(accId, license).host("geolite.info").build(); } + getCommand("realweather").setExecutor(new RealWeatherCommand()); + double scale_lat = map.getDouble("scale_lat"); double scale_lon = map.getDouble("scale_lon"); int on_exceed = map.getInt("on_exceed"); @@ -77,6 +83,20 @@ public class RW extends JavaPlugin { settingsSec.getLong("timeBetweenRecheck") ); + 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") + ).runTaskTimerAsynchronously(this, 0, realtimeSec.getLong("interval")); + } + Metrics metrics = new Metrics(this, 15020); metrics.addCustomChart(new Metrics.SimplePie("source_type", () -> { return source; diff --git a/src/main/java/pl/minecon724/realweather/commands/RealWeatherCommand.java b/src/main/java/pl/minecon724/realweather/commands/RealWeatherCommand.java new file mode 100644 index 0000000..23572f2 --- /dev/null +++ b/src/main/java/pl/minecon724/realweather/commands/RealWeatherCommand.java @@ -0,0 +1,15 @@ +package pl.minecon724.realweather.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class RealWeatherCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + sender.sendMessage("TODO"); + return true; + } + +} diff --git a/src/main/java/pl/minecon724/realweather/realtime/RTTask.java b/src/main/java/pl/minecon724/realweather/realtime/RTTask.java new file mode 100644 index 0000000..092d0cf --- /dev/null +++ b/src/main/java/pl/minecon724/realweather/realtime/RTTask.java @@ -0,0 +1,36 @@ +package pl.minecon724.realweather.realtime; + +import java.time.OffsetDateTime; +import java.time.ZoneId; +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 { + double timeScale; + ZoneId timezone; + List worlds; + + public RTTask(double timeScale, ZoneId timezone, List worlds) { + 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 + public void run() { + double time = OffsetDateTime.now(timezone).toEpochSecond() / (72 * timeScale) - 18000; + Bukkit.getLogger().info(Double.toString(time)); + for (World w : worlds) { + w.setTime((long)time); + } + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 839a90f..a07eeb2 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -42,6 +42,19 @@ provider: apiKey: 'd3d37fd3511ef1d4b44c7d574e9b56b8' # More providers soon! +realtime: + enabled: true + worlds: + - world + # "auto" to use server's timezone + # Alternatively choose one of these: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List + timezone: 'auto' + # x day cycles / 24 hrs + timeScale: 1.0 + # How often should we recalculate the time (in ticks) + # Very minimal, if any, impact on performance + interval: 1 + settings: # Delay between rechecking weather # 20 is one second diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5c8745a..5b26d3e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,4 +5,8 @@ author: Minecon724 main: pl.minecon724.realweather.RW libraries: - org.json:json:20220320 - - com.maxmind.geoip2:geoip2:3.0.1 \ No newline at end of file + - com.maxmind.geoip2:geoip2:3.0.1 +commands: + realweather: + alias: rw + description: RealWeather main command \ No newline at end of file