[SOLVED..]Custom config failing to writte into the file.

Discussion in 'Plugin Development' started by MrMag518, Jan 18, 2012.

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

    MrMag518

    Ok, I am getting some issus when trying to create this custom config, I think I know the issue, but I'm not so sure about it. I will show the parts of the code below:

    In the main class:
    Code:java
    1.  
    2. public void loadBlacklist() {
    3. config.addDefault("this.is.a.complete.test", false);
    4. this.getBlacklist().options().copyDefaults(true);
    5. saveBlacklist();
    6. log.info("Loaded blacklist file.");
    7. }
    8.  
    9. public void reloadBlacklist() {
    10. if (blacklistFile == null) {
    11. blacklistFile = new File(getDataFolder(), "blacklist.yml");
    12. }
    13. blacklist = YamlConfiguration.loadConfiguration(blacklistFile);
    14.  
    15. // Look for defaults in the jar
    16. InputStream defConfigStream = getResource("blacklist.yml");
    17. if (defConfigStream != null) {
    18. YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
    19. blacklist.setDefaults(defConfig);
    20. }
    21. }
    22.  
    23. public FileConfiguration getBlacklist() {
    24. if (blacklist == null) {
    25. reloadBlacklist();
    26. }
    27. return blacklist;
    28. }
    29.  
    30. public void saveBlacklist() {
    31. if (blacklist == null || blacklistFile == null) {
    32. return;
    33. }
    34. try {
    35. blacklist.save(blacklistFile);
    36. } catch (IOException ex) {
    37. Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Error saving blacklist to " + blacklistFile, ex);
    38. }
    39. }


    the main class, onEnable:

    Code:java
    1. blacklist = this.getBlacklist();
    2. loadBlacklist();


    And the statements/declarations in the main class:

    Code:java
    1. public FileConfiguration blacklist = null;
    2. public File blacklistFile = null;


    I think I know what's wrong, but I'm not sure...
    Anyone?

    Wait, DAMN
    I said in the custom config, config.addDefault(...);
    Should be: blacklist.addDefault(...);
    ...
    easy confusion..

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

Share This Page