@EventHandler
 public Message onWeatherChanged(WeatherChangeEvent event) {
   Weather newWeather = event.getNewWeather();
   if (newWeather.equals(Weather.RAIN) || newWeather.equals(Weather.THUNDERSTORM)) {
     return new PlayerGameStateMessage(PlayerGameStateMessage.BEGIN_RAINING);
   } else {
     return new PlayerGameStateMessage(PlayerGameStateMessage.END_RAINING);
   }
 }
Example #2
0
 @Override
 public void onTick(float dt) {
   final Random random = GenericMath.getRandom();
   float secondsUntilWeatherChange = sky.getData().get(VanillaData.WEATHER_CHANGE_TIME);
   secondsUntilWeatherChange -= dt;
   if (forceWeatherUpdate.compareAndSet(true, false) || secondsUntilWeatherChange <= 0) {
     this.sky.updateWeather(getCurrent(), getForecast());
     sky.getData().put(VanillaData.WORLD_WEATHER, getForecast());
     final Weather current = getCurrent();
     Weather forecast = current;
     while (forecast == current) {
       // When Rain/Snow or Thunderstorms occur, always go to Clear after.
       if (current == Weather.RAIN || current == Weather.THUNDERSTORM) {
         forecast = Weather.CLEAR;
       } else {
         forecast = Weather.get(random.nextInt(3));
       }
       setForecast(forecast);
     }
     setForecast(forecast);
     secondsUntilWeatherChange =
         current.getBaseWeatherTime() + random.nextInt(current.getRandomWeatherTime());
     if (VanillaPlugin.getInstance().getEngine().debugMode()) {
       Spout.getLogger()
           .info(
               "Weather changed to: "
                   + current
                   + ", next change in "
                   + secondsUntilWeatherChange / 1000F
                   + "s");
     }
   }
   float currentRainStrength = sky.getData().get(VanillaData.CURRENT_RAIN_STRENGTH);
   sky.getData().put(VanillaData.PREVIOUS_RAIN_STRENGTH, currentRainStrength);
   if (this.isRaining()) {
     currentRainStrength = Math.min(1.0f, currentRainStrength + 0.01f);
   } else {
     currentRainStrength = Math.max(0.0f, currentRainStrength - 0.01f);
   }
   sky.getData().put(VanillaData.CURRENT_RAIN_STRENGTH, currentRainStrength);
   if (hasLightning()) {
     lightning.onTick(dt);
   }
   if (getCurrent().isRaining()) {
     snowfall.onTick(dt);
   }
   sky.getData().put(VanillaData.WEATHER_CHANGE_TIME, secondsUntilWeatherChange);
 }
Example #3
0
  @Override
  public void updateWeather(Weather oldWeather, Weather newWeather) {
    org.spout.vanilla.event.world.WeatherChangeEvent event =
        Spout.getEventManager()
            .callEvent(
                new org.spout.vanilla.event.world.WeatherChangeEvent(this, oldWeather, newWeather));
    if (event.isCancelled()) {
      return;
    }
    this.getWorld().getDataMap().put(Data.WEATHER, newWeather);

    byte reason =
        (newWeather.equals(Weather.RAIN) || newWeather.equals(Weather.THUNDERSTORM))
            ? ChangeGameStateMessage.BEGIN_RAINING
            : ChangeGameStateMessage.END_RAINING;
    broadcastMessage(new ChangeGameStateMessage(reason));
  }