-
Notifications
You must be signed in to change notification settings - Fork 32
Comments are lost when using CommentedConfig#copy with a mapCreator specified. #196
Copy link
Copy link
Open
Description
Hello! I think I have found a weird edge case in Night Config.
What Breaks
public CommentedConfig getConfig() {
return CommentedConfig.copy(config, LinkedHashMap::new);
}Calling this (or any mapCreator included copy method) will strip all comments from your config.
Background
We have to make abstractions to Night Config's content, mainly so we are able to work a specific interface into Mojang's DFU library.
This is specifically for user-facing content, so I wish to keep the order of the config entirely in-tact when encoding to a file.
Whilst the environment variable could be set in my case for LinkedHashSet, I'd prefer to avoid doing so just in case others are doing this too.
I have come up with a workaround for the time being, but I'd love to avoid implementing a workaround if possible.
Evil Workaround >:3
private CommentedConfig recurseComments(CommentedConfig newConfig, CommentedConfig oldConfig) {
for (CommentedConfig.Entry entry : oldConfig.entrySet()) {
newConfig.setComment(entry.getKey(), entry.getComment());
if (entry.getValue() instanceof CommentedConfig innerConfig) {
recurseComments(innerConfig, oldConfig.get(entry.getKey()));
}
}
return newConfig;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels