Looking for onReload and onBootup

Discussion in 'Plugin Development' started by spy85, Mar 4, 2014.

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

    spy85

    onEnable is essential and useful but I need a method that is only called on server boot up and one that is called only on reloads. How can I get 2 methods that differ in this way?


    Thanks!
     
  2. Offline

    Alshain01

    There is no immediate way to do this, but you can monitor the ServerCommandEvent for a reload command. Write a boolean flag somewhere in YAML or whatever you prefer to indicate a reload rather than startup. Then read the flag as your plugin loads (and reset it to false).

    Be warned, this is not a guarantee. The server could be killed during a reload before your plugin loads. Then it would be a startup but think it was a reload.
     
  3. Offline

    Garris0n

    What exactly are you trying to do with such methods?
     
  4. Offline

    Barinade

    onEnable runs on reload, the current instance of your plugin is 'quarantined' on reload, a new instance is created. If you're trying to "reset variables" or something on reload, it all resets already.

    I highly recommend avoiding reload. Try a server stop with batch goto.
    Code:
    :top
    java -jar server.jar
    goto top
    Replace the java line with whatever command line you use to run your server. When the server is stopped this will automatically reboot it.
     
  5. Offline

    spy85

    I know reloading is best avoided but I am working on a public plugin and the plugin needs to be prepared to handle reloads because people will do them.
     
  6. Offline

    Barinade

    onDisable - save data you need to keep
    onEnable - load said data
     
  7. Offline

    RawCode

    just ignore.

    only very "not smart" server admins use reloading feature, you will be fine without them.
     
Thread Status:
Not open for further replies.

Share This Page