@SneakyThrows
public static void saveYAML(@NonNull YamlConfiguration config, @NonNull File file) {
Method buildHeader = Reflect.getMethod(config.getClass(), "buildHeader");
DumperOptions yamlOptions = (DumperOptions) Reflect.getField(config.getClass(), "yamlOptions").get(config);
YamlRepresenter yamlRepresenter = (YamlRepresenter) Reflect.getField(config.getClass(), "yamlRepresenter").get(config);
Yaml yaml = (Yaml) Reflect.getField(config.getClass(), "yaml").get(config);
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
yamlOptions.setIndent(config.options().indent());
yamlOptions.setAllowUnicode(true);
String configHeader = (String) buildHeader.invoke(config);
String yamlDump = yaml.dump(config.getValues(false));
String blankConfig = (String) Reflect.getField(config.getClass(), "BLANK_CONFIG").get(null);
if (yamlDump.equalsIgnoreCase(blankConfig)) yamlDump = "";
String data = StringEscapeUtils.unescapeJava(new String(new StringBuilder(configHeader).append(yamlDump).toString().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
try(OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
writer.write(data);
} catch(IOException e) {
e.printStackTrace();
}
}
ConfigManager.java 文件源码
java
阅读 31
收藏 0
点赞 0
评论 0
项目:TownyWands
作者:
评论列表
文章目录