diff --git a/pom.xml b/pom.xml index 3c2ca4e..e3ec3bb 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 pl.minecon724 realweather - 0.5.1-DEV + 0.5.0.2 17 @@ -39,4 +39,4 @@ - \ No newline at end of file + diff --git a/src/main/java/pl/minecon724/realweather/weather/WeatherChanger.java b/src/main/java/pl/minecon724/realweather/weather/WeatherChanger.java index ec85818..798d077 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); + }); + } }