use of org.spongepowered.api.event.world.ChangeWorldWeatherEvent in project LanternServer by LanternPowered.
the class LanternWeatherUniverse method setWeather.
private boolean setWeather(CauseStack causeStack, Weather weather, long duration, boolean doEvent) {
checkNotNull(weather, "weather");
final LanternWeather current = this.weatherData.getWeather();
if (doEvent) {
final ChangeWorldWeatherEvent event = SpongeEventFactory.createChangeWorldWeatherEvent(causeStack.getCurrentCause(), (int) duration, (int) duration, current, weather, weather, this.world);
Sponge.getEventManager().post(event);
if (event.isCancelled()) {
return true;
}
weather = event.getWeather();
duration = event.getDuration();
}
final LanternWeather weather0 = (LanternWeather) weather;
this.weatherData.setRemainingDuration(duration);
if (current != weather) {
this.weatherData.setRunningDuration(0);
this.weatherData.setWeather(weather0);
}
this.darknessTarget = weather0.getOptions().getOrDefault(WeatherOptions.SKY_DARKNESS).get().floatValue();
this.rainStrengthTarget = weather0.getOptions().getOrDefault(WeatherOptions.RAIN_STRENGTH).get().floatValue();
return false;
}
use of org.spongepowered.api.event.world.ChangeWorldWeatherEvent in project SpongeCommon by SpongePowered.
the class MixinWorldServer method onUpdateWeatherReturn.
@Inject(method = "updateWeather", at = @At(value = "RETURN"))
private void onUpdateWeatherReturn(CallbackInfo ci) {
final Weather weather = getWeather();
int duration = (int) getRemainingDuration();
if (this.prevWeather != weather && duration > 0) {
try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(this);
final ChangeWorldWeatherEvent event = SpongeEventFactory.createChangeWorldWeatherEvent(frame.getCurrentCause(), duration, duration, weather, weather, this.prevWeather, this);
if (Sponge.getEventManager().post(event)) {
this.setWeather(this.prevWeather);
} else {
if (!weather.equals(event.getWeather()) || duration != event.getDuration()) {
this.setWeather(event.getWeather(), event.getDuration());
this.prevWeather = event.getWeather();
this.weatherStartTime = this.worldInfo.getWorldTotalTime();
}
}
}
}
}
Aggregations