本文整理匯總了Java中ninja.leaping.configurate.hocon.HoconConfigurationLoader.save方法的典型用法代碼示例。如果您正苦於以下問題:Java HoconConfigurationLoader.save方法的具體用法?Java HoconConfigurationLoader.save怎麽用?Java HoconConfigurationLoader.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ninja.leaping.configurate.hocon.HoconConfigurationLoader
的用法示例。
在下文中一共展示了HoconConfigurationLoader.save方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: load
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; //導入方法依賴的package包/類
public static void load(BetterKits instance) {
//load defaults
try {
URL defaultsInJarURL = CommonUtils.class.getResource("messages.yml");
YAMLConfigurationLoader defaultsLoader = YAMLConfigurationLoader.builder().setURL(defaultsInJarURL).build();
ConfigurationNode defaults = defaultsLoader.load();
HoconConfigurationLoader loader = HoconConfigurationLoader.builder().setPath(instance.getConfigDir().resolve("messages.conf")).build();
ConfigurationNode root = loader.load();
root.mergeValuesFrom(defaults);
loader.save(root);
for (Entry<Object, ? extends ConfigurationNode> entry : root.getChildrenMap().entrySet()) {
messages.put(entry.getKey().toString(), entry.getValue().getString());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例2: loadConfig
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; //導入方法依賴的package包/類
/**
* Loads the bStats configuration.
*
* @throws IOException If something did not work :(
*/
private void loadConfig() throws IOException {
Path configPath = configDir.resolve("bStats");
configPath.toFile().mkdirs();
File configFile = new File(configPath.toFile(), "config.conf");
HoconConfigurationLoader configurationLoader = HoconConfigurationLoader.builder().setFile(configFile).build();
CommentedConfigurationNode node;
if (!configFile.exists()) {
configFile.createNewFile();
node = configurationLoader.load();
// Add default values
node.getNode("enabled").setValue(true);
// Every server gets it's unique random id.
node.getNode("serverUuid").setValue(UUID.randomUUID().toString());
// Should failed request be logged?
node.getNode("logFailedRequests").setValue(false);
// Add information about bStats
node.getNode("enabled").setComment(
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
"To honor their work, you should not disable it.\n" +
"This has nearly no effect on the server performance!\n" +
"Check out https://bStats.org/ to learn more :)"
);
configurationLoader.save(node);
} else {
node = configurationLoader.load();
}
// Load configuration
enabled = node.getNode("enabled").getBoolean(true);
serverUUID = node.getNode("serverUuid").getString();
logFailedRequests = node.getNode("logFailedRequests").getBoolean(false);
}
示例3: serializeToJson
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; //導入方法依賴的package包/類
public static String serializeToJson(DataContainer container) throws IOException {
try (StringWriter writer = new StringWriter()) {
HoconConfigurationLoader loader = HoconConfigurationLoader.builder().setSink(() -> new BufferedWriter(writer)).build();
loader.save(DataTranslators.CONFIGURATION_NODE.translate(container));
return Base64.getEncoder().encodeToString(writer.toString().getBytes(Charsets.UTF_8));
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
示例4: loadConfig
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; //導入方法依賴的package包/類
/**
* Loads the bStats configuration.
*
* @throws IOException
* If something did not work :(
*/
private void loadConfig() throws IOException {
Path configPath = configDir.resolve("bStats");
configPath.toFile().mkdirs();
File configFile = new File(configPath.toFile(), "config.conf");
HoconConfigurationLoader configurationLoader = HoconConfigurationLoader.builder().setFile(configFile).build();
CommentedConfigurationNode node;
if (!configFile.exists()) {
configFile.createNewFile();
node = configurationLoader.load();
// Add default values
node.getNode("enabled").setValue(true);
// Every server gets it's unique random id.
node.getNode("serverUuid").setValue(UUID.randomUUID().toString());
// Should failed request be logged?
node.getNode("logFailedRequests").setValue(false);
// Add information about bStats
node.getNode("enabled").setComment(
"bStats collects some data for plugin authors like how many servers are using their plugins.\n"
+ "To honor their work, you should not disable it.\n"
+ "This has nearly no effect on the server performance!\n"
+ "Check out https://bStats.org/ to learn more :)");
configurationLoader.save(node);
} else {
node = configurationLoader.load();
}
// Load configuration
enabled = node.getNode("enabled").getBoolean(true);
serverUUID = node.getNode("serverUuid").getString();
logFailedRequests = node.getNode("logFailedRequests").getBoolean(false);
}
示例5: saveData
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; //導入方法依賴的package包/類
synchronized public void saveData() throws IOException, ObjectMappingException {
HoconConfigurationLoader loader = getDataLoader();
ConfigurationNode rootNode = loader.load();
rootNode.getNode("Kits").setValue(KitSerializer.token, new ArrayList<Kit>(this.kits.values()));
rootNode.getNode("PlayersData").setValue(PlayerDataSerializer.token, new ArrayList<PlayerData>(this.playersData.values()));
loader.save(rootNode);
}
示例6: writeTo
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; //導入方法依賴的package包/類
private static void writeTo(Callable<BufferedWriter> sink, DataView data) throws IOException {
final HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
.setHeaderMode(HeaderMode.NONE)
.setSink(sink)
.build();
final ConfigurationNode node = ConfigurateTranslator.instance().translate(data);
loader.save(node);
}
示例7: loadConfig
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; //導入方法依賴的package包/類
/**
* Loads the bStats configuration.
*
* @throws IOException If something did not work :(
*/
private void loadConfig() throws IOException {
Path configPath = configDir.resolve("bStats");
configPath.toFile().mkdirs();
File configFile = new File(configPath.toFile(), "config.conf");
HoconConfigurationLoader configurationLoader = HoconConfigurationLoader.builder().setFile(configFile).build();
CommentedConfigurationNode node;
if (!configFile.exists()) {
configFile.createNewFile();
node = configurationLoader.load();
// Add default values
node.getNode("enabled").setValue(true);
// Every server gets it's unique random id.
node.getNode("serverUuid").setValue(UUID.randomUUID().toString());
// Should failed request be logged?
node.getNode("logFailedRequests").setValue(false);
// Add information about bStats
node.getNode("enabled").setComment(
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
"To honor their work, you should not disable it.\n" +
"This has nearly no effect on the server performance!\n" +
"Check out https://bStats.org/ to learn more :)"
);
configurationLoader.save(node);
} else {
node = configurationLoader.load();
}
// Load configuration
enabled = node.getNode("enabled").getBoolean(true);
serverUUID = node.getNode("serverUuid").getString();
logFailedRequests = node.getNode("logFailedRequests").getBoolean(false);
}
示例8: loadWorldContext
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; //導入方法依賴的package包/類
private WorldFallbackContext loadWorldContext(World world) throws IOException
{
Path worldPath = configDir.resolve("world");
Path configPath = worldPath.resolve(world.getName().replaceAll("[^a-zA-Z0-9-]", "_") + ".conf");
if(!Files.isDirectory(worldPath))
Files.createDirectory(worldPath);
HoconConfigurationLoader loader = HoconConfigurationLoader.builder().setPath(configPath).build();
CommentedConfigurationNode main = loader.load(
ConfigurationOptions.defaults()
.setShouldCopyDefaults(true)
.setHeader("Default wild permissions on the world " + world.getName() + " with dimension " +
world.getDimension().getName() + " and unique id: " + world.getUniqueId())
);
CommentedConfigurationNode wildPerms = main.getNode("wild-permissions");
wildPerms.setComment(
"The permissions that affects unclaimed chunks on this world. Null values are inherited from the default-world-permissions declared on the default-permissions.conf file"
);
CommentedConfigurationNode defaultPerms = main.getNode("fallback-permissions");
defaultPerms.setComment(
"The fallback permissions that will be used when a claimed chunk or a zone does not define the permission, this will take priority over the default defined on the defailt-permission.conf file"
);
WorldFallbackContext worldContext = new WorldFallbackContext(world.getUniqueId());
loadWorldConfig(worldContext, defaultPerms, false);
loadWorldConfig(worldContext.getWilderness(), wildPerms, true);
try
{
loader.save(main);
}
catch(Exception e)
{
logger.error("Failed to save the world config file for " + world.getName() + " DIM:" +
world.getDimension().getName(), e);
}
return worldContext;
}
示例9: load
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; //導入方法依賴的package包/類
public ItemCategoryManager load() {
categoryToItemIds.clear();
CustomItemLibrary plugin = CustomItemLibrary.getInstance();
Path path = plugin.getConfigPath();
ConfigurationOptions options = plugin.getDefaultConfigurationOptions();
HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
.setDefaultOptions(options).setPath(path).build();
try {
CommentedConfigurationNode root = loader.load();
CommentedConfigurationNode nodeCategories = root.getNode(NODE_ITEM_CATEGORIES);
nodeCategories.setComment("Categories are used to determine the mining speed of blocks. Here you can add items from mods.");
if(nodeCategories.isVirtual()) {
defaultCategory(nodeCategories, "shovel", ItemTypes.WOODEN_SHOVEL, ItemTypes.STONE_SHOVEL,
ItemTypes.IRON_SHOVEL, ItemTypes.GOLDEN_SHOVEL, ItemTypes.DIAMOND_SHOVEL);
defaultCategory(nodeCategories, "hoe", ItemTypes.WOODEN_HOE, ItemTypes.STONE_HOE,
ItemTypes.IRON_HOE, ItemTypes.GOLDEN_HOE, ItemTypes.DIAMOND_HOE);
defaultCategory(nodeCategories, "pickaxe", ItemTypes.WOODEN_PICKAXE, ItemTypes.STONE_PICKAXE,
ItemTypes.IRON_PICKAXE, ItemTypes.GOLDEN_PICKAXE, ItemTypes.DIAMOND_PICKAXE);
defaultCategory(nodeCategories, "axe", ItemTypes.WOODEN_AXE, ItemTypes.STONE_AXE,
ItemTypes.IRON_AXE, ItemTypes.GOLDEN_AXE, ItemTypes.DIAMOND_AXE);
defaultCategory(nodeCategories, "shears", ItemTypes.SHEARS);
}
nodeCategories.getChildrenMap().forEach((rawCategory, rawItemIds) -> {
String category = Objects.toString(rawCategory);
List<String> itemIds = rawItemIds.getList(Objects::toString);
Set<Identifier> identifiers = itemIds.stream().map(itemId -> {
if(Identifier.isParseable(itemId))
return Identifier.parse(itemId);
else
return new Identifier("minecraft", itemId);
}).collect(Collectors.toSet());
categoryToItemIds.putAll(category, identifiers);
});
loader.save(root);
} catch (IOException e) {
e.printStackTrace();
}
return this;
}