How to make a plugin reload command

Discussion in 'Plugin Development' started by sammyg7241, May 19, 2015.

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

    sammyg7241

    Hi, I am wondering if anybody knows how to make a reload command to reload the config file. Thanks!
     
  2. Offline

    Koobaczech

    This is the reload syntax. Put that inside a block { } or a method
    Code:
    config.reloadConfig();
     
    Last edited: May 19, 2015
  3. Save your config and than load it again.
    Or just load it again.
     
  4. Offline

    sammyg7241

    This doesn't seem to work.
     
  5. @sammyg7241
    It isn't as easy as just reloading the config, you're gonna have to do most of the loading you did in your onEnable method, also make sure you call JavaPlugin#reloadConfig()
     
  6. Offline

    RingOfStorms

    A reload can mean different things in different plugins. For the most part you should just have to re-load your configuration from the file system and then recache any cached variables that you've stored in memory.

    Also, I don't see any benefit to saving right after loading from the filesystem, it serves no purpose other than taking a long time and burning CPU saving to the disk.
     
  7. Offline

    Koobaczech

    @RingOfStormsA reload can mean different things in different plugins, but he just wants to reload config file.
    Edit. Removed some stuff

    @sammyg7241 Can you show me a snippet of code you are using to handle your configs?

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: May 19, 2015
  8. @Koobaczech No let me tell you what you're doing. reloadConfig() takes the data in the configuration file from the disk. saveConfig() takes the configuration data in the memory, and then writes it to the file. Saving it after just loading it is basically copying the file and pasting it over itself - it is simply impossible for the configuration in memory to be different, except in the case that the user managed to make some changes to the file in the milliseconds between method calls. And if they did manage that, then congratulations, you've just eliminated their changes :p

    @RingOfStorms has this right. There's literally no reason to save a config after reloading it.
     
  9. Offline

    CoolGamerXD

    I always use reloadConfig();
    Code:
     this.plugin.reloadConfig();
     
  10. Offline

    Koobaczech

    Wow!!! Im absolutely perplexed as how i never saw that. Thank you so much
     
  11. saveConfig() works for me :p
     
  12. Nice one, use reloadConfig();
     
    Last edited: May 19, 2015
  13. No..
     
  14. hahaha good luck using "saveConfig()" for reload the config :)
     
  15. Thanks :)
     
  16. Offline

    xMrPoi

    Save the config then reload it.
     
  17. Offline

    RingOfStorms

    That does exactly the opposite of what "reload" is for. You use a reload command in order to reload new settings frmo the disk, if you save before loading then you've overwritten all the user's changes. Saving should be held in its own command.
     
    Konato_K and timtower like this.
  18. Offline

    xMrPoi

    oh oops :p. I wrote that without checking my plugin. You're right! Haha
     
  19. Offline

    MrFrozen

Thread Status:
Not open for further replies.

Share This Page