Solved Save to config.yml

Discussion in 'Plugin Development' started by Krolewicz, Aug 9, 2018.

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

    Krolewicz

    Hello,
    if I repeat a subject, I apologize, but I did not find anything on the forum.
    I have config.yml and when a player will use the command /save to config.yml to write to the file "save".
    I want get config and add "save"

    Code:
    FileConfiguration config = main.getConfig();
    config.set("check.player.save", "save");
      try {
         config.save(main.getDataFolder()+"/config.yml");
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
    
    And this work, but turns Polish characters into squares and does not save values that are empty and mixes the ruler.
    Can you fix it?
    Code:
    I have:
    key1:
    key2:
    key3: ąćężź
    check:
      player:
        save:
    key4: Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum
    
    Code:
    I want:
    key1:
    key2:
    key3: ąćężź
    check:
      player:
        save: save
    key4: Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum
    
    Code:
    I receive
    key3: ∆∆∆∆
    check:
      player:
        save: save
    key4: Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem {<<<---moved ruler to down}
    IpsumLorem IpsumLorem Ipsum
    
    PS utf-8 is in config.yml but when i make this code it doesn't work
     
    Last edited by a moderator: Aug 12, 2018
  2. Offline

    ToldiIII

    File save is not appropriate.

    Use this:
    Main.java:
    Code:
    FileConfiguration config = getConfig();
    File config_file = new File(getDataFolder(), "config.yml");
    
    public void createFile() {
        try {
            if (config_file.exists()) {
                config = YamlConfiguration.loadConfiguration(config_file);
        } catch (IOException e) {
            e.printStackTrace();
            }
    }
    Other class:
    Code:
    main.config.set("check.player.save", "save");
      try {
         main.config.save(main.config_file);
      } catch (IOException e) {
         e.printStackTrace();
      }
    For Polish characters, use the replaceAll("<value>", "$") code in your code.
     
  3. Offline

    Krolewicz

    Nothing helped.
    Next cuts off the keys that have no value.
    folded keys e.g.
    changes from:
    Code:
    key1:
      key2:
        key3:
    
    on:
    Code:
    key1: {}
    
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Krolewicz You can't have keys without values.
     
  5. Offline

    Krolewicz

    Okay, but why this change
    Code:
    Key1: value1
      Key2:value2
        Key3:value3
    On:
    Key1: {}
     
    Last edited by a moderator: Aug 13, 2018
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    Krolewicz

Thread Status:
Not open for further replies.

Share This Page