/** Attempts to find a config If there is one load it If there is not one create one */
  private void loadConfig() {
    config = new Properties(defaults);

    try {
      configPath =
          Minecraft.getMinecraft().mcDataDir.getCanonicalPath()
              + File.separatorChar
              + "config"
              + File.separatorChar
              + "ServerListFolder"
              + File.separatorChar;

      File cfg = new File(configPath + "ServerListFolder.cfg");

      if (cfg.exists()) {
        ServerListFolder.info("Config file found, loading...");
        config.load(new FileInputStream(configPath + "ServerListFolder.cfg"));
      } else {
        ServerListFolder.info("No config file found, creating...");
        createConfig(cfg);
      }
    } catch (Exception e) {
      ServerListFolder.warn(e.toString());
    }
  }
 public void saveConfig() {
   try {
     config.store(new FileOutputStream(configPath + "ServerListFolder.cfg"), null);
     config.load(new FileInputStream(configPath + "ServerListFolder.cfg"));
   } catch (Exception e) {
     ServerListFolder.warn(e.toString());
   }
 }
 /** Loads the property data into the local data */
 public void loadConfigData() {
   ServerListFolder.info("Loading Config to Local Data");
   configVersion = this.getIntProperty("configVersion");
   FolderMotdColor = this.getStringProperty("FolderMotdColor");
   parseColor();
   FolderMotdText = this.getStringProperty("FolderMotdText");
   checkForConfigUpdate();
 }
  /**
   * Creates a config properties of default values Then saves the config to the config location
   *
   * @param cfg config file
   */
  private void createConfig(File cfg) {
    File folder = new File(configPath);
    if (!folder.exists()) {
      ServerListFolder.info("No folder found, creating...");
      folder.mkdirs();
    }

    try {
      cfg.createNewFile();
      config.setProperty("configVersion", "" + version);
      config.setProperty("FolderMotdColor", "purple");
      config.setProperty("FolderMotdText", "Folder");
      config.store(
          new FileOutputStream(configPath + "ServerListFolder.cfg"),
          "Server List Folder Mod Config"
              + "\nUse the color names(without spaces!) form: http://www.minecraftwiki.net/wiki/Color_Codes");
    } catch (Exception e) {
      ServerListFolder.warn(e.toString());
    }
  }
 private void parseColor() {
   if (FolderMotdColor.equalsIgnoreCase("black")) {
     FolderMotdColorCode = EnumChatFormatting.BLACK;
   } else if (FolderMotdColor.equalsIgnoreCase("white")) {
     FolderMotdColorCode = EnumChatFormatting.WHITE;
   } else if (FolderMotdColor.equalsIgnoreCase("red")) {
     FolderMotdColorCode = EnumChatFormatting.RED;
   } else if (FolderMotdColor.equalsIgnoreCase("blue")
       || FolderMotdColor.equalsIgnoreCase("indigo")) {
     FolderMotdColorCode = EnumChatFormatting.BLUE;
   } else if (FolderMotdColor.equals("darkblue") || FolderMotdColor.equalsIgnoreCase("navy")) {
     FolderMotdColorCode = EnumChatFormatting.DARK_BLUE;
   } else if (FolderMotdColor.equalsIgnoreCase("darkgreen")
       || FolderMotdColor.equalsIgnoreCase("green")) {
     FolderMotdColorCode = EnumChatFormatting.DARK_GREEN;
   } else if (FolderMotdColor.equalsIgnoreCase("darkaqua")
       || FolderMotdColor.equalsIgnoreCase("teal")) {
     FolderMotdColorCode = EnumChatFormatting.DARK_AQUA;
   } else if (FolderMotdColor.equalsIgnoreCase("yellow")) {
     FolderMotdColorCode = EnumChatFormatting.YELLOW;
   } else if (FolderMotdColor.equalsIgnoreCase("grey")
       || FolderMotdColor.equalsIgnoreCase("silver")) {
     FolderMotdColorCode = EnumChatFormatting.GRAY;
   } else if (FolderMotdColor.equalsIgnoreCase("aqua")) {
     FolderMotdColorCode = EnumChatFormatting.AQUA;
   } else if (FolderMotdColor.equalsIgnoreCase("pink")) {
     FolderMotdColorCode = EnumChatFormatting.LIGHT_PURPLE;
   } else if (FolderMotdColor.equalsIgnoreCase("gold")
       || FolderMotdColor.equalsIgnoreCase("orange")) {
     FolderMotdColorCode = EnumChatFormatting.GOLD;
   } else if (FolderMotdColor.equalsIgnoreCase("lime")
       || FolderMotdColor.equalsIgnoreCase("brightgreen")) {
     FolderMotdColorCode = EnumChatFormatting.GREEN;
   } else if (FolderMotdColor.equalsIgnoreCase("darkgrey")) {
     FolderMotdColorCode = EnumChatFormatting.DARK_GRAY;
   } else if (FolderMotdColor.equalsIgnoreCase("darkred")
       || FolderMotdColor.equalsIgnoreCase("maroon")) {
     FolderMotdColorCode = EnumChatFormatting.DARK_RED;
   } else if (FolderMotdColor.equalsIgnoreCase("purple")) {
     FolderMotdColorCode = EnumChatFormatting.DARK_PURPLE;
   } else {
     ServerListFolder.warn("Failed to parse the Color Setting. Using Purple");
     FolderMotdColorCode = EnumChatFormatting.DARK_PURPLE;
   }
 }
 /** Checks if the config version has changed and adds the options which are new. */
 private void checkForConfigUpdate() {
   if (version != configVersion) {
     ServerListFolder.info("Updating the config...");
     switch (configVersion) {
       case 0:
         if (FolderMotdColor.equals(defaults.getProperty("FolderMotdColor"))) {
           config.setProperty("FolderMotdColor", defaults.getProperty("FolderMotdColor"));
         }
         if (FolderMotdText.equals(defaults.getProperty("FolderMotdText"))) {
           config.setProperty("FolderMotdText", defaults.getProperty("FolderMotdText"));
         }
       case 1:
         // for the next version.
     }
     config.setProperty("configVersion", "" + version);
     saveConfig();
   }
 }
 public ServerListFolderConfig() {
   ServerListFolder.info("Attempting to load/create the configuration.");
   loadConfig();
   loadConfigData();
 }