@Override
  public List<IConfigElement> getChildElements() {
    if (!isProperty) {
      List<IConfigElement> elements = new ArrayList<IConfigElement>();
      Iterator<ConfigCategory> ccI = category.getChildren().iterator();
      Iterator<Property> pI = category.getOrderedValues().iterator();
      @SuppressWarnings("unused")
      int index = 0;

      if (categoriesFirst)
        while (ccI.hasNext()) {
          ConfigElement temp = new ConfigElement(ccI.next());
          if (temp.showInGui()) // don't bother adding elements that shouldn't show
          elements.add(temp);
        }

      while (pI.hasNext()) {
        ConfigElement temp = new ConfigElement(pI.next());
        if (temp.showInGui()) elements.add(temp);
      }

      if (!categoriesFirst)
        while (ccI.hasNext()) {
          ConfigElement temp = new ConfigElement(ccI.next());
          if (temp.showInGui()) elements.add(temp);
        }

      return elements;
    }
    return null;
  }
 private void saveProperty(ConfigCategory cat, ConfigPropertyData propData) {
   if (cat.containsKey(propData.name())) {
     Property forgeProp = cat.get(propData.name());
     forgeProp.comment = propData.comment();
     setForgePropertyDefaultValue(forgeProp, propData);
     setForgePropertyValue(forgeProp, propData);
   } else {
     Property forgeProp = makeProperty(propData);
     if (forgeProp == null) return;
     forgeProp.comment = propData.comment();
     setForgePropertyDefaultValue(forgeProp, propData);
     cat.put(forgeProp.getName(), forgeProp);
   }
 }
 private void saveGroup(String parentName, ConfigGroupData groupData) {
   String catName = (parentName == null ? "" : (parentName + ".")) + groupData.name();
   ConfigCategory forgeCat = forgeConfig.getCategory(catName);
   forgeCat.setComment(groupData.comment());
   // Save Properties
   if (groupData.getProperties() != null) {
     for (ConfigPropertyData propData : groupData.getProperties()) {
       saveProperty(forgeCat, propData);
     }
   }
   // Save Children
   if (groupData.getChildGroups() != null) {
     for (ConfigGroupData childGroup : groupData.getChildGroups()) {
       saveGroup(catName, childGroup);
     }
   }
 }
 @Override
 public String getQualifiedName() {
   return isProperty ? prop.getName() : category.getQualifiedName();
 }
 @Override
 public Class<? extends IConfigEntry> getConfigEntryClass() {
   return isProperty ? prop.getConfigEntryClass() : category.getConfigEntryClass();
 }
 @Override
 public String getLanguageKey() {
   return isProperty ? prop.getLanguageKey() : category.getLanguagekey();
 }
 @Override
 public boolean requiresMcRestart() {
   return isProperty ? prop.requiresMcRestart() : category.requiresMcRestart();
 }
 @Override
 public boolean showInGui() {
   return isProperty ? prop.showInGui() : category.showInGui();
 }
 @Override
 public String getComment() {
   return isProperty ? prop.getComment() : category.getComment();
 }
  public void write(BufferedWriter out, int indent) throws IOException {
    String pad0 = getIndent(indent);
    String pad1 = getIndent(indent + 1);
    String pad2 = getIndent(indent + 2);

    write(out, pad0, "####################");
    write(out, pad0, "# ", name);

    if (comment != null) {
      write(out, pad0, "#===================");
      Splitter splitter = Splitter.onPattern("\r?\n");

      for (String line : splitter.split(comment)) {
        write(out, pad0, "# ", line);
      }
    }

    write(out, pad0, "####################", NEW_LINE);

    if (!allowedProperties.matchesAllOf(name)) {
      name = '"' + name + '"';
    }

    write(out, pad0, name, " {");

    Property[] props = properties.values().toArray(new Property[properties.size()]);

    for (int x = 0; x < props.length; x++) {
      Property prop = props[x];

      if (prop.comment != null) {
        if (x != 0) {
          out.newLine();
        }

        Splitter splitter = Splitter.onPattern("\r?\n");
        for (String commentLine : splitter.split(prop.comment)) {
          write(out, pad1, "# ", commentLine);
        }
      }

      String propName = prop.getName();

      if (!allowedProperties.matchesAllOf(propName)) {
        propName = '"' + propName + '"';
      }

      if (prop.isList()) {
        char type = prop.getType().getID();

        write(out, pad1, String.valueOf(type), ":", propName, " <");

        for (String line : prop.getStringList()) {
          write(out, pad2, line);
        }

        write(out, pad1, " >");
      } else if (prop.getType() == null) {
        write(out, pad1, propName, "=", prop.getString());
      } else {
        char type = prop.getType().getID();
        write(out, pad1, String.valueOf(type), ":", propName, "=", prop.getString());
      }
    }

    for (ConfigCategory child : children) {
      child.write(out, indent + 1);
    }

    write(out, pad0, "}", NEW_LINE);
  }
 public ConfigCategory getFirstParent() {
   return (parent == null ? this : parent.getFirstParent());
 }
 public static String getQualifiedName(String name, ConfigCategory parent) {
   return (parent == null
       ? name
       : parent.getQualifiedName() + Configuration.CATEGORY_SPLITTER + name);
 }