Auto-Updating Config Files (Bukkit - YML)

Any help topics that don't fit in the current categories can go here.
Post Reply
User avatar
offluffy
Posts: 65
Joined: Tue Mar 20, 2012 7:04 am

Auto-Updating Config Files (Bukkit - YML)

Post by offluffy »

So this isn't so much something I can't do, but wondering if there's a better way to do it. The only way I've been able to auto-update config files is by creating temp variables for every option in the config, overwriting the old config, then replacing the old variables into the new config and setting the rest to default values. This seems a little complicated because I have to keep going back to the function that updates the config and altering it to accommodate new variables, which I think in doing so may cause the console to spit out errors trying to find variables that aren't in certain version of the file. I also tried a semi-automatic way of doing it, by extracting the entire config into a ConfigurationSection, overwriting the config with the new one, then setting the ConfigurationSection back, but this didn't work much at all, albeit I can't recall exactly why not. Is there a better way to have the plugin update the config file yet preserve variables that are already set? May also need to do this with more than just the config since I have another file that was completely restructured to merge 2 or 3 files together. Thanks in advance!
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Auto-Updating Config Files (Bukkit - YML)

Post by jacek »

Are we talking about updating across plugin version changes ? If so I think it's generally accepted that people just manually delete their config file and have to edit it again. Realistically how often do you need to change the format of the file ?
Image
User avatar
offluffy
Posts: 65
Joined: Tue Mar 20, 2012 7:04 am

Re: Auto-Updating Config Files (Bukkit - YML)

Post by offluffy »

Well, considering this plugin is still fairly new and I keep coming up with new features, I end up restructuring files or adding options to the config, and since the config has options with lists of stuff, and I thought it'd be convenient to have the plugin do the updating automatically. Especially when it comes to the bans file. I would rather have the plugin migrate the lists to the new structuring automatically because I know if it doesn't I'll get spammed on the dev page about how the plugin messed up because people are generally too lazy to read the instructions XD
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Auto-Updating Config Files (Bukkit - YML)

Post by jacek »

Well there is not really a way around it as far as I can tell. You do just have to take the old values and put them with the new keys.

I normally have a finalised config file before release though so it might be worth trying to come up a with a format that can easily be extended if needed.
Image
User avatar
offluffy
Posts: 65
Joined: Tue Mar 20, 2012 7:04 am

Re: Auto-Updating Config Files (Bukkit - YML)

Post by offluffy »

Ahhh, alrighty, thanks anyways! XD I'm very persistent >.> I'll prolly keep trying various methods.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Auto-Updating Config Files (Bukkit - YML)

Post by jacek »

If you come up with a neat way let me know :D
Image
Post Reply