Changes to config get reset on reload

Discussion in 'Plugin Development' started by caldabeast, Jun 5, 2012.

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

    caldabeast

    Im currently wrapping up coding of my plugin olyChatSuite, but I have fun across a few issues.
    The most notable that I can't figure out how to fix is that, whenever I reload the server after changing the config in any way, the changes get reverted. This makes it so that any changes to the config must occur while the server is offline. How can I fix this?

    Also, I found a thread recently that showed how to reload your plugin. It suggested using "this.reload()" in the main class file. I did that, and it threw a gigantic stack trace in which it gave an error to that line of code nearly a hundred times. I put it in a try block, but it still gave a stack trace instead of reverting to the catch.

    Any help with these two problems would be extremely appreciated.

    If you need to see any of my source, I have the following GitHub link which has just been commited and it now completely up to date.
    http://dft.ba/-olyChatSuiteOnGitHub
     
  2. I had the same issue when I used defaults for the config.
    I changed my code to something like this:
    Code:
    this.getConfig().set(<path>, this.getConfig().get(<path>, <defaultvalue>));
    I don't know if the defaults are actually the problem, but this solved at least my issue.
     
  3. Offline

    caldabeast

    I actually solved this problem by myself after taking a quick break. Thanks for your help anyway!
     
  4. How did you solve this? I'm curious since my method doesn't seem to be that 'elegant'.
     
  5. Offline

    caldabeast

    I used the following snippits of code to solve both problems:

    Code:java
    1.  
    2. //in the onEnable()
    3. public void onEnable() {
    4. -----unimportaint snip----
    5. config = getConfig();
    6. loadConfig();
    7. }
    8.  
    9.  
    10. //my loadConfig() method
    11. public void loadConfig(){
    12. try{
    13. config.load(configFile);
    14. }catch(Exception e){
    15. System.out.println("==================");
    16. e.printStackTrace();
    17. System.out.println("==================");
    18. }
    19. }
    20.  
    21. //in the onCommand() method
    22. if(cl.equalsIgnoreCase("chatreload") || cl.equalsIgnoreCase("crl")){
    23. loadConfig();
    24. s.sendMessage(ChatColor.GRAY + "olyChatSuite has been reloaded.");
    25. }
     
Thread Status:
Not open for further replies.

Share This Page