Solved Custom configs

Discussion in 'Plugin Development' started by amatokus, Jul 10, 2014.

Thread Status:
Not open for further replies.
  1. Hi all I have this piece of code:

    Code:java
    1. private File side1File = new File(this.getDataFolder(), this.getConfig().getString("side_1.name")+"_players.yml");
    2. private FileConfiguration side1Config = YamlConfiguration.loadConfiguration(side1File);
    3.  
    4. private File side2File = new File(this.getDataFolder(), this.getConfig().getString("side_2.name")+"_players.yml");
    5. private FileConfiguration side2Config = YamlConfiguration.loadConfiguration(side2File);
    6.  
    7.  
    8. @Override
    9. public void onEnable() {
    10.  
    11. listt1 = side1Config.getStringList("players");
    12. listt2 = side2Config.getStringList("players");
    13.  
    14. try {
    15. side1File.createNewFile();
    16. } catch (IOException e) {
    17. e.printStackTrace();
    18. }
    19.  
    20. side1Config.addDefault("path", "string");
    21. }


    But when my file is created, IT'S BLANK! help [sheep]
     
  2. Offline

    tommycake50

    You need to save configs BTW, if you set a config value the file doesn't update until you save it.
     
    amatokus likes this.
  3. Offline

    unrealdesign

    Code:java
    1. public void save()
    2. {
    3. try
    4. {
    5. side1Config.save(side1File);
    6. side2Config.save(side2File);
    7. }
    8. catch(IOException ex)
    9. {
    10. e.printStackTrace();
    11. }
    12. }
     
    amatokus likes this.
  4. Hi! now I have this but config is still blank!

    Code:java
    1. private File side1File = new File(this.getDataFolder(), this.getConfig().getString("side_1.name")+"_players.yml");
    2. private FileConfiguration side1Config = YamlConfiguration.loadConfiguration(side1File);
    3.  
    4. private File side2File = new File(this.getDataFolder(), this.getConfig().getString("side_2.name")+"_players.yml");
    5. private FileConfiguration side2Config = YamlConfiguration.loadConfiguration(side2File);
    6.  
    7. public void saveFileConfig()
    8. {
    9. try
    10. {
    11. side1Config.save(side1File);
    12. side2Config.save(side2File);
    13. }
    14. catch(IOException ex)
    15. {
    16. ex.printStackTrace();
    17. }
    18. }
    19.  
    20. @Override
    21. public void onEnable() {
    22.  
    23. listt1 = side1Config.getStringList("players");
    24. listt2 = side2Config.getStringList("players");
    25.  
    26. try {
    27. side1File.createNewFile();
    28. } catch (IOException e) {
    29. e.printStackTrace();
    30. }
    31.  
    32. side1Config.addDefault("path", "string");
    33. this.saveFileConfig();
    34. }

    And no errors!

    Hey! I also tried one thing.

    I typed "path: "in my config, and when I reaload, It gets deleted!

    Solved, here is my new onEnable:

    Code:java
    1. side1Config.options().copyDefaults(true);
    2.  
    3. side1Config.addDefault("path", "string");
    4. this.saveFileConfig();


    Thanks tagged as SOLVED.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page