Updating config.yml to new version.

Discussion in 'Plugin Development' started by DutchJellyV2, Mar 10, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    DutchJellyV2

    Hi programmers,

    I'm currently struggeling with figuring out why saveDefaultConfig() won't actually save new configuration attributes. The config.yml of the plugin I'm working on needs to update to the newer version of the config.yml in order for the enable-updatechecker option.

    However, when completely removing the config.yml, the saveDefaultConfig() function will paste the new one as expected.

    I do understand why it's not adding new values to the config because everything is by default null. But if something is set to null you don't want to add this keyword to the config again. But I still would like to know any work-around to this issue!

    What could be a workaround is to make a class that handles this. I could for example make a class called LegacyConfigUpdater.

    Thanks alot,
    DutchJelly
     
    Last edited: Mar 10, 2019
  2. Offline

    MightyOne

    Show your code
     
  3. @DutchJellyV2
    If the only thing you want to update is the update-checker, then just append it yourself when the plugin loads. If that line already exists, then you don't need to update it again.
     
  4. Offline

    DutchJellyV2

    I dont want do do that for every update where the default config gets changed. Ill try to look for a solution thats generic.

    Verstuurd vanaf mijn COL-L29 met Tapatalk
     
  5. @DutchJellyV2
    Well with each update, create a copy of the users current settings, then when delete their config and replace it with a new one with all values, paste the users old settings into the required sections.
     
  6. Offline

    DutchJellyV2

    What the problem with that is is that comments and spacing get removed when using saveConfig(). But that approach could probably work and I'll look into that more.

    Verstuurd vanaf mijn COL-L29 met Tapatalk
     
  7. Offline

    OpperElfje

    Did you solve it? i have the same issue.
     
  8. Offline

    DutchJellyV2

    No I haven't solved it yet sorry.

    Verstuurd vanaf mijn COL-L29 met Tapatalk
     
  9. @DutchJellyV2
    Okay so you want to keep config comments?

    Likely case is to use a custom config. They're easy to setup, not as easy as bukkit's built in one, but pretty nifty. They can store comments without being overwritten, just call config#save(); and unlike Bukkit, it will not attempt to format / remove anything. Therefore, keeping your comments.
     
    TheKiller53 likes this.
Thread Status:
Not open for further replies.

Share This Page