Created
October 13, 2014 15:56
-
-
Save 2called-chaos/25b097fe9e805699a0e7 to your computer and use it in GitHub Desktop.
Automatic Server Restart (MCL handler)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mcl | |
Mcl.reloadable(:AutomaticServerRestart) | |
class AutomaticServerRestart < Handler | |
def setup | |
@stop_at = 1.hour.from_now | |
end | |
def tick! | |
# only check every 240 MCL ticks == 60 seconds | |
# wouldn't really hurt to check every tick though | |
if app.eman.tick % 240 == 0 | |
if @stop_at && @stop_at.past? | |
@stop_at = nil # don't call restart_server multiple times | |
restart_server | |
end | |
end | |
end | |
def restart_server | |
announce_server_restart | |
sleep 3 # also blocks MCL | |
# you could also invoke stop but be aware of | |
# https://bugs.mojang.com/browse/MC-63802 | |
if true | |
$mcl_reboot = true | |
else | |
$mcl.server.invoke("/stop") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
announce_server_restart
is coming from here https://github.com/2called-chaos/mcl/blob/master/lib/mcl/handler/helper.rb#L38why those methods get called: https://github.com/2called-chaos/mcl/blob/master/lib/mcl/handler/api.rb
why don't we have to reset
@stop_at
? Because MCL reboots when the server exits and therefore initializes all handlers again.