Jimothy Bringus
Jimothy Bringus

Reputation: 21

Trying to auto restart minecraft server every 3 hours

I used the code provided in the best answer in this thread: Need auto-restart script in batch for minecraft server

However, I'm not sure when the choice function is supposed to run.

Furthermore, I'd rather not have a choice option. I'd like the server just to give a 60 second heads up that it's going to restart and then execute the restart.

Any help would be appreciated!

Here's the code from the previous answer:

@echo off
title minecraft-server-1.8.3
color 0A
prompt [server]:
cls

:start
echo loading server...
java -Xms3G -Xmx3G -jar minecraft_server.1.8.3.jar nogui
cls

:choice
set /P a=do you want to restart[Y/N]?
if /I "%a%" EQU "Y" goto :restart
if /I "%a%" EQU "N" goto :stop
goto :choice


:restart
cls
echo server will restart
TIMEOUT /T 5
cls
goto :start

:stop

cls
echo closing server
TIMEOUT /T 5
exit

Upvotes: 2

Views: 9583

Answers (1)

IoCalisto
IoCalisto

Reputation: 53

Welcome to stack overflow. As @Mofi mentioned in a comment, you can use TIMEOUT to create wait statement The script you might want would look something like this:

:start
echo loading server...
java -Xms3G -Xmx3G -jar minecraft_server.1.8.3.jar nogui
cls

REM I recommend NOT using TIMEOUT /T for the main wait, this way you can skip it and initiate a restart immediately 

TIMEOUT 10720

REM 3 hours minus 60 seconds to allow for 60 second restart notification

cls
echo server will restart
TIMEOUT /T 60
cls
goto :start


(Since you seem to be somewhat new to batch, REM is used to comment out lines)

To answer your question surrounding why the :choice section is a thing: It is initiated after the :start section, allowing you to either (Y) restart, or (N) stop the server

Upvotes: 0

Related Questions