How to add a "time sleep" to code.

Discussion in 'Plugin Development' started by mrcal17, Apr 16, 2014.

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

    mrcal17

    Hello! So recently I have created a plugin called 'shutalert'. What this plugin does is broadcasts to the server The server is restarting yada yada yada... I wanted to add a function to make the server restart it's self about 10 seconds after the command is ran... For example
    (Plugin already does this part)
    *Player*: /shutalert
    [ShutAlert]Pack your bags! It's time for a server restart!
    Make sure to restart the server player name!
    (I want the plugin too do this part also, this is the part you should read down here)
    10 seconds later:
    *Server kicks everyone for the server restart*
    *Server restarts*
    Kick message for the restart: *Server is restarting come back soon!*
    Original code:
    http://pastebin.com/KxxPzjW9

    Thank you in advance!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    Hoolean

    Hey mrcal17

    Try to edit additional messages into your original post when there have been no other posts in between, it's polite forum etiquette, as otherwise it bumps your thread up to the top and takes up space (and you're only supposed to bump every 24 hours). :)

    As for your question, take a look at the article on scheduler programming in the Bukkit wiki, you will find it mosts informative. It allows one to schedule events to take place later on without delaying the main thread, which is a nasty and avoidable side effect of just doing a Thread.sleep (so please don't do it :p).
     
  3. Offline

    mrcal17

    I'm not exactly sure where to insert some things... Or what mostly to add quite frankly.

    Also, the custom server restart message.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    Hoolean

    Well, you should make a BukkitRunnable that contains the code to shut down the server and display the message. On the command, it should be scheduled to run 10 seconds later. :)
     
  5. Offline

    mrcal17

    I'm a bit new too coding, how do I do I custom restart message?

    Also, can you post where I should put all of this in my code?
     
  6. Offline

    Garris0n

    Either set the message in the server.properties or kick all players with it.
     
  7. Offline

    mrcal17

    Bump?
     
Thread Status:
Not open for further replies.

Share This Page