From c200d43f51c3e6e31c845c5efce0f584fa8fc8bf Mon Sep 17 00:00:00 2001 From: fernferret Date: Tue, 11 Oct 2011 16:45:47 -0400 Subject: [PATCH] Bunch of NPE fixes --- .../onarandombox/MultiverseCore/MVWorld.java | 17 ++++++++++++----- .../MultiverseCore/MultiverseCore.java | 5 ++++- .../MultiverseCore/api/MultiverseWorld.java | 2 +- .../MultiverseCore/utils/EnglishChatColor.java | 2 +- .../MultiverseCore/utils/WorldManager.java | 8 ++++++++ 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index f1b484fa..f24e2581 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -80,14 +80,18 @@ public class MVWorld implements MultiverseWorld { // Initialize our lists this.initLists(); worldSection = config.getConfigurationSection("worlds." + this.name); + if (worldSection == null) { + config.createSection("worlds." + this.name); + worldSection = config.getConfigurationSection("worlds." + this.name); + } // Write these files to the config (once it's saved) if (generatorString != null) { worldSection.set("generator", generatorString); } if (seed != null) { - worldSection.set("worlds." + this.name + "seed", this.seed); + worldSection.set("seed", this.seed); } - worldSection.set("worlds." + this.name + "environment", this.environment.toString()); + worldSection.set("environment", this.environment.toString()); // Set local values that CAN be changed by the user @@ -363,8 +367,7 @@ public class MVWorld implements MultiverseWorld { } if (name.equalsIgnoreCase("scale") || name.equalsIgnoreCase("scaling")) { try { - this.setScaling(Double.parseDouble(value)); - return true; + return this.setScaling(Double.parseDouble(value)); } catch (Exception e) { return false; } @@ -525,14 +528,17 @@ public class MVWorld implements MultiverseWorld { } @Override - public void setScaling(double scaling) { + public boolean setScaling(double scaling) { + boolean success = true; if (scaling <= 0) { // Disallow negative or 0 scalings. scaling = 1.0; + success = false; } this.scaling = scaling; this.worldSection.set("scale", scaling); saveConfig(); + return success; } @Override @@ -548,6 +554,7 @@ public class MVWorld implements MultiverseWorld { } public boolean isValidAliasColor(String aliasColor) { + System.out.print("Checking color... " + aliasColor); return (EnglishChatColor.fromString(aliasColor) != null); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index c7087254..26e87232 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -268,7 +268,10 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { PrefixChat = this.multiverseConfig.getBoolean("worldnameprefix", true); BedRespawn = this.multiverseConfig.getBoolean("bedrespawn", true); this.multiverseConfig.set("enforceaccess", EnforceAccess); - this.multiverseConfig.set("enforcegamemodes", EnforceAccess); + this.multiverseConfig.set("enforcegamemodes", EnforceGameModes); + this.multiverseConfig.set("bedrespawn", BedRespawn); + this.multiverseConfig.set("worldnameprefix", PrefixChat); + this.multiverseConfig.set("debug", GlobalDebug); this.messaging = new MVMessaging(this); this.messaging.setCooldown(this.multiverseConfig.getInt("messagecooldown", 5000)); try { diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java index a5725d00..75c1f8b5 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java @@ -366,7 +366,7 @@ public interface MultiverseWorld { * * @param scaling A scaling value, cannot be negative or 0. */ - public void setScaling(double scaling); + public boolean setScaling(double scaling); /** * Gets the scaling value of this world.Really only has an effect if you use diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/EnglishChatColor.java b/src/main/java/com/onarandombox/MultiverseCore/utils/EnglishChatColor.java index 097c47d9..d9cf9207 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/EnglishChatColor.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/EnglishChatColor.java @@ -55,6 +55,6 @@ public enum EnglishChatColor { } } } - return EnglishChatColor.WHITE; + return null; } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java index 3d102b86..ca3cc0a5 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java @@ -357,6 +357,14 @@ public class WorldManager implements MVWorldManager { // Basic Counter to count how many Worlds we are loading. int count = 0; // Grab all the Worlds from the Config. + if (this.configWorlds.getConfigurationSection("worlds") == null) { + this.configWorlds.createSection("worlds"); + try { + this.configWorlds.save(new File(this.plugin.getDataFolder(), "worlds.yml")); + } catch (IOException e) { + this.plugin.log(Level.SEVERE, "Failed to save worlds.yml. Please check your file permissions."); + } + } Set worldKeys = this.configWorlds.getConfigurationSection("worlds").getKeys(false); // Force the worlds to be loaded, ie don't just load new worlds.