From b2a474b0115da340604a98fecfc0bb5978c1936f Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Wed, 5 Jun 2024 19:08:58 +0200 Subject: [PATCH] work sorry I'm really tired because of school you see it's almost the year's end so there's nothing left to do so we just sit in class doing nothing, what a waste of time --- .../realweather/time/AsyncPlayerTimeTask.java | 41 +++++++++++++++++++ .../realweather/time/SyncTimeUpdateTask.java | 24 +++++++++++ .../eu/m724/realweather/time/TimeMaster.java | 8 ++++ 3 files changed, 73 insertions(+) create mode 100644 src/main/java/eu/m724/realweather/time/AsyncPlayerTimeTask.java create mode 100644 src/main/java/eu/m724/realweather/time/SyncTimeUpdateTask.java diff --git a/src/main/java/eu/m724/realweather/time/AsyncPlayerTimeTask.java b/src/main/java/eu/m724/realweather/time/AsyncPlayerTimeTask.java new file mode 100644 index 0000000..d0d2a8b --- /dev/null +++ b/src/main/java/eu/m724/realweather/time/AsyncPlayerTimeTask.java @@ -0,0 +1,41 @@ +package eu.m724.realweather.time; + +import org.bukkit.Server; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import eu.m724.realweather.GlobalConstants; +import eu.m724.realweather.mapper.Mapper; +import eu.m724.realweather.weather.PlayerWeatherDirectory; +import eu.m724.wtapi.object.Coordinates; +import eu.m724.wtapi.object.Weather; + +public class AsyncPlayerTimeTask extends BukkitRunnable { + private PlayerWeatherDirectory playerWeatherDirectory = + GlobalConstants.getPlayerWeatherDirectory(); + private Server server = GlobalConstants.getPlugin().getServer(); + private Mapper mapper = GlobalConstants.getMapper(); + + private TimeConfig timeConfig; + + AsyncPlayerTimeTask(TimeConfig timeConfig) { + this.timeConfig = timeConfig; + } + + @Override // TODO TODO TODO + public void run() { + for (Player player : server.getOnlinePlayers()) { + if (!player.hasPermission("realweather.dynamic")) continue; + Weather weather = playerWeatherDirectory.getWeather(player); + + if (weather != null) { + // TODO sunrise sunset + } + + Coordinates coordinates = mapper.locationToCoordinates(player.getLocation()); + long offsetTicks = (long) (coordinates.longitude / (360 / 1728000)); + player.setPlayerTime(offsetTicks, true); + } + } + // TODO make this also a listener for player joins +} diff --git a/src/main/java/eu/m724/realweather/time/SyncTimeUpdateTask.java b/src/main/java/eu/m724/realweather/time/SyncTimeUpdateTask.java new file mode 100644 index 0000000..22e1463 --- /dev/null +++ b/src/main/java/eu/m724/realweather/time/SyncTimeUpdateTask.java @@ -0,0 +1,24 @@ +package eu.m724.realweather.time; + +import org.bukkit.scheduler.BukkitRunnable; + +import eu.m724.realweather.GlobalConstants; +import eu.m724.realweather.mapper.Mapper; + +public class SyncTimeUpdateTask extends BukkitRunnable { + private TimeConfig timeConfig; + private Mapper mapper = GlobalConstants.getMapper(); + + SyncTimeUpdateTask(TimeConfig timeConfig) { + this.timeConfig = timeConfig; + } + + @Override + public void run() { + long now = System.currentTimeMillis() / 1000; + long time = (long) (((now / 3600 * 1000) - 6000) * timeConfig.modifier % 24000); // TODO test this + + mapper.getWorlds().forEach(world -> world.setFullTime(time)); + } + +} diff --git a/src/main/java/eu/m724/realweather/time/TimeMaster.java b/src/main/java/eu/m724/realweather/time/TimeMaster.java index fb46b74..5922dc4 100644 --- a/src/main/java/eu/m724/realweather/time/TimeMaster.java +++ b/src/main/java/eu/m724/realweather/time/TimeMaster.java @@ -1,5 +1,7 @@ package eu.m724.realweather.time; +import org.bukkit.plugin.Plugin; + import eu.m724.realweather.DebugLogger; import eu.m724.realweather.GlobalConstants; import eu.m724.realweather.mapper.Mapper; @@ -8,6 +10,7 @@ import eu.m724.realweather.object.UserException; public class TimeMaster { private TimeConfig config; private Mapper mapper = GlobalConstants.getMapper(); + private Plugin plugin = GlobalConstants.getPlugin(); public TimeMaster(TimeConfig config) { this.config = config; @@ -21,6 +24,11 @@ public class TimeMaster { if (!config.enabled) return; + + long period = 1; // TODO calculate update period + new SyncTimeUpdateTask(config).runTaskTimer(plugin, 0, period); + new AsyncPlayerTimeTask(config).runTaskTimerAsynchronously(plugin, 0, period); + // TODO start task, actually create that task, account for data from weather like sunrise sunset timezone DebugLogger.info("time loaded", 1); }