From 5c92762ba9b53ec60217501e1261742518a14506 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Fri, 27 Jan 2012 21:54:53 -0800 Subject: [PATCH] Configuration should be fixed for real. Finally. --- .../bukkit/ConfigurationManager.java | 20 +++++++++++++------ .../worldguard/bukkit/WorldConfiguration.java | 14 ++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/ConfigurationManager.java b/src/main/java/com/sk89q/worldguard/bukkit/ConfigurationManager.java index 51c1fda0..709a3182 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/ConfigurationManager.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/ConfigurationManager.java @@ -75,6 +75,11 @@ public class ConfigurationManager { */ private Map worlds; + /** + * The global configuration for use when loading worlds + */ + private YAMLProcessor config; + /** * List of people with god mode. */ @@ -112,10 +117,13 @@ public void load() { plugin.createDefaultConfiguration( 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 { config.load(); - } catch (IOException ignore) {} + } catch (IOException e) { + WorldGuardPlugin.logger.severe("Error reading configuration for global config: "); + e.printStackTrace(); + } suppressTickSyncWarnings = config.getBoolean( "suppress-tick-sync-warnings", false); @@ -125,8 +133,6 @@ public void load() { "auto-invincible", config.getBoolean("auto-invincible-permission", true)); usePlayerMove = config.getBoolean( "use-player-move-event", true); - - config.setWriteDefaults(false); // Load configurations for each world for (World world : plugin.getServer().getWorlds()) { @@ -138,7 +144,9 @@ public void load() { } 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); if (config == null) { - config = new WorldConfiguration(plugin, worldName); + config = new WorldConfiguration(plugin, worldName, this.config); worlds.put(worldName, config); } diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java index 2b43f6ba..9d62466e 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java @@ -158,17 +158,18 @@ public class WorldConfiguration { /** * Construct the object. * - * @param plugin - * @param worldName + * @param plugin The WorldGuardPlugin instance + * @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); configFile = new File(baseFolder, "config.yml"); blacklistFile = new File(baseFolder, "blacklist.txt"); this.plugin = plugin; 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(blacklistFile, "blacklist.txt"); @@ -277,7 +278,10 @@ private Object getProperty(String node) { private void loadConfiguration() { try { config.load(); - } catch (IOException ignore) {} + } catch (IOException e) { + WorldGuardPlugin.logger.severe("Error reading configuration for world " + worldName + ": "); + e.printStackTrace(); + } opPermissions = getBoolean("op-permissions", true);