mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-01 06:23:22 +01:00
32 lines
836 B
Java
32 lines
836 B
Java
package com.Acrobot.Breeze.Configuration;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
/**
|
|
* @author Acrobot
|
|
*/
|
|
public class FieldParser {
|
|
/**
|
|
* Parses a field into a YAML-compatible string
|
|
*
|
|
* @param field Field to parse
|
|
* @return Parsed field
|
|
*/
|
|
public static String parse(Field field) {
|
|
StringBuilder builder = new StringBuilder(50);
|
|
|
|
try {
|
|
builder.append(field.getName()).append(": ").append(ValueParser.parseToYAML(field.get(null)));
|
|
} catch (IllegalAccessException e) {
|
|
e.printStackTrace();
|
|
return "";
|
|
}
|
|
|
|
if (field.isAnnotationPresent(ConfigurationComment.class)) {
|
|
builder.append('\n').append('#').append(field.getAnnotation(ConfigurationComment.class).value());
|
|
}
|
|
|
|
return builder.toString();
|
|
}
|
|
}
|