org.bukkit.event.weather.WeatherChangeEvent Java Examples

The following examples show how to use org.bukkit.event.weather.WeatherChangeEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CraftWorld.java    From Thermos with GNU General Public License v3.0 7 votes vote down vote up
public void setStorm(boolean hasStorm) {
    CraftServer server = world.getServer();

    WeatherChangeEvent weather = new WeatherChangeEvent(this, hasStorm);
    server.getPluginManager().callEvent(weather);
    if (!weather.isCancelled()) {
        world.worldInfo.setRaining(hasStorm);

        // These numbers are from Minecraft
        if (hasStorm) {
            setWeatherDuration(rand.nextInt(12000) + 12000);
        } else {
            setWeatherDuration(rand.nextInt(168000) + 12000);
        }
    }
}
 
Example #2
Source File: EvtWeatherChange.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
public boolean check(final Event e) {
	if (types == null)
		return true;
	if (!(e instanceof WeatherChangeEvent || e instanceof ThunderChangeEvent))
		return false;
	final boolean rain = e instanceof WeatherChangeEvent ? ((WeatherChangeEvent) e).toWeatherState() : ((ThunderChangeEvent) e).getWorld().hasStorm();
	final boolean thunder = e instanceof ThunderChangeEvent ? ((ThunderChangeEvent) e).toThunderState() : ((WeatherChangeEvent) e).getWorld().isThundering();
	return types.check(e, new Checker<WeatherType>() {
		@Override
		public boolean check(final WeatherType t) {
			return t.isWeather(rain, thunder);
		}
	});
}
 
Example #3
Source File: WeatherListener.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onWeatherEvent(WeatherChangeEvent we) {
  if (we.isCancelled()) {
    return;
  }

  List<Game> games = BedwarsRel.getInstance().getGameManager().getGamesByWorld(we.getWorld());

  if (games.size() == 0) {
    return;
  }

  for (Game game : games) {
    if (game.getState() != GameState.STOPPED) {
      we.setCancelled(true);
      break;
    }
  }
}
 
Example #4
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onWeatherChange(WeatherChangeEvent e) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is onChangeWeather event");

    World w = e.getWorld();
    if (!RedProtect.get().config.globalFlagsRoot().worlds.get(w.getName()).weather.allow_weather) {
        int attempts = RedProtect.get().config.globalFlagsRoot().worlds.get(w.getName()).weather.attempts_before_rain;
        if (e.toWeatherState()) {
            if (!rainCounter.containsKey(w)) {
                rainCounter.put(w, attempts);
                e.setCancelled(true);
            } else {
                int acTry = rainCounter.get(w);
                if (acTry - 1 <= 0) {
                    Bukkit.getScheduler().runTaskLater(RedProtect.get(), () -> w.setWeatherDuration(RedProtect.get().config.globalFlagsRoot().worlds.get(w.getName()).weather.rain_time * 20), 40);
                    rainCounter.put(w, attempts);
                } else {
                    rainCounter.put(w, acTry - 1);
                    e.setCancelled(true);
                }
            }
        }
    }
}
 
Example #5
Source File: DWorldListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onWeatherChange(WeatherChangeEvent event) {
    InstanceWorld instance = plugin.getInstanceWorld(event.getWorld());
    if (instance instanceof EditWorld && event.toWeatherState()) {
        event.setCancelled(true);
    } else if (instance instanceof GameWorld) {
        Boolean raining = ((GameWorld) instance).getDungeon().getRules().getState(GameRule.RAIN);
        if (raining == null) {
            return;
        }
        if ((raining && !event.toWeatherState()) || (!raining && event.toWeatherState())) {
            event.setCancelled(true);
        }
    }
}
 
Example #6
Source File: NoWeather.java    From HubBasics with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onWeather(WeatherChangeEvent event) {
    WeatherType type = this.worldStates.get(event.getWorld().getName());
    if (type == null) return;
    if (type == WeatherType.CLEAR && event.toWeatherState()) {
        event.setCancelled(true);
    } else if (type == WeatherType.DOWNFALL && !event.toWeatherState()) {
        event.setCancelled(true);
    }
}
 
Example #7
Source File: AcidEffect.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tracks weather changes and acid rain
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.NORMAL)
public void onWeatherChange(final WeatherChangeEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: " + e.getEventName());

    // Check that they are in the ASkyBlock world
    // plugin.getLogger().info("weather change noted");
    if (!e.getWorld().getName().equalsIgnoreCase(Settings.worldName)) {
        return;
    }
    this.isRaining = e.toWeatherState();
    // plugin.getLogger().info("is raining = " + isRaining);
}
 
Example #8
Source File: EventFilterMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onWeatherChange(final WeatherChangeEvent event) {
  cancelAlways(event, event.getWorld());
}
 
Example #9
Source File: EventFilterMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onWeatherChange(final WeatherChangeEvent event) {
    cancelAlways(event, event.getWorld());
}
 
Example #10
Source File: EnvironmentControlListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler
public void noWeather(final WeatherChangeEvent event) {
    event.setCancelled(true);
}
 
Example #11
Source File: NoWeatherChangeFeature.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
@EventHandler
public void onWeatherChange(WeatherChangeEvent e) {
    if (e.getWorld().getName().equals(world.getName())) {
        e.setCancelled(true);
    }
}
 
Example #12
Source File: ExprWeather.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean setTime(final int time) {
	return super.setTime(time, getExpr(), WeatherChangeEvent.class, ThunderChangeEvent.class);
}
 
Example #13
Source File: ServerListener.java    From ZombieEscape with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onWeather(WeatherChangeEvent event) {
    event.setCancelled(true);
}
 
Example #14
Source File: WorldFreeze.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onWeatherChange(WeatherChangeEvent event) {
    event.setCancelled(true);
}
 
Example #15
Source File: UHPluginListener.java    From KTP with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onWeatherChange(WeatherChangeEvent ev) {
	if (!p.getConfig().getBoolean("weather")) {
		ev.setCancelled(true);
	}
}