mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 18:47:20 +01:00
Move weather handling to new wm
This commit is contained in:
parent
0824108109
commit
0a62081d03
@ -7,10 +7,11 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.listeners;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.inject.InjectableListener;
|
||||
import com.onarandombox.MultiverseCore.worldnew.WorldManager;
|
||||
import jakarta.inject.Inject;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.weather.ThunderChangeEvent;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
@ -22,10 +23,10 @@ import org.jvnet.hk2.annotations.Service;
|
||||
@Service
|
||||
public class MVWeatherListener implements InjectableListener {
|
||||
|
||||
private MVWorldManager worldManager;
|
||||
private final WorldManager worldManager;
|
||||
|
||||
@Inject
|
||||
public MVWeatherListener(MVWorldManager worldManager) {
|
||||
public MVWeatherListener(WorldManager worldManager) {
|
||||
this.worldManager = worldManager;
|
||||
}
|
||||
|
||||
@ -35,14 +36,16 @@ public class MVWeatherListener implements InjectableListener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void weatherChange(WeatherChangeEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
if (event.isCancelled() || !event.toWeatherState()) {
|
||||
return;
|
||||
}
|
||||
MVWorld world = this.worldManager.getMVWorld(event.getWorld().getName());
|
||||
if (world != null) {
|
||||
// If it's going to start raining and we have weather disabled
|
||||
event.setCancelled((event.toWeatherState() && !world.isWeatherEnabled()));
|
||||
}
|
||||
worldManager.getMVWorld(event.getWorld())
|
||||
.peek((world) -> {
|
||||
if (!world.getAllowWeather()) {
|
||||
Logging.fine("Cancelling weather for %s as getAllowWeather is false", world.getName());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,13 +54,15 @@ public class MVWeatherListener implements InjectableListener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void thunderChange(ThunderChangeEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
if (event.isCancelled() || !event.toThunderState()) {
|
||||
return;
|
||||
}
|
||||
MVWorld world = this.worldManager.getMVWorld(event.getWorld().getName());
|
||||
if (world != null) {
|
||||
// If it's going to start raining and we have weather disabled
|
||||
event.setCancelled((event.toThunderState() && !world.isWeatherEnabled()));
|
||||
}
|
||||
worldManager.getMVWorld(event.getWorld())
|
||||
.peek((world) -> {
|
||||
if (!world.getAllowWeather()) {
|
||||
Logging.fine("Cancelling thunder for %s as getAllowWeather is false", world.getName());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,14 @@ public class WorldConfigNodes {
|
||||
public final ConfigNode<Boolean> ALLOW_WEATHER = node(ConfigNode.builder("allow-weather", Boolean.class)
|
||||
.defaultValue(true)
|
||||
.name("allow-weather")
|
||||
.onSetValue((oldValue, newValue) -> {
|
||||
if (world == null) { return; }
|
||||
world.getBukkitWorld().peek(world -> {
|
||||
if (!world.isClearWeather() && !newValue) {
|
||||
world.setClearWeatherDuration(-1);
|
||||
}
|
||||
});
|
||||
})
|
||||
.build());
|
||||
|
||||
public final ConfigNode<Boolean> AUTO_HEAL = node(ConfigNode.builder("auto-heal", Boolean.class)
|
||||
|
Loading…
Reference in New Issue
Block a user