org.bukkit.event.weather.ThunderChangeEvent Java Examples

The following examples show how to use org.bukkit.event.weather.ThunderChangeEvent. 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: 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 #2
Source File: CraftWorld.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public void setThundering(boolean thundering) {
    if (thundering && !hasStorm()) setStorm(true);
    CraftServer server = world.getServer();

    ThunderChangeEvent thunder = new ThunderChangeEvent(this, thundering);
    server.getPluginManager().callEvent(thunder);
    if (!thunder.isCancelled()) {
        world.worldInfo.setThundering(thundering);

        // These numbers are from Minecraft
        if (thundering) {
            setThunderDuration(rand.nextInt(12000) + 3600);
        } else {
            setThunderDuration(rand.nextInt(168000) + 12000);
        }
    }
}
 
Example #3
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 onThunderChange(ThunderChangeEvent e) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is onThunderChange 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.toThunderState()) {
            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 #4
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 #5
Source File: WorldFreeze.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onThunderChange(ThunderChangeEvent event) {
    event.setCancelled(true);
}