1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How to handle server reload properly

Discussion in 'Development' started by Thunder33345, Jan 2, 2017.

  1. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    As the title self described,
    how to handle server /reload properly by reloading configs and so on...?
    i dont seem to find onReload function or any related event listeners?
    i remember sofe mentioning how some developers did a poor implementation or something related to reload so it is better to restart, and since this section is added so i might as well ask it here

    I guess i should do a Xpost to dev section as if this section is as good as posting on pocketmine.net
     
    Last edited: Jan 2, 2017
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Reloading unloads the plugin normally. You should just free all references to everything else on unload, destroy all tasks, destroy all your objects (and save your data beforhand). then you are very likely to not run into problems, because the reload just acts like a normal plugin unload and then loading it again.
     
    applqpak likes this.
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    Finally someone, by that you meant...
    to unset all properties under onDisable?
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    no, to free all references and save data. unsetting everything will also help. Most important is destroying your objects. (unset/free all references to them)
     
    applqpak likes this.
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    During the reload phase, the server doesn't stop. The plugin run through its onDisable function where it's supposed to destroy all objects and save any data needed to the config or a database.
     
    applqpak likes this.
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Reloading is to unload the plugin and then load it again. Most things will be automatically reset, and iirc the plugin instance is also garbaged (a new one will be instantiated), so you don't need to unset anything explicitly. However the Server instance isn't reloaded. Basically, if you don't use any static class properties, and if you don't register anything to the Server that isn't disabled by plugin unload (basically, anything you register other than event handlers, commands and plugin tasks), you don't have to worry about it. Sorry I think I wrote something wrong in the other post - most plugins support server reload, just that merely using the reloadConfig() function doesn't reload the config data known by the plugin.
     
    applqpak likes this.
  7. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.