Custom config problem

Discussion in 'Plugin Development' started by ChazSchmidt, May 25, 2014.

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

    ChazSchmidt

    Code:java
    1. public void finalizeList() {
    2. sChestLoc.clear();
    3. sChestLoc = sLocConstruct(chestLoc);
    4. chestsConfig.getStringList("sChestLoc").clear();
    5. chestsConfig.set("sChestLoc", sChestLoc);
    6. }
    7.  
    8. // File chestsFile = new File(getDataFolder(), "chests.yml");
    9. // FileConfiguration chestsConfig = YamlConfiguration
    10. // .loadConfiguration(chestsFile);
    11.  
    12. File chestsFile;
    13. FileConfiguration chestsConfig;
    14.  
    15. private void firstRun() throws Exception {
    16. if (!chestsFile.exists()) {
    17. chestsFile.getParentFile().mkdirs();
    18. copy(this.getResource("chests.yml"), chestsFile);
    19. }
    20. }
    21.  
    22. private void copy(InputStream in, File file) {
    23. try {
    24. OutputStream out = new FileOutputStream(file);
    25. byte[] buf = new byte[1024];
    26. int len;
    27. while ((len = in.read(buf)) > 0) {
    28. out.write(buf, 0, len);
    29. }
    30. out.close();
    31. in.close();
    32. } catch (Exception e) {
    33. e.printStackTrace();
    34. }
    35. }
    36.  
    37. public void saveYamls() {
    38. try {
    39. chestsConfig.save(chestsFile);
    40. } catch (IOException e) {
    41. e.printStackTrace();
    42. }
    43. }
    44.  
    45. public void loadYamls() {
    46. try {
    47. chestsConfig.save(chestsFile);
    48. } catch (Exception e) {
    49. e.printStackTrace();
    50. }
    51. }
    52.  
    53. @Override
    54. public void onDisable() {
    55. finalizeList();
    56. saveConfig();
    57. saveYamls();
    58. log.info(pdfFile.getName() + " has been disabled!");
    59. }
    60.  
    61. @Override
    62. public void onEnable() {
    63. chestsFile = new File(getDataFolder(), "chests.yml");
    64.  
    65. try {
    66. firstRun();
    67. } catch (Exception e) {
    68. e.printStackTrace();
    69. }
    70.  
    71. chestsConfig = new YamlConfiguration();
    72. loadYamls();
    73.  
    74. loadConfiguration();
    75.  
    76. log.info(pdfFile.getName() + " Version " + pdfFile.getVersion()
    77. + " has been enabled!");
    78. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    79.  
    80. if (getConfig().getBoolean("metrics") == true) {
    81. try {
    82. Metrics metrics = new Metrics(this);
    83. metrics.start();
    84. this.log.info("[ChestLoot] Metrics Activated!");
    85. } catch (IOException e) {
    86. // Failed to submit the stats :-(
    87. }
    88. }


    Been having trouble with loading the chests.yml I have in my .jar. I'll test it with a clean folder where there are no files and then chests.yml is created but is blank
     
  2. Offline

    mrkirby153

  3. Offline

    ChazSchmidt

    mrkirby153 Trust me, unlike most people I've googled the hell out of this and read that and like 10 other guides. I wouldn't be posting here unless I was at wit's end.
     
Thread Status:
Not open for further replies.

Share This Page