Problems with Configurate

I am trying to read a comment from my config using this method

ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setURL(asset.getUrl()).build();
CommentedConfigurationNode assetnode = loader.load();
System.out.println(assetnode.getNode("updater", "check").getComment().orElse(""));

Where ‘asset’ refers to this file

The problem is that all new lines are completely ignored, so this code returns:
(Where it should output a \n between the lines)

UltimateCore automatically checks for updates from Set this to true if you want to automatically check for updates This won’t download any files

This problem happens for all my config files, and for all nodes in these configs.
The big problem is that after editing a config, and saving it back, it also does not read the comments and saves the config like this:

So this makes it so me updating any value from within my plugin, fucking up the whole config.
This is a pretty high priority issue for me because it stops me from editing my config at all in my plugin.
What could cause this?
How can I fix this?

I a m uncertain, but it could be a problem in typesafe-config. Fire up a quick environment with just that (no configurate), and try reading, editing and saving that file again.

I don’t know how typesafe-config works.
If you could give me a quick example, considering I can’t find a quick start guide, I will try
I could only find this but its pretty long and I can’t find a quick example.

  1. Make sure that your config is on the classpath and is named application.conf.
  2. ConfigFactory.load() loads the config.
  3. Read the comment. Should be config.getConfig(path).origin().comments() if I remember correctly.
  4. Save the file. (or just inspect what it would have saved). You can convert the config to a String by going config.root.render(renderOptions). The render options are gotten using the ConfigRenderOptions class.
1 Like

I first tried this code

Config config = ConfigFactory.load();
config.getConfig(“application.conf”); //I tried both ‘application’ and ‘application.conf’ here

Which gave this error:

I finally came up with this code, altough it outputs way more than it should, it works.
This code (Where the application.conf file is the same af the general.conf linked above)

Config config = ConfigFactory.load(“application”);

Ended up outputting this:

Where at one of the important parts, for example the updater, the comments are intact.

"updater" : {
    # application.conf @ jar:file:/C:/Users/Jonathan/Desktop/Projecten/UltimateCore/build/libs/UltimateCore.jar!/application.conf: 22
    # UltimateCore automatically checks for updates from
    # Set this to true if you want to automatically check for updates
    # This won't download any files
    "check" : true

And config.origin().comments() is an empty list, weirdly enough.


It looks like it formats it correctly. I’d open an issue on Configurate’s bug tracker if nothing else comes up. Also for getting the comments, make sure you’re on the correct node first.

Already did that some time ago

I’ve investigated this issue a bit and posted my findings on the GitHub Issue.

Short Answer: TypeSafe Config

Long Answer: Probably TypeSafe Config. From my final post on the issue (so far):

The last hope for this to be a Configurate problem is if ConfigParseOptions.defaults() can be tweaked to allow multi-line comments.

1 Like

Thanks for looking in to this.
I have no idea how TypeSafe config works (as you could notice in my posts above) but if I can do anything to help/test, message me.
I would really love a solution for this tho, so I can finally update my config from code without breaking everything

The most helpful thing you could do would be to show your support for the new issue located here.

Well, the most helpful thing outside of, obviously, solving the problem on your own, somehow. xD