This commit is contained in:
parent
3abb437c5b
commit
18e9c2e183
2 changed files with 20 additions and 2 deletions
2
pom.xml
2
pom.xml
|
@ -2,7 +2,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pl.minecon724</groupId>
|
||||
<artifactId>realweather</artifactId>
|
||||
<version>0.5.0.1</version>
|
||||
<version>0.5.0.2</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue