YAML saveConfig() removes all spaces and headers?

Discussion in 'Plugin Development' started by PretMetInternet, Jan 6, 2019.

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

    PretMetInternet

    Hello everyone, I just have a bug I can't fix.
    The thing is that I am having this:
    Code:
    getConfig().options().copyDefaults(true);
            getConfig().options().copyHeader(true);
            saveDefaultConfig();
    in my onEnable() method, which saves all the defaults into the config. This part works.
    But, here it comes. Whenever I call the method "saveConfig()", all headers and spaces get deleted.

    Before:
    Code:
    # Hey there! Thanks for using NickNamesPlus! In the configuration file, you can change everything to your own wishes!
    
    # Here, you can set up the ranks you are able to display while nicked!
    # Change the rank prefix to the prefix you want the rank to show.
    # NOTE: You have to put the ranks in order from lowest - highest, as shown below.
    
    ranks:
      default:
        display: "&7Default"
        prefix: "&7"
        suffix: ""
    
    # Here, you can change the "not enough permissions" message!
    
    not-enough-permissions: "&cYou don't have enough permissions to execute this command."
    
    # Set the GUI name
    gui-name: &aSet Nickname
    
    # Set a location for signs which is not used:
    sign-location:
      x:
      y:
      z:
      world:
    
    # --------------------------WARNING--------------------------
    # DON'T TOUCH THIS! OR SYSTEM MECHANICS WILL BECOME UNSTABLE!
    # --------------------------WARNING--------------------------
    players:
      begin:
      
    After:
    Code:
    # Hey there! Thanks for using NickNamesPlus! In the configuration file, you can change everything to your own wishes!
    #
    # Here, you can set up the ranks you are able to display while nicked!
    # Change the rank prefix to the prefix you want the rank to show.
    # NOTE: You have to put the ranks in order from lowest - highest, as shown below.
    
    ranks:
      default:
        display: '&7Default'
        prefix: '&7'
        suffix: ''
    not-enough-permissions: '&cYou don''t have enough permissions to execute this command.'
    gui-name: Nickname
    sign-location: {}
    players:
      f98ed4ad-5a40-3665-84b5-6d9309ef5391:
        display:
          name: Normal
          rank: Normal
          skin: Normal
        setting-up:
          name: Not Set
          rank: Not Set
          skin: Not Set
    
    I know, this last "don't touch" part doesn't really fit in config.yml, I am moving that to a custom .yml later.

    Whenever I call this method:
    Code:
    public void registerPlayer(Player p){
            getConfig().set("players." + p.getUniqueId().toString() + ".display.name", "Normal");
            getConfig().set("players." + p.getUniqueId().toString() + ".display.rank", "Normal");
            getConfig().set("players." + p.getUniqueId().toString() + ".display.skin", "Normal");
           
            getConfig().set("players." + p.getUniqueId().toString() + ".setting-up.name", "Not Set");
            getConfig().set("players." + p.getUniqueId().toString() + ".setting-up.rank", "Not Set");
            getConfig().set("players." + p.getUniqueId().toString() + ".setting-up.skin", "Not Set");
    
            saveConfig();
        }
    It removes all headers and spaces.

    The strange thing is that the beginning headers stay, and the other ones don't.

    Thanks a lot for your help, all help is appreciated.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @PretMetInternet The header is just the first part, comments are no headers.
    Spacing is not saved anyways.
     
  3. Offline

    PretMetInternet

    Alright thanks for that
    Is there any way to save comments?
     
  4. Offline

    timtower Administrator Administrator Moderator

    You can't.
    My suggestion would be to save the changing data in a different file.
     
  5. Offline

    PretMetInternet

    Alright thats a good idea
    thanks for your help
     
Thread Status:
Not open for further replies.

Share This Page