本文整理汇总了Java中ninja.leaping.configurate.loader.ConfigurationLoader.createEmptyNode方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationLoader.createEmptyNode方法的具体用法?Java ConfigurationLoader.createEmptyNode怎么用?Java ConfigurationLoader.createEmptyNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ninja.leaping.configurate.loader.ConfigurationLoader
的用法示例。
在下文中一共展示了ConfigurationLoader.createEmptyNode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
public static boolean load(File configDir) {
if (!configDir.exists() && !configDir.mkdir()) {
// todo failed to create config dir go die
return false;
}
File config = new File(configDir, "config.conf");
ConfigurationLoader<CommentedConfigurationNode> configLoader;
CommentedConfigurationNode rootNode;
try {
if (config.exists()) {
configLoader = HoconConfigurationLoader.builder().setFile(config).build();
rootNode = configLoader.load();
} else if (config.createNewFile()) {
configLoader = HoconConfigurationLoader.builder().setFile(config).build();
rootNode = configLoader.createEmptyNode();
} else {
// todo failed to create file for config go die
return false;
}
sConfig.clear();
putDefaultsAndGetValues(rootNode);
configLoader.save(rootNode);
} catch (IOException e) {
e.printStackTrace();
// todo some error go die
return false;
}
return true;
}
示例2: Configuration
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
public Configuration(ConfigurationLoader<CommentedConfigurationNode> configManager) {
this.configManager = configManager;
try {
this.rootNode = configManager.load();
} catch (IOException e) {
Latch.getLogger().error("Unable to load configuration, starting with a default one.");
this.rootNode = configManager.createEmptyNode();
}
loadDefaults();
saveConfig();
}
示例3: save
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
public void save(Path directory) {
Path configPath = directory.resolve(FILE_NAME);
ConfigurationLoader<CommentedConfigurationNode> loader =
HoconConfigurationLoader.builder().setPath(configPath).build();
ConfigurationOptions options = CustomItemLibrary.getInstance().getDefaultConfigurationOptions();
CommentedConfigurationNode rootNode = loader.createEmptyNode(options);
CommentedConfigurationNode modelIdsNode = rootNode.getNode(NODE_MODEL_IDS);
modelIdsNode.setComment("DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ARE ABSOLUTELY SURE ABOUT WHAT YOU ARE DOING!");
for (Map.Entry<DurabilityIdentifier, Identifier> entry : durabilityIdToModelId.entrySet()) {
DurabilityIdentifier durability = entry.getKey();
Identifier modelId = entry.getValue();
modelIdsNode.getNode(durability.toString()).setValue(modelId.toString());
}
try {
Files.createDirectories(configPath.getParent());
if (Files.exists(configPath))
Files.delete(configPath);
Files.createFile(configPath);
loader.save(rootNode);
} catch (IOException e) {
e.printStackTrace();
CustomItemLibrary.getInstance().getLogger()
.warn("Could not save the custom tool registry: " + e.getLocalizedMessage());
}
}
示例4: testThatConfigurationOptionsFunctionWorksAsExpected
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
/**
* Test that changing the ConfigurationOptions via the function argument between loads works.
*
* @throws Exception I hope not!
*/
@Test
public void testThatConfigurationOptionsFunctionWorksAsExpected() throws Exception {
URL url = getClass().getResource("/test.json");
final Path tempFile = folder.newFile().toPath();
ConfigurationLoader<ConfigurationNode> loader = GsonConfigurationLoader.builder()
.setSource(() -> new BufferedReader(new InputStreamReader(url.openStream())))
.setSink(AtomicFiles.createAtomicWriterFactory(tempFile, UTF_8)).setLenient(true).build();
// Create the SimpleConfig
SerialiserTransformer st = new SerialiserTransformer();
SimpleConfig simpleConfig = new SimpleConfig(loader, () -> loader.createEmptyNode(st.apply(loader.getDefaultOptions())), st);
Field field = AbstractAdaptableConfig.class.getDeclaredField("node");
field.setAccessible(true);
// The transformer shouldn't add any serialisers.
simpleConfig.load();
Assert.assertNull(((ConfigurationNode)field.get(simpleConfig)).getOptions().getSerializers().get(TypeToken.of(Dummy.class)));
st.set = true;
// The transformer shouldn't have added any serialisers yet.
Assert.assertNull(((ConfigurationNode)field.get(simpleConfig)).getOptions().getSerializers().get(TypeToken.of(Dummy.class)));
// It will on next load.
simpleConfig.load();
Assert.assertEquals(DummySerialiser.class, ((ConfigurationNode)field.get(simpleConfig)).getOptions().getSerializers().get(TypeToken.of(Dummy.class)).getClass());
}
示例5: testRoundtripValue
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
private void testRoundtripValue(Object value) throws IOException {
final Path tempFile = folder.newFile().toPath();
ConfigurationLoader<ConfigurationNode> loader = JSONConfigurationLoader.builder().setPath(tempFile).build();
ConfigurationNode start = loader.createEmptyNode();
start.getNode("value").setValue(value);
loader.save(start);
ConfigurationNode ret = loader.load();
assertEquals(value, ret.getNode("value").getValue());
}
示例6: testRoundtrippingLong
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
@Test
@Ignore("Gson currently makes it rather difficult to get the correct number type")
public void testRoundtrippingLong() throws IOException {
final Path tempFile = folder.newFile().toPath();
ConfigurationLoader<ConfigurationNode> loader = GsonConfigurationLoader.builder().setPath(tempFile).build();
ConfigurationNode start = loader.createEmptyNode();
start.getNode("long-num").setValue(TEST_LONG_VAL);
loader.save(start);
System.out.println(Files.readAllLines(tempFile));
ConfigurationNode ret = loader.load();
System.out.println(ret.getNode("long-num").getValue().getClass());
assertEquals(TEST_LONG_VAL, ret.getNode("long-num").getValue());
}
示例7: SingleToFiles
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
public static int SingleToFiles() {
int saved = 0;
for (World w:Sponge.getServer().getWorlds()){
Set<Region> regions = RedProtect.get().rm.getRegionsByWorld(w);
for (Region r:regions){
File wf = new File(RedProtect.get().configDir+File.separator+"data", w.getName()+File.separator+r.getName()+".conf");
ConfigurationLoader<CommentedConfigurationNode> regionManager = HoconConfigurationLoader.builder().setPath(wf.toPath()).build();
CommentedConfigurationNode fileDB = regionManager.createEmptyNode();
File f = new File(RedProtect.get().configDir+File.separator+"data", w.getName());
if (!f.exists()){
f.mkdir();
}
saved++;
saveConf(addProps(fileDB, r), regionManager);
}
File oldf = new File(RedProtect.get().configDir+File.separator+"data", "data_"+ w.getName() + ".conf");
if (oldf.exists()){
oldf.delete();
}
}
if (!RedProtect.get().cfgs.getBool("flat-file.region-per-file")){
RedProtect.get().cfgs.setConfig("flat-file.region-per-file", true);
}
RedProtect.get().cfgs.save();
return saved;
}
示例8: save
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
@Override
public int save() {
int saved = 0;
try {
RedProtect.get().logger.debug("default","RegionManager.Save(): File type is " + RedProtect.get().cfgs.getString("file-type"));
String world = this.getWorld().getName();
if (RedProtect.get().cfgs.getString("file-type").equals("file")) {
File datf = new File(RedProtect.get().configDir+File.separator+"data", "data_" + world + ".conf");
ConfigurationLoader<CommentedConfigurationNode> regionManager = HoconConfigurationLoader.builder().setPath(datf.toPath()).build();
CommentedConfigurationNode fileDB = regionManager.createEmptyNode();
for (Region r:regions.values()){
if (r.getName() == null){
continue;
}
if (RedProtect.get().cfgs.getBool("flat-file.region-per-file")) {
if (!r.toSave()){
continue;
}
datf = new File(RedProtect.get().configDir+File.separator+"data", world+File.separator+ r.getName() + ".conf");
regionManager = HoconConfigurationLoader.builder().setPath(datf.toPath()).build();
fileDB = regionManager.createEmptyNode();
}
fileDB = RPUtil.addProps(fileDB, r);
saved++;
if (RedProtect.get().cfgs.getBool("flat-file.region-per-file")) {
saveConf(fileDB, regionManager);
r.setToSave(false);
}
}
if (!RedProtect.get().cfgs.getBool("flat-file.region-per-file")) {
RPUtil.backupRegions(fileDB, world);
saveConf(fileDB, regionManager);
} else {
//remove deleted regions
File wfolder = new File(RedProtect.get().configDir+File.separator+"data", world);
if (wfolder.exists()){
File[] listOfFiles = wfolder.listFiles();
for (File region:listOfFiles){
if (region.isFile() && !regions.containsKey(region.getName().replace(".conf", ""))){
region.delete();
}
}
}
}
}
}
catch (Exception e4) {
e4.printStackTrace();
}
return saved;
}