Search in sources :

Example 1 with WeatherChangeEvent

use of org.bukkit.event.weather.WeatherChangeEvent in project Glowstone by GlowstoneMC.

the class GlowWorld method setStorm.

@Override
public void setStorm(boolean hasStorm) {
    // call event
    WeatherChangeEvent event = new WeatherChangeEvent(this, hasStorm);
    if (EventFactory.callEvent(event).isCancelled()) {
        return;
    }
    // change weather
    boolean previouslyRaining = currentlyRaining;
    currentlyRaining = hasStorm;
    // Numbers borrowed from CraftBukkit.
    if (currentlyRaining) {
        setWeatherDuration(random.nextInt(HALF_DAY_IN_TICKS) + HALF_DAY_IN_TICKS);
    } else {
        setWeatherDuration(random.nextInt(WEEK_IN_TICKS) + HALF_DAY_IN_TICKS);
    }
    // update players
    if (previouslyRaining != currentlyRaining) {
        getRawPlayers().forEach(GlowPlayer::sendWeather);
    }
}
Also used : WeatherChangeEvent(org.bukkit.event.weather.WeatherChangeEvent)

Aggregations

WeatherChangeEvent (org.bukkit.event.weather.WeatherChangeEvent)1