Solved Config File Question

Discussion in 'Spigot Plugin Development' started by SpiroMarshes, May 31, 2016.

  1. Here is my config file:

    Code (Text):
    # MystiqueCore
    # Version 1.1.2

    # The minimum and maximum delay in seconds that a welcome message can be sent to a player
    Minimum: 2
    Maximum: 5

    # Anybody with the mystique.welcomeback permission will greet
    # returning players with these sayings
    Welcome Sayings:
        - 'WB :)'
        - 'wb'
        - 'welcome back!'
        - 'Welcome Back!'
        - 'welcome back :)'
        - 'Welcome back! :)'

    # How much to multiply the players bet by for win payout
    BlackJack Win : 2

    # Additional reward if player gets 21
    BlackJack 21: .5

    # If using permission based win boosters, this value is the maximum boost allowed
    Max Boost: 5
     
    The config that is generated with the plugin looks like this:
    Code (Text):
    # MystiqueCore
    # Version 1.1.2
    #
    # The minimum and maximum delay in seconds that a welcome message can be sent to a player
    Minimum: 2
    Maximum: 5
    Welcome Sayings:
    - WB :)
    - wb
    - welcome back!
    - Welcome Back!
    - welcome back :)
    - Welcome back! :)
    BlackJack Win: 2
    BlackJack 21: 0.5
    Max Boost: 5
    What am I doing wrong?
     
  2. Pretty sure if you do it with the built in APIs it's going to remove all comments past the first value.
    Best option is to save the file yourself.
     
  3. This is what I'm doing:

    Code (Text):
    private void registerConfig()
        {
            getConfig().options().copyDefaults(true);
            saveConfig();
         
        }
    I call the registerConfig() method in my onEnable
     
    #4 SpiroMarshes, May 31, 2016
    Last edited: Jun 2, 2016
  4. You CAN NOT create comments in the config file except in the header if you create the config file while runtime!
     
  5. use
    Code (Java):
    saveDefaultConfig();
     
  6. The saveDefaultConfig(); as @MadMaxCookie mentioned will save the config once, and with comments throughout the whole YML.
     
  7. Thank you.