diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index 2fbaa06ae..bf7993f4f 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -385,7 +385,7 @@ public class Config extends ConfigLoader { } @Override - protected void load() { + public void load() { if (!configFile.exists()) { dataFolder.mkdir(); plugin.saveDefaultConfig(); diff --git a/src/main/java/com/gmail/nossr50/config/ConfigLoader.java b/src/main/java/com/gmail/nossr50/config/ConfigLoader.java index 1b79001fa..fb2330826 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigLoader.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigLoader.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.IOException; import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import com.gmail.nossr50.mcMMO; @@ -18,12 +19,21 @@ public abstract class ConfigLoader { this.plugin = plugin; dataFolder = plugin.getDataFolder(); configFile = new File(dataFolder, File.separator + fileName); + config = YamlConfiguration.loadConfiguration(this.configFile); } /** * Load this config file. */ - protected abstract void load(); + public void load() { + if (!configFile.exists()) { + dataFolder.mkdir(); + saveConfig(); + } + + addDefaults(); + loadKeys(); + } /** * Save this config file. @@ -32,8 +42,8 @@ public abstract class ConfigLoader { try { config.save(configFile); } - catch (IOException e) { - e.printStackTrace(); + catch (IOException ex) { + plugin.getLogger().severe("Could not save config to " + configFile + ex); } } @@ -41,7 +51,6 @@ public abstract class ConfigLoader { * Add the defaults to this config file. */ protected void addDefaults() { - // Load from included config.yml config.options().copyDefaults(true); saveConfig(); } diff --git a/src/main/java/com/gmail/nossr50/config/HiddenConfig.java b/src/main/java/com/gmail/nossr50/config/HiddenConfig.java index 661e11711..bf908205f 100644 --- a/src/main/java/com/gmail/nossr50/config/HiddenConfig.java +++ b/src/main/java/com/gmail/nossr50/config/HiddenConfig.java @@ -27,8 +27,10 @@ public class HiddenConfig extends ConfigLoader { } @Override - protected void load() { - if(plugin.isInJar(fileName)) loadKeys(); + public void load() { + if (plugin.getResource(fileName) != null) { + loadKeys(); + } } @Override diff --git a/src/main/java/com/gmail/nossr50/config/RepairConfig.java b/src/main/java/com/gmail/nossr50/config/RepairConfig.java index eb0947191..36999ee45 100644 --- a/src/main/java/com/gmail/nossr50/config/RepairConfig.java +++ b/src/main/java/com/gmail/nossr50/config/RepairConfig.java @@ -22,7 +22,7 @@ public class RepairConfig extends ConfigLoader { } @Override - protected void load() { + public void load() { loadKeys(); } @@ -32,6 +32,7 @@ public class RepairConfig extends ConfigLoader { ConfigurationSection section = config.getConfigurationSection("Repairables"); Set keys = section.getKeys(false); + for (String key : keys) { // Validate all the things! List reason = new ArrayList(); diff --git a/src/main/java/com/gmail/nossr50/config/RepairConfigManager.java b/src/main/java/com/gmail/nossr50/config/RepairConfigManager.java index f2123e67d..00cedcdf7 100644 --- a/src/main/java/com/gmail/nossr50/config/RepairConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/RepairConfigManager.java @@ -16,8 +16,8 @@ public class RepairConfigManager { Pattern pattern = Pattern.compile("repair\\.(?:.+)\\.yml"); File dataFolder = plugin.getDataFolder(); - File vanilla = new File(dataFolder, "repair.vanilla.yml"); + if (!vanilla.exists()) { plugin.saveResource("repair.vanilla.yml", false); } diff --git a/src/main/java/com/gmail/nossr50/config/SpoutConfig.java b/src/main/java/com/gmail/nossr50/config/SpoutConfig.java index a187a29f7..3af7cf6b6 100644 --- a/src/main/java/com/gmail/nossr50/config/SpoutConfig.java +++ b/src/main/java/com/gmail/nossr50/config/SpoutConfig.java @@ -18,11 +18,11 @@ public class SpoutConfig extends ConfigLoader { public SpoutConfig(mcMMO plugin) { super(plugin, "spout.yml"); - config = plugin.getSpoutConfig(); } public boolean spoutEnabled; public boolean getShowPowerLevel() { return config.getBoolean("HUD.Show_Power_Level", true); } + public String getMenuKey() { return config.getString("Menu.Key", "KEY_M"); } /* XP Bar */ public boolean getXPBarEnabled() { return config.getBoolean("XP.Bar.Enabled", true); } @@ -77,17 +77,6 @@ public class SpoutConfig extends ConfigLoader { public double getRetroHUDFishingGreen() { return config.getDouble("HUD.Retro.Colors.Fishing.GREEN", 0.3); } public double getRetroHUDFishingBlue() { return config.getDouble("HUD.Retro.Colors.Fishing.BLUE", 0.75); } - @Override - public void load() { - if (!configFile.exists()) { - dataFolder.mkdir(); - plugin.saveSpoutConfig(); - } - - addDefaults(); - loadKeys(); - } - @Override protected void loadKeys() { plugin.getLogger().info("Loading mcMMO spout.yml File..."); diff --git a/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java b/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java index 0dc758a89..dfbe81ad6 100644 --- a/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java +++ b/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java @@ -43,18 +43,6 @@ public class TreasuresConfig extends ConfigLoader{ private TreasuresConfig(mcMMO plugin) { super(plugin, "treasures.yml"); - config = plugin.getTreasuresConfig(); - } - - @Override - protected void load() { - if (!configFile.exists()) { - dataFolder.mkdir(); - plugin.saveTreasuresConfig(); - } - - addDefaults(); - loadKeys(); } @Override diff --git a/src/main/java/com/gmail/nossr50/config/mods/CustomArmorConfig.java b/src/main/java/com/gmail/nossr50/config/mods/CustomArmorConfig.java index 1d6c4952e..965d6da01 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/CustomArmorConfig.java +++ b/src/main/java/com/gmail/nossr50/config/mods/CustomArmorConfig.java @@ -37,18 +37,6 @@ public class CustomArmorConfig extends ModConfigLoader{ public CustomArmorConfig(mcMMO plugin) { super(plugin, "armor.yml"); - config = plugin.getArmorConfig(); - } - - @Override - public void load() { - if (!configFile.exists()) { - dataFolder.mkdir(); - plugin.saveArmorConfig(); - } - - addDefaults(); - loadKeys(); } @Override diff --git a/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java b/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java index fb44334be..0eba9e247 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java +++ b/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java @@ -36,18 +36,6 @@ public class CustomBlocksConfig extends ModConfigLoader{ public CustomBlocksConfig(mcMMO plugin) { super(plugin, "blocks.yml"); - config = plugin.getBlocksConfig(); - } - - @Override - public void load() { - if (!configFile.exists()) { - dataFolder.mkdir(); - plugin.saveBlocksConfig(); - } - - addDefaults(); - loadKeys(); } @Override diff --git a/src/main/java/com/gmail/nossr50/config/mods/CustomToolsConfig.java b/src/main/java/com/gmail/nossr50/config/mods/CustomToolsConfig.java index b57a66da9..f878d8fa5 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/CustomToolsConfig.java +++ b/src/main/java/com/gmail/nossr50/config/mods/CustomToolsConfig.java @@ -39,18 +39,6 @@ public class CustomToolsConfig extends ModConfigLoader { private CustomToolsConfig(mcMMO plugin) { super(plugin, "tools.yml"); - config = plugin.getToolsConfig(); - } - - @Override - public void load() { - if (!configFile.exists()) { - dataFolder.mkdir(); - plugin.saveToolsConfig(); - } - - addDefaults(); - loadKeys(); } @Override diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 5a3e200ec..17e7d7d56 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -389,274 +389,4 @@ public class mcMMO extends JavaPlugin { getCommand("mchud").setExecutor(new MchudCommand(this)); } - - /* - * Boilerplate Custom Config Stuff (Treasures) - */ - - private FileConfiguration treasuresConfig = null; - private File treasuresConfigFile = null; - - /** - * Reload the Treasures.yml file. - */ - public void reloadTreasuresConfig() { - if (treasuresConfigFile == null) { - treasuresConfigFile = new File(getDataFolder(), "treasures.yml"); - } - - treasuresConfig = YamlConfiguration.loadConfiguration(treasuresConfigFile); - - if (isInJar("treasures.yml")) { - InputStream defConfigStream = getResource("treasures.yml"); - YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); - treasuresConfig.setDefaults(defConfig); - } - } - - /** - * Get the Treasures config information. - * - * @return the configuration object for treasures.yml - */ - public FileConfiguration getTreasuresConfig() { - if (treasuresConfig == null) { - reloadTreasuresConfig(); - } - - return treasuresConfig; - } - - /** - * Save the Treasures config informtion. - */ - public void saveTreasuresConfig() { - if (treasuresConfig == null || treasuresConfigFile == null) { - return; - } - - try { - treasuresConfig.save(treasuresConfigFile); - } - catch (IOException ex) { - getLogger().severe("Could not save config to " + treasuresConfigFile + ex.toString()); - } - } - - /* - * Boilerplate Custom Config Stuff (Tools) - */ - - private FileConfiguration toolsConfig = null; - private File toolsConfigFile = null; - - /** - * Reload the Tools.yml file. - */ - public void reloadToolsConfig() { - if (toolsConfigFile == null) { - toolsConfigFile = new File(modDirectory, "tools.yml"); - } - - toolsConfig = YamlConfiguration.loadConfiguration(toolsConfigFile); - - if (isInJar("tools.yml")) { - InputStream defConfigStream = getResource("tools.yml"); - YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); - toolsConfig.setDefaults(defConfig); - } - } - - /** - * Get the Tools config information. - * - * @return the configuration object for tools.yml - */ - public FileConfiguration getToolsConfig() { - if (toolsConfig == null) { - reloadToolsConfig(); - } - - return toolsConfig; - } - - /** - * Save the Tools config informtion. - */ - public void saveToolsConfig() { - if (toolsConfig == null || toolsConfigFile == null) { - return; - } - - try { - toolsConfig.save(toolsConfigFile); - } - catch (IOException ex) { - getLogger().severe("Could not save config to " + toolsConfigFile + ex.toString()); - } - } - - /* - * Boilerplate Custom Config Stuff (Armor) - */ - - private FileConfiguration armorConfig = null; - private File armorConfigFile = null; - - /** - * Reload the Armor.yml file. - */ - public void reloadArmorConfig() { - if (armorConfigFile == null) { - armorConfigFile = new File(modDirectory, "armor.yml"); - } - - armorConfig = YamlConfiguration.loadConfiguration(armorConfigFile); - - if (isInJar("armor.yml")) { - InputStream defConfigStream = getResource("armor.yml"); - YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); - armorConfig.setDefaults(defConfig); - } - } - - /** - * Get the Armor config information. - * - * @return the configuration object for armor.yml - */ - public FileConfiguration getArmorConfig() { - if (armorConfig == null) { - reloadArmorConfig(); - } - - return armorConfig; - } - - /** - * Save the Armor config informtion. - */ - public void saveArmorConfig() { - if (armorConfig == null || armorConfigFile == null) { - return; - } - - try { - armorConfig.save(armorConfigFile); - } - catch (IOException ex) { - getLogger().severe("Could not save config to " + armorConfigFile + ex.toString()); - } - } - - /* - * Boilerplate Custom Config Stuff (Blocks) - */ - - private FileConfiguration blocksConfig = null; - private File blocksConfigFile = null; - - /** - * Reload the Blocks.yml file. - */ - public void reloadBlocksConfig() { - if (blocksConfigFile == null) { - blocksConfigFile = new File(modDirectory, "blocks.yml"); - } - - blocksConfig = YamlConfiguration.loadConfiguration(blocksConfigFile); - - if (isInJar("blocks.yml")) { - InputStream defConfigStream = getResource("blocks.yml"); - YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); - blocksConfig.setDefaults(defConfig); - } - } - - /** - * Get the Blocks config information. - * - * @return the configuration object for blocks.yml - */ - public FileConfiguration getBlocksConfig() { - if (blocksConfig == null) { - reloadBlocksConfig(); - } - - return blocksConfig; - } - - /** - * Save the Blocks config informtion. - */ - public void saveBlocksConfig() { - if (blocksConfig == null || blocksConfigFile == null) { - return; - } - - try { - blocksConfig.save(blocksConfigFile); - } - catch (IOException ex) { - getLogger().severe("Could not save config to " + blocksConfigFile + ex.toString()); - } - } - - /* - * Boilerplate Custom Config Stuff (Spout) - */ - - private FileConfiguration spoutConfig = null; - private File spoutConfigFile = null; - - /** - * Reload the Spout.yml file. - */ - public void reloadSpoutConfig() { - if (spoutConfigFile == null) { - spoutConfigFile = new File(modDirectory, "spout.yml"); - } - - spoutConfig = YamlConfiguration.loadConfiguration(spoutConfigFile); - - if (isInJar("spout.yml")) { - InputStream defConfigStream = getResource("spout.yml"); - YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); - spoutConfig.setDefaults(defConfig); - } - } - - /** - * Get the Spout config information. - * - * @return the configuration object for spout.yml - */ - public FileConfiguration getSpoutConfig() { - if (spoutConfig == null) { - reloadSpoutConfig(); - } - - return spoutConfig; - } - - /** - * Save the Spout config informtion. - */ - public void saveSpoutConfig() { - if (spoutConfig == null || spoutConfigFile == null) { - return; - } - - try { - spoutConfig.save(spoutConfigFile); - } - catch (IOException ex) { - getLogger().severe("Could not save config to " + spoutConfigFile + ex.toString()); - } - } - - public boolean isInJar(String resource) { - InputStream iStream = getResource(resource); - return iStream != null; - } } diff --git a/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java b/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java index 940d199c6..0836f2d62 100644 --- a/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java +++ b/src/main/java/com/gmail/nossr50/spout/SpoutStuff.java @@ -21,6 +21,7 @@ import org.getspout.spoutapi.keyboard.Keyboard; import org.getspout.spoutapi.player.SpoutPlayer; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.config.SpoutConfig; import com.gmail.nossr50.datatypes.HUDmmo; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.popups.PopupMMO; @@ -134,7 +135,7 @@ public class SpoutStuff { * Setup Spout config options */ public static void setupSpoutConfigs() { - String temp = plugin.getSpoutConfig().getString("Menu.Key", "KEY_M"); + String temp = SpoutConfig.getInstance().getMenuKey(); for (Keyboard x : Keyboard.values()) { if (x.toString().equalsIgnoreCase(temp)) {