From 401af172ae902244eedeab4f932b49b9baaba428 Mon Sep 17 00:00:00 2001 From: TheYeti Date: Mon, 30 Jan 2012 12:20:43 -0800 Subject: [PATCH] Update LoadProperties to use new FileConfiguration --- Changelog.txt | 3 +- .../gmail/nossr50/config/LoadProperties.java | 57 ++++++++++++------- src/main/java/com/gmail/nossr50/mcMMO.java | 2 +- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 3d5163762..146f8fafa 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -7,7 +7,8 @@ Version 1.2.09-dev - Changed timer to be a bit more efficient (Issue #19) - Changed to fire EntityDamageEvents for all damage done by mcMMO - New custom event for developers McMMOPlayerLevelUpEvent - - New custmo event for developers McMMOItemSpawnEvent + - New custom event for developers McMMOItemSpawnEvent + - Fishing Configuration inclusion (Pull Request #60) Version 1.2.08 - Changed Bukkit events to new event system diff --git a/src/main/java/com/gmail/nossr50/config/LoadProperties.java b/src/main/java/com/gmail/nossr50/config/LoadProperties.java index 3f3194928..20a170bb2 100644 --- a/src/main/java/com/gmail/nossr50/config/LoadProperties.java +++ b/src/main/java/com/gmail/nossr50/config/LoadProperties.java @@ -16,8 +16,11 @@ */ package com.gmail.nossr50.config; +import com.gmail.nossr50.mcMMO; import java.io.File; -import org.bukkit.util.config.Configuration; +import java.io.IOException; + +import org.bukkit.configuration.file.FileConfiguration; import com.gmail.nossr50.datatypes.HUDType; @@ -53,21 +56,27 @@ public class LoadProperties archeryxpmodifier, swordsxpmodifier, axesxpmodifier, acrobaticsxpmodifier; public static HUDType defaulthud; + protected static File configFile; + protected static File dataFolder; + protected final mcMMO plugin; + protected static FileConfiguration config; - public String directory = "plugins/mcMMO/"; - - File file = new File(directory + File.separator + "config.yml"); - static Configuration config = null; + public LoadProperties(mcMMO plugin) + { + this.plugin = plugin; + dataFolder = plugin.getDataFolder(); + configFile = new File(dataFolder, "config.yml"); + } public void configCheck() { - new File(directory).mkdir(); - config = load(); - if(!file.exists()) + load(); + if(!configFile.exists()) { try { - file.createNewFile(); + configFile.getParentFile().mkdir(); + configFile.createNewFile(); addDefaults(); } catch (Exception ex) @@ -83,27 +92,26 @@ public class LoadProperties private void write(String root, Object x) { //Configuration config = load(); - config.setProperty(root, x); - config.save(); + config.set(root, x); } private Boolean readBoolean(String root, Boolean def) { //Configuration config = load(); Boolean result = config.getBoolean(root, def); - config.save(); + saveConfig(); return result; } private Double readDouble(String root, Double def) { Double result = config.getDouble(root, def); - config.save(); + saveConfig(); return result; } private Integer readInteger(String root, Integer def) { //Configuration config = load(); Integer result = config.getInt(root, def); - config.save(); + saveConfig(); return result; } @@ -111,22 +119,31 @@ public class LoadProperties { //Configuration config = load(); String result = config.getString(root, def); - config.save(); + saveConfig(); return result; } - private Configuration load() + private FileConfiguration load() { try { - Configuration configx = new Configuration(file); - configx.load(); - return configx; + config.load(configFile); + return config; } catch (Exception e) { e.printStackTrace(); } return null; } + + private static void saveConfig() + { + try { + config.save(configFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + private void addDefaults() { System.out.println("Generating Config File..."); @@ -389,6 +406,7 @@ public class LoadProperties write("Fishing.Drops.Glowstone_Dust", true); write("Fishing.Drops.Diamonds", true); + saveConfig(); loadkeys(); } private void loadkeys() @@ -396,6 +414,7 @@ public class LoadProperties System.out.println("Loading Config File..."); //Setup default HUD + load(); String temp = readString("Spout.HUD.Default", "STANDARD"); for(HUDType x : HUDType.values()) { diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 75c799fd7..b80b9fbce 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -97,7 +97,7 @@ public class mcMMO extends JavaPlugin public Misc misc = new Misc(this); //Config file stuff - LoadProperties config = new LoadProperties(); + LoadProperties config = new LoadProperties(this); //Jar stuff public static File mcmmo;