Solved Generating missing properties in config

Discussion in 'Spigot Plugin Development' started by MrGeneralQ, Jan 26, 2020.

  1. MrGeneralQ

    MrGeneralQ Previously qintinator

    Good morning everyone

    I'm currently looking for a solution on how I can generate config properties without checking them all for missing properties.

    Imagine I have a plugin with a series of properties, then a new release happens, I need to know the missing properties.

    Is there any proper way of doing this?

    Thank you in advance.

    Best regards,

    Mr Q
  2. SteelPhoenix


    Grab and load the internal configuration, then set it as default for the external configuration (Configuration#setDefaults(Configuration))
    Then I believe you can use ConfigurationOptions#copyDefaults(boolean) and FileConfiguration#save(File) to push the missing values to the external config file. (This will get rid of comments)
    • Like Like x 1
  3. MrGeneralQ

    MrGeneralQ Previously qintinator

    Does that not overwrite all the properties that were set by the user?
  4. Can‘t you jest set a default value? From what I remember FileConfiguration has getters that sound something like getOrDef(...) that will get the config or else a provided default value
  5. SteelPhoenix


    void addDefaults(@NotNull Configuration defaults)

    Sets the default values of the given paths as provided.
    If no source Configuration was provided as a default collection, then a new MemoryConfiguration will be created to hold the new default value.

    This method will not hold a reference to the specified Configuration, nor will it automatically update if that Configuration ever changes. If you require this, you should set the default source with setDefaults(org.bukkit.configuration.Configuration).

    defaults - A configuration holding a list of defaults to copy.
    IllegalArgumentException - Thrown if defaults is null or this.