Stop Configurate from ordering nodes by alphabetical order?

I want to organize my config so it looks like this:

version="0.3"
playJoinSound=false
warps{
}

But, Configurate has other ideas.

playJoinSound=false
version="0.3"
warps{
}

How can I prevent this?

I’m going to tentatively say that alphabetical order is the default, and cannot be changed (Someone please correct me if I am wrong). You might consider making an issue in the Configurate repo.

@zml any word on this? this seems like it’d be a common issue considering the typical scenario where plugin developers order their configuration by category.

This is an issue in the underlying Hocon library: https://github.com/typesafehub/config/blob/master/config/src/main/java/com/typesafe/config/impl/ConfigImpl.java#L250

Unfortunately it looks like future versions of Hocon will require jdk8, so seems like you’re stuck with this issue.

Configurate could always use a fork of typesafe config.
That’s what SpongeAPI did when a bug in checkstyle was fixed in a version that needs jdk7.
https://github.com/SpongePowered/SpongeAPI/blob/master/gradle/java.gradle#L123

I’m using JDK8 anyway.

That doesn’t mean you will ever see the new version. It depends what version gets bundled with configurate, and what the build target is for sponge implementations.

SpongeAPI has the same build targets as minecraft, which currently is JDK6, making plugins for 7 or higher means that their is a portion of users that will NOT be able to use your releases if you use any of the new JDK features.

Personally I hope Mojang move minecraft up to 8 soon considering Java 7 has been End of Life’d and Java 8 is being included in the launcher.

1 Like

Has there been any change to this? I would like to have control over the order of the nodes so I can put the config options in a logical order.

I’ve found this commit to Configurate that added setting a MapFactory that should change the ordering: hocon: Preserve element order in configurations. · zml2008/Configurate@70043d9 · GitHub

I’ve tried setting the MapFactories.insertionOrdered() to both the ConfigurationLoader and the root ConfigurationNode but it seems to have no effect. When the file and config options get created they’re still re-ordered alphabetically.

ConfigurationLoader<CommentedConfigurationNode> configLoader = HoconConfigurationLoader.builder().setDefaultOptions(ConfigurationOptions.defaults().setMapFactory(MapFactories.insertionOrdered())).setFile(config).build();
CommentedConfigurationNode rootNode = configLoader.createEmptyNode(ConfigurationOptions.defaults().setMapFactory(MapFactories.insertionOrdered()));

Its not a configurate issue as such, its more of the underlying support library :wink:

Has anyone come up with a solution?

Nope, my config’s still a mess unfortunately

Yes, mine too. I just asked if anyone found an easy solution.