コード例 #1
0
 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);
   }
 }
コード例 #2
0
  private Property makeProperty(ConfigPropertyData propData) {
    Property.Type type = CONFIG_TYPES.get(propData.getType());
    if (type == null) return null;
    if (!propData.getType().isArray()) {
      Property forgeProp = new Property(propData.name(), String.valueOf(propData.getValue()), type);
      forgeProp.set(String.valueOf(propData.getValue()));
      return forgeProp;
    }

    switch (type) {
      case INTEGER:
        {
          Integer[] val = (Integer[]) propData.getValue();
          String[] propVal = new String[val.length];
          for (int i = 0; i < val.length; i++) propVal[i] = String.valueOf(val[i]);
          Property forgeProp = new Property(propData.name(), propVal, type);
          forgeProp.set(propVal);
          return forgeProp;
        }
      case DOUBLE:
        if (propData.getType().equals(Float.class) || propData.getType().equals(float.class)) {
          Float[] val = (Float[]) propData.getValue();
          String[] propVal = new String[val.length];
          for (int i = 0; i < val.length; i++) propVal[i] = String.valueOf(val[i]);
          Property forgeProp = new Property(propData.name(), propVal, type);
          forgeProp.set(propVal);
          return forgeProp;
        } else {
          Double[] val = (Double[]) propData.getValue();
          String[] propVal = new String[val.length];
          for (int i = 0; i < val.length; i++) propVal[i] = String.valueOf(val[i]);
          Property forgeProp = new Property(propData.name(), propVal, type);
          forgeProp.set(propVal);
          return forgeProp;
        }
      case BOOLEAN:
        {
          Boolean[] val = (Boolean[]) propData.getValue();
          String[] propVal = new String[val.length];
          for (int i = 0; i < val.length; i++) propVal[i] = String.valueOf(val[i]);
          Property forgeProp = new Property(propData.name(), propVal, type);
          forgeProp.set(propVal);
          return forgeProp;
        }
      case STRING:
        String[] propVal = (String[]) propData.getValue();
        Property forgeProp = new Property(propData.name(), propVal, type);
        forgeProp.set(propVal);
        return forgeProp;
    }

    return null;
  }