I have a config to store different dates and values per date. You can add more dates with values1 and 2, etc. Code: foo: 21-07-2012 20:00: value1: abc value2: def 19-07-2012 21:15: value1: ghi value2: jkl From this I create an array list of foo objects which is sorted by date. Now I'm searching for a possibility to write these sorted objects back into the config file. getConfig().addDefault(...) does nothing, probably because the values are all present in the config. getConfig().set(...) only overrides the first section and deletes the rest. Any help would be appreciated.
getConfig().set(...) shouldn't alter other sections than the passed section, can you give the failed code for it/
Sure. Code: //f is my sorted array list of foo objects. for (int i = 0; i < f.size(); i++){ getConfig().set("foo", f.get(i).getUnformatedDate()); getConfig().set("foo." + f.get(i).getUnformatedDate() + ".value1", f.get(i).getValue1()); getConfig().set("foo." + f.get(i).getUnformatedDate() + ".value2", f.get(i).getValue2()); } saveConfig(); After running this, only the latest date and its values are present in the config: Code: foo: 21-07-2012 20:00: value1: abc value2: def
it is this line that causes the removing getConfig().set("foo", f.get(i).getUnformatedDate()); it chances Code:yaml foo: 21-07-2012 20:00: value1: abc value2: def 19-07-2012 21:15: value1: ghi value2: jkl to Code:yaml foo: 21-07-2012 20:00
Oh yeah, good catch. Just remove that line. When you set value1 and value2 it will create the nodes above it automatically.
yes, you can even do set("a.really.long.name.for.an.node.You.know.it","?") and it creates them all automaticly
Thanks, that fixed the overwriting issue, but does not do what I want it to. I am searching for a possibility to sort the whole config per date, so that the config exemple given in the first post looks like this afterwards: Code: foo: 19-07-2012 21:15: value1: ghi value2: jkl 21-07-2012 20:00: value1: abc value2: def getConfig().set(...) doesn't seem do do this, since the the whole path is already present in the config. I thought of cleaning the config before writing, but I have no idea how I could do this... Any ideas how to archive such a sorting in the config itself?
I think you cant do it, because bukkit use an hashmap to store the key-value bindings, and the order of an hashmap is created by the hashcode, whits you can chance you can try putting it in a list if you want to keep the order