Config Troubles

Discussion in 'Plugin Development' started by BungeeTheCookie, Jun 19, 2014.

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

    BungeeTheCookie

    Alright, I have a question.
    I am coding a minigame plugin, and on every update, the config.yml and messages.yml configs will change their format. I use Config-Version to sync the config's version to the plugin's version. On a new update, if the config version does not equal the actual version, it will add the changes made. How do I do this instead of just using config.delete() and saveDefaultConfig?
     
  2. Offline

    1Rogue

    Why would you bother with config versioning? Just guarantee that the appropriate values are there on startup, and if not, set them.
     
  3. Offline

    Garris0n

    He said that the config/messages will change their entire format every single version.

    I think you have a design problem if you know there will be an entire format change every update.
     
    1Rogue likes this.
  4. Offline

    1Rogue

    What is your "format"? How is it changing every time?
     
  5. Offline

    BungeeTheCookie

    1Rogue Garris0n
    Im sorry, I didn't mean it like that. I typed this up at 10:00 PM :p. What I meant to say was that I was likely to add new things and remove others on every version update. I am making a minigame plugin, so each update will include large changes.
    EDIT: Is there a way to loop through all of the values in the config and store them in an object HashMap<String, Object>?
     
  6. Offline

    Garris0n

    Removing others suggests a lack of backwards compatibility, which you should fix.

    Adding new ones just involves enabling copyDefaults...
     
  7. Offline

    BungeeTheCookie

    copyDefaults overrides the values in the config, so it would be the same as deleting and restoring a new config..?
     
  8. Offline

    Garris0n

    I believe it copies in any values that are in the default config but not in the config.
     
  9. Offline

    1Rogue

    What is it you are saving to the config?
     
  10. Offline

    BungeeTheCookie

  11. Offline

    1Rogue

    So then just have a check if the values aren't there and set them if they aren't. You can use an enum to store config values and then iterate over the values to look for everything.
     
  12. Offline

    BungeeTheCookie

    So like this..?
    Code:java
    1. public enum Blah {
    2. WOW("ConfigLine1"),
    3. BOB("Meepers2"),
    4. MEEP("ConfigVersion")
    5. }

    If the enum set up is like that, how do you get the string next to the enum? And iterate through everything?
     
  13. Offline

    1Rogue


    Here's an example:

    https://github.com/CodeLanx/LanxLib...delanx/lanxlibexample/config/ConfigValue.java

    You simply provide the path and the default value, and then when startup up you can iterate through the config values:

    Code:java
    1. YamlConfiguration file = /* your config file */;
    2. for (YourEnum conf : YourEnum.values()) {
    3. if (!file.isSet(conf.getPath())) {
    4. file.set(conf.getPath(), conf.getDefault());
    5. }
    6. }
     
Thread Status:
Not open for further replies.

Share This Page