Solved Rename config.yml?

Discussion in 'Plugin Development' started by Reteckz, Mar 29, 2013.

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

    Reteckz

    Hey guys,

    I have a fully working plugin for a XPStorage, but the problem is that i'm storing all the information in config.yml at the moment.
    Is there a way to rename config.yml to storage.yml or something?

    I'm using the following code atm.

    Code:
                            FileConfiguration config;
                config = getConfig();
                new File("plugins" + File.separator + "XPStorage" + File.separator + "db.yml");
                if(!config.contains(name)) {
                    config.set(name, 0);
                }
                saveConfig();
     
  2. Offline

    DSH105

  3. Offline

    Reteckz

  4. Offline

    DSH105

    So you've tried this?

    Code:java
    1.  
    2. private FileConfiguration customConfig = null;
    3. private File customConfigFile = null;
    4.  
    5. public void reloadCustomConfig() {
    6. if (customConfigFile == null) {
    7. customConfigFile = new File(getDataFolder(), "storage.yml");
    8. }
    9. customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
    10.  
    11. InputStream defConfigStream = this.getResource("storage.yml");
    12. if (defConfigStream != null) {
    13. YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
    14. customConfig.setDefaults(defConfig);
    15. }
    16. }
    17. public FileConfiguration getCustomConfig() {
    18. if (customConfig == null) {
    19. this.reloadCustomConfig();
    20. }
    21. return customConfig;
    22. }
    23. public void saveCustomConfig() {
    24. if (customConfig == null || customConfigFile == null) {
    25. return;
    26. }
    27. try {
    28. getCustomConfig().save(customConfigFile);
    29. } catch (IOException ex) {
    30. this.getLogger().log(Level.SEVERE, "Custom config failed to save!", ex);
    31. }
    32. }
     
  5. Offline

    Reteckz

    Nevermind, got it to work, and it's not that much actually:

    Code:
    FileConfiguration customConfig;
                customConfig = getConfig();
                File customConfigFile = new File("plugins" + File.separator + "XPStorage" + File.separator + "Storage.yml");           
                customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
                if(!customConfig.contains(name)) {
                    customConfig.set(name, 0);
                }
                try {
                    customConfig.save(customConfigFile);
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
     
Thread Status:
Not open for further replies.

Share This Page