本文整理汇总了Java中ninja.leaping.configurate.commented.CommentedConfigurationNode.setComment方法的典型用法代码示例。如果您正苦于以下问题:Java CommentedConfigurationNode.setComment方法的具体用法?Java CommentedConfigurationNode.setComment怎么用?Java CommentedConfigurationNode.setComment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ninja.leaping.configurate.commented.CommentedConfigurationNode
的用法示例。
在下文中一共展示了CommentedConfigurationNode.setComment方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serializeTo
import ninja.leaping.configurate.commented.CommentedConfigurationNode; //导入方法依赖的package包/类
@Override
public void serializeTo(Object instance, ConfigurationNode node) throws ObjectMappingException {
if (!node.isVirtual() && node instanceof CommentedConfigurationNode) {
CommentedConfigurationNode ccn = (CommentedConfigurationNode) node;
String comment = ccn.getComment().orElse("");
if (!comment.endsWith(COMMENT)) {
ccn.setComment(ccn.getComment() + System.lineSeparator() + COMMENT);
}
}
// super.serializeTo(instance, node);
}
示例2: addComment
import ninja.leaping.configurate.commented.CommentedConfigurationNode; //导入方法依赖的package包/类
public void addComment(final String paths, final String... comments){
CommentedConfigurationNode node = get(paths);
if (node.getValue() == null){
node.setComment(String.join("\n", comments));
this.setModified(true);
}
}
示例3: loadWorldConfig
import ninja.leaping.configurate.commented.CommentedConfigurationNode; //导入方法依赖的package包/类
private void loadWorldConfig(@Nullable PublicContext context, CommentedConfigurationNode parentNode, boolean wild)
{
for(Permission permission : values())
{
CommentedConfigurationNode node = parentNode.getNode(permission.toString().toLowerCase());
boolean def = wild? permission.isAllowedByDefaultOnTheWild() : permission.isAllowedByDefault();
node.setComment(permission.getDescription() + " [Default:" + def + "]");
if(context != null)
{
if(!node.isVirtual())
{
Object value = node.getValue();
if(value instanceof Boolean)
{
context.setPublicPermission(permission, Tristate.fromBoolean((boolean) value));
context.setModified(false);
}
}
}
else
{
boolean val = node.getBoolean(def);
if (val != def)
{
if (wild)
permission.setAllowedByDefaultOnTheWild(val);
else
permission.setAllowedByDefault(val);
permission.setModified(false);
}
}
}
}
示例4: save
import ninja.leaping.configurate.commented.CommentedConfigurationNode; //导入方法依赖的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());
}
}
示例5: setNode
import ninja.leaping.configurate.commented.CommentedConfigurationNode; //导入方法依赖的package包/类
/**
* Saves the data that this adapter manages back to the config manager.
*
* @param data An object of type {@link R}.
* @see #insertIntoConfigurateNode(ConfigurationNode, Object)
* @throws ObjectMappingException if the object could not be saved.
*/
public final void setNode(R data) throws ObjectMappingException {
Preconditions.checkState(attachedConfig != null, "You must attach this adapter before using it.");
ConfigurationNode node = insertIntoConfigurateNode(getNewNode(), data);
if (this.header != null && node instanceof CommentedConfigurationNode) {
CommentedConfigurationNode ccn = (CommentedConfigurationNode) node;
ccn.setComment(this.header);
}
nodeSaver.accept(node);
}
示例6: saveConfig
import ninja.leaping.configurate.commented.CommentedConfigurationNode; //导入方法依赖的package包/类
public void saveConfig(CommentedConfigurationNode node) throws IOException
{
node.setComment(node.getComment().orElse(this.translation
.take("virtualchest.config.commandAliases.comment").toPlain()));
}
示例7: loadWorldContext
import ninja.leaping.configurate.commented.CommentedConfigurationNode; //导入方法依赖的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;
}
示例8: load
import ninja.leaping.configurate.commented.CommentedConfigurationNode; //导入方法依赖的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;
}