当前位置: 首页>>代码示例>>Java>>正文


Java YamlRepresenter类代码示例

本文整理汇总了Java中org.bukkit.configuration.file.YamlRepresenter的典型用法代码示例。如果您正苦于以下问题:Java YamlRepresenter类的具体用法?Java YamlRepresenter怎么用?Java YamlRepresenter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


YamlRepresenter类属于org.bukkit.configuration.file包,在下文中一共展示了YamlRepresenter类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: YamlConfigurationR

import org.bukkit.configuration.file.YamlRepresenter; //导入依赖的package包/类
public YamlConfigurationR() throws Exception {
  Field yamlOptionsField = YamlConfiguration.class.getDeclaredField("yamlOptions");
  yamlOptionsField.setAccessible(true);
  DumperOptionsR yamlOptions = new DumperOptionsR();
  yamlOptionsField.set(this, yamlOptions);

  Field yamlRepresenterField = YamlConfiguration.class.getDeclaredField("yamlRepresenter");
  yamlRepresenterField.setAccessible(true);
  YamlRepresenter yamlRepresenter = new YamlRepresenter();
  yamlRepresenterField.set(this, yamlRepresenter);

  Field yamlField = YamlConfiguration.class.getDeclaredField("yaml");
  yamlField.setAccessible(true);
  yamlField.set(this, new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions));
}
 
开发者ID:SCLeoX,项目名称:SCUtils,代码行数:16,代码来源:Config.java

示例2: saveYAML

import org.bukkit.configuration.file.YamlRepresenter; //导入依赖的package包/类
@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();
	}

}
 
开发者ID:FastFelix771,项目名称:TownyWands,代码行数:30,代码来源:ConfigManager.java


注:本文中的org.bukkit.configuration.file.YamlRepresenter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。