Apply weather settings on world load.

This commit is contained in:
Wizjany 2011-09-22 16:17:35 -04:00
parent 89ce7312d1
commit e6de06aae8
2 changed files with 31 additions and 1 deletions

View File

@ -169,7 +169,12 @@ public void onEnable() {
(new WorldGuardBlockListener(this)).registerEvents();
(new WorldGuardEntityListener(this)).registerEvents();
(new WorldGuardWeatherListener(this)).registerEvents();
(new WorldGuardWorldListener(this)).registerEvents();
// handle worlds separately to initialize already loaded worlds
WorldGuardWorldListener worldListener = (new WorldGuardWorldListener(this));
for (World world : getServer().getWorlds()) {
worldListener.initWorld(world);
}
// Check god mode for existing players, if any
for (Player player : getServer().getOnlinePlayers()) {

View File

@ -7,10 +7,12 @@
import java.util.logging.Logger;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.WorldListener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.plugin.PluginManager;
public class WorldGuardWorldListener extends WorldListener {
@ -38,6 +40,7 @@ public void registerEvents() {
// PluginManager pm = plugin.getServer().getPluginManager();
registerEvent("CHUNK_LOAD", Event.Priority.Normal);
registerEvent("WORLD_LOAD", Event.Priority.Normal);
}
/**
@ -78,4 +81,26 @@ public void onChunkLoad(ChunkLoadEvent event) {
}
}
}
/**
* Called when a world is loaded.
*/
public void onWorldLoad(WorldLoadEvent event) {
initWorld(event.getWorld());
}
public void initWorld(World world) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.alwaysRaining && !wcfg.disableWeather) {
world.setStorm(true);
} else if (wcfg.disableWeather && !wcfg.alwaysRaining) {
world.setStorm(false);
}
if (wcfg.alwaysThundering && !wcfg.disableThunder) {
world.setThundering(true);
} else if (wcfg.disableThunder && !wcfg.alwaysThundering) {
world.setStorm(false);
}
}
}