Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automatic Server Restart (MCL handler)
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
@2called-chaos

This comment has been minimized.

Copy link
Owner Author

2called-chaos commented Oct 13, 2014

announce_server_restart is coming from here https://github.com/2called-chaos/mcl/blob/master/lib/mcl/handler/helper.rb#L38

why 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.