Solved Not copying default config properly?

Discussion in 'Plugin Development' started by O3Bubbles09, Jul 13, 2014.

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

    O3Bubbles09

    So this is my SettingsManager class:
    Code:java
    1. package me.robert.bubbleeconomy.files;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.io.InputStreamReader;
    6. import java.io.Reader;
    7. import java.io.UnsupportedEncodingException;
    8. import java.util.logging.Level;
    9.  
    10. import me.robert.bubbleeconomy.BubbleEconomy;
    11.  
    12. import org.bukkit.configuration.file.FileConfiguration;
    13. import org.bukkit.configuration.file.YamlConfiguration;
    14.  
    15. public class SettingsManager {
    16.  
    17. private BubbleEconomy plugin = BubbleEconomy.getPlugin();
    18.  
    19. private SettingsManager() { }
    20. private static SettingsManager instance = new SettingsManager();
    21. public static SettingsManager getInstance() { return instance; }
    22.  
    23. private FileConfiguration config;
    24. private File cFile;
    25.  
    26. /* Reload / Create config.yml file */
    27. public void setup() {
    28. if(cFile == null) {
    29. cFile = new File(plugin.getDataFolder(), "config.yml");
    30. }
    31. config = YamlConfiguration.loadConfiguration(cFile);
    32.  
    33. /* Check the Jar for default config.yml */
    34. Reader defConfigStream;
    35. try {
    36. defConfigStream = new InputStreamReader(plugin.getResource("config.yml"), "UTF8");
    37. if (defConfigStream != null) {
    38. config = YamlConfiguration.loadConfiguration(defConfigStream);
    39. }
    40. e.printStackTrace();
    41. }
    42.  
    43. //addDefaults();
    44. saveConfig();
    45. }
    46.  
    47. /* private void addDefaults() {
    48.  
    49.   if(cFile == null) {
    50.   config.set("Prefix", "&6[Bubble Economy]");
    51.   config.set("Enable Starting Cash", true);
    52.   config.set("Starting Balance", 100.0);
    53.   } else {
    54.   return;
    55.   }
    56.   }*/
    57.  
    58. /* Get the config.yml file */
    59. public FileConfiguration getConfig() {
    60. if(config == null) {
    61. setup();
    62. }
    63. return config;
    64. }
    65.  
    66. /* Save the config.yml */
    67. public void saveConfig() {
    68. if (config == null || cFile == null) {
    69. return;
    70. }
    71. try {
    72. getConfig().save(cFile);
    73. } catch (IOException ex) {
    74. plugin.getLogger().log(Level.SEVERE, "Could not save config to " + cFile, ex);
    75. }
    76. }
    77.  
    78.  
    79. }


    This is my default config:
    Code:
    # Set the prefix for Bubble Economy #
    Prefix: '&6[Bubble Economy]'
    # Should new players get money when they join? If so how much? #
    Enable Starting Cash: true
    Starting Balance: 100.0
    The generated config:
    Code:
    # Set the prefix for Bubble Economy #
    Prefix: '&6[Bubble Economy]'
    Enable Starting Cash: true
    Starting Balance: 100.0
    
    Anyone know why? Also no errors in console....
     
  2. Offline

    xTigerRebornx

    O3Bubbles09 Bukkit's ConfigurationAPI doesn't save comments, you'll have to use your own method for it.
    There are resources around I believe though.
     
  3. Offline

    O3Bubbles09

    xTigerRebornx Okay thanks for the information. I will look into it for sure.
     
  4. Offline

    nzkiwi.5000

  5. Offline

    Gater12

    xTigerRebornx
    I use saveDefaultConfig() and that saves the comments somehow?
     
Thread Status:
Not open for further replies.

Share This Page