Configuration should be fixed for real. Finally.

This commit is contained in:
zml2008 2012-01-27 21:54:53 -08:00 committed by TomyLobo
parent e665f966e6
commit 5c92762ba9
2 changed files with 23 additions and 11 deletions

View File

@ -75,6 +75,11 @@ public class ConfigurationManager {
*/ */
private Map<String, WorldConfiguration> worlds; private Map<String, WorldConfiguration> worlds;
/**
* The global configuration for use when loading worlds
*/
private YAMLProcessor config;
/** /**
* List of people with god mode. * List of people with god mode.
*/ */
@ -112,10 +117,13 @@ public void load() {
plugin.createDefaultConfiguration( plugin.createDefaultConfiguration(
new File(plugin.getDataFolder(), "config.yml"), "config.yml"); new File(plugin.getDataFolder(), "config.yml"), "config.yml");
YAMLProcessor config = new YAMLProcessor(new File(plugin.getDataFolder(), "config.yml"), true, YAMLFormat.EXTENDED); config = new YAMLProcessor(new File(plugin.getDataFolder(), "config.yml"), true, YAMLFormat.EXTENDED);
try { try {
config.load(); config.load();
} catch (IOException ignore) {} } catch (IOException e) {
WorldGuardPlugin.logger.severe("Error reading configuration for global config: ");
e.printStackTrace();
}
suppressTickSyncWarnings = config.getBoolean( suppressTickSyncWarnings = config.getBoolean(
"suppress-tick-sync-warnings", false); "suppress-tick-sync-warnings", false);
@ -126,8 +134,6 @@ public void load() {
usePlayerMove = config.getBoolean( usePlayerMove = config.getBoolean(
"use-player-move-event", true); "use-player-move-event", true);
config.setWriteDefaults(false);
// Load configurations for each world // Load configurations for each world
for (World world : plugin.getServer().getWorlds()) { for (World world : plugin.getServer().getWorlds()) {
get(world); get(world);
@ -138,7 +144,9 @@ public void load() {
} catch (Throwable t) { } catch (Throwable t) {
} }
config.save(); if (!config.save()) {
WorldGuardPlugin.logger.severe("Error saving configuration!");
}
} }
/** /**
@ -159,7 +167,7 @@ public WorldConfiguration get(World world) {
WorldConfiguration config = worlds.get(worldName); WorldConfiguration config = worlds.get(worldName);
if (config == null) { if (config == null) {
config = new WorldConfiguration(plugin, worldName); config = new WorldConfiguration(plugin, worldName, this.config);
worlds.put(worldName, config); worlds.put(worldName, config);
} }

View File

@ -158,17 +158,18 @@ public class WorldConfiguration {
/** /**
* Construct the object. * Construct the object.
* *
* @param plugin * @param plugin The WorldGuardPlugin instance
* @param worldName * @param worldName The world name that this WorldConfiguration is for.
* @param parentConfig The parent configuration to read defaults from
*/ */
public WorldConfiguration(WorldGuardPlugin plugin, String worldName) { public WorldConfiguration(WorldGuardPlugin plugin, String worldName, YAMLProcessor parentConfig) {
File baseFolder = new File(plugin.getDataFolder(), "worlds/" + worldName); File baseFolder = new File(plugin.getDataFolder(), "worlds/" + worldName);
configFile = new File(baseFolder, "config.yml"); configFile = new File(baseFolder, "config.yml");
blacklistFile = new File(baseFolder, "blacklist.txt"); blacklistFile = new File(baseFolder, "blacklist.txt");
this.plugin = plugin; this.plugin = plugin;
this.worldName = worldName; this.worldName = worldName;
this.parentConfig = new YAMLProcessor(new File(plugin.getDataFolder(), "config.yml"), true, YAMLFormat.EXTENDED); this.parentConfig = parentConfig;
plugin.createDefaultConfiguration(configFile, "config_world.yml"); plugin.createDefaultConfiguration(configFile, "config_world.yml");
plugin.createDefaultConfiguration(blacklistFile, "blacklist.txt"); plugin.createDefaultConfiguration(blacklistFile, "blacklist.txt");
@ -277,7 +278,10 @@ private Object getProperty(String node) {
private void loadConfiguration() { private void loadConfiguration() {
try { try {
config.load(); config.load();
} catch (IOException ignore) {} } catch (IOException e) {
WorldGuardPlugin.logger.severe("Error reading configuration for world " + worldName + ": ");
e.printStackTrace();
}
opPermissions = getBoolean("op-permissions", true); opPermissions = getBoolean("op-permissions", true);