Setting in config.yml

Discussion in 'Plugin Development' started by Ollywood, Jul 23, 2014.

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

    Ollywood

    Hi,
    Im trying to change config.yml through commands, but whenever I set the config, and save it, the config reformats and deletes stuff.

    Code:
    int startItemNum = Integer.parseInt(args[2]);
    getConfig().set("startItem", startItemNum);
    saveConfig();
    
    The config goes from this:

    Code:
    # The number below is the mount of time (in seconds) is the duration of the game.
    gameDuration: 120
     
    # What item the player recieves when the game starts.
    # Default is Iron Pickaxe
    startItem: 257
     
    # Below is the item that players will have to find during the game!
    # Default is Iron Ore
    # IT WILL ONLY ACCEPT ITEM NUMBERS!!
    item: 15
    # Please put the name of the item players are supposed to collect below!
    itemName: Iron Ore
     
    # Whether the player keeps the items specified above after the game ends
    keepItems: true
     
    # Pretty self-explanatory. Whether the user keeps the start item when the gaem ends
    keepStartItem: false
     
    # The amount of start items you get at start
    # E.g. startItemAmount: 2 (You get 2 iron pickaxes/startItem)
    startItemAmount: 1
    To this:

    Code:
    gameDuration: 120
    startItem: 3
    item: 15
    itemName: Iron Ore
    keepItems: true
    keepStartItem: false
    startItemAmount: 1
    
    And when i open it in normal notepad, its just 1 long line
     
  2. Offline

    CorrieKay

    If you want to do something like this, you'll need to create a custom saving method, as the yaml implementation that Bukkit uses doesnt support saving of comments besides the header.

    Considering you're only using the root configuration section, it shouldn't be too difficult to do so with a file output stream.
     
  3. Offline

    Ollywood

    CorrieKay I don't know how to make a custom saving method. Could you please direct me to a tutorial or create an example yourself?
     
  4. Offline

    Gater12

    Ollywood
    There is a resource for saving comments in the config somewhere in the Resources sub-section.
     
  5. Offline

    CorrieKay

    Ooh, so there is. I like it!
     
  6. Offline

    Ollywood

Thread Status:
Not open for further replies.

Share This Page