From 18e9c2e183ddf8c34ff58fb0e6f32c13c197b79b Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sun, 26 May 2024 12:41:51 +0200 Subject: [PATCH] actually change weather --- pom.xml | 2 +- .../realweather/weather/WeatherChanger.java | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0a1bb26..0b98e9f 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 pl.minecon724 realweather - 0.5.0.1 + 0.5.0.2 17 diff --git a/src/main/java/pl/minecon724/realweather/weather/WeatherChanger.java b/src/main/java/pl/minecon724/realweather/weather/WeatherChanger.java index d0f1a37..7c42192 100644 --- a/src/main/java/pl/minecon724/realweather/weather/WeatherChanger.java +++ b/src/main/java/pl/minecon724/realweather/weather/WeatherChanger.java @@ -3,14 +3,19 @@ package pl.minecon724.realweather.weather; import java.util.ArrayList; import java.util.List; +import org.bukkit.GameRule; +import org.bukkit.WeatherType; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.weather.WeatherChangeEvent; +import org.bukkit.event.weather.WeatherEvent; import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldUnloadEvent; import pl.minecon724.realweather.SubLogger; +import pl.minecon724.realweather.weather.WeatherState.ConditionSimple; import pl.minecon724.realweather.weather.WeatherState.State; import pl.minecon724.realweather.weather.events.WeatherSyncEvent; @@ -30,6 +35,7 @@ public class WeatherChanger implements Listener { if (worldNames.contains(world.getName())) { worlds.add(world); + world.setGameRule(GameRule.DO_WEATHER_CYCLE, false); subLogger.info("World %s has been registered", world.getName()); } @@ -38,6 +44,7 @@ public class WeatherChanger implements Listener { @EventHandler public void onWorldUnload(WorldUnloadEvent event) { World world = event.getWorld(); + world.setGameRule(GameRule.DO_WEATHER_CYCLE, true); worlds.remove(world); subLogger.info("World %s unloaded", world.getName()); @@ -48,11 +55,22 @@ public class WeatherChanger implements Listener { Player player = event.getPlayer(); State state = event.getState(); - if (player != null) { subLogger.info("new weather for %s: %s %s", player.getName(), state.getCondition().name(), state.getLevel().name()); + + player.setPlayerWeather( + state.getSimple() == ConditionSimple.CLEAR + ? WeatherType.CLEAR : WeatherType.DOWNFALL + ); + } else { subLogger.info("new weather: %s %s", state.getCondition().name(), state.getLevel().name()); + + worlds.forEach(w -> { + w.setStorm(state.getSimple() != ConditionSimple.CLEAR); + w.setThundering(state.getSimple() == ConditionSimple.THUNDER); + }); + } }