Skip to content

Instantly share code, notes, and snippets.

@timvisee
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timvisee/c1c23ef009329de7c2b5 to your computer and use it in GitHub Desktop.
Save timvisee/c1c23ef009329de7c2b5 to your computer and use it in GitHub Desktop.
Minecraft Server Runner
REM Set some constants
set appName=Minecraft Server Runner
set appVersionCode=2
set appVersion=0.1.1
REM Initialize
call:init
REM Build the window
call:buildWindow
REM Search and start the server JAR
call:searchServerJar
call:acceptEULA
call:startServer
call:setTitle "%serverType% server Stopped!"
call:serverStopped
call:printFooter
PAUSE > NUL
exit
:init
@echo off
cls
goto:eof
:buildWindow
call:setTitle
call:printHeader
goto:eof
REM Function: Set window title
:setTitle
if "%~1"=="" (
title %appName% v%appVersion% by Tim Visee
) else (
title %appName% v%appVersion% by Tim Visee - %~1
)
goto:eof
:printHeader
@echo.
@echo. ^+--------------------------------------------------------------------------^+
@echo. ^|
@echo. ^| %appName% v%appVersion% by Tim Visee
@echo. ^| Copyright (c) Tim Visee 2014. All Rights Reserved.
@echo. ^|
@echo. ^+--------------------------------------------------------------------------^+
goto:eof
:searchServerJar
call:setTitle "Preparing..."
@echo. ^|
@echo. ^| Preparing...
@echo. ^| Searching for CraftBukkit server JAR file...
FOR %%F IN (craftbukkit*.jar) DO (
set filename=%%F
set serverType=CraftBukkit
goto searchFinished
)
@echo. ^| Couldn't find CraftBukkit server JAR file.
@echo. ^| Searching for Minecraft server JAR file...
FOR %%F IN (minecraft_server*.jar) DO (
set filename=%%F
set serverType=Minecraft
goto searchFinished
)
@echo. ^| Couldn't find Minecraft server JAR file.
@echo. ^| Searching for custom server JAR file...
FOR %%F IN (*.jar) DO (
set filename=%%F
set serverType=custom
goto searchFinished
)
:searchFinished
if "%filename%"=="" (
@echo. ^| Couldn't find any server JAR file, unable to start server!
@echo. ^| Failed to prepare!
@echo. ^|
call:setTitle "Failed!"
call:printFooter
PAUSE > NUL
exit
)
@echo. ^| Found %serverType% server JAR: %filename%
@echo. ^| Successfully prepared!
call:setTitle
goto:eof
:acceptEULA
REM Automatically accept the EULA agreement, or create the file if it doesn't exist.
@echo. ^|
@echo. ^| Automatically accepting the EULA agreement...
@echo. ^| Feature temporarily disabled, please accept EULA by hand.
goto:eof
REM Make sure the EULA file exists already!
if exist eula.txt (
@echo off & setlocal EnableDelayedExpansion
set row=
for /F "delims=" %%j in (./eula.txt) do (
if defined row echo.!row!>> ./eula_accepted.txt
set row=%%j
)
@echo eula=true >> ./eula_accepted.txt
del eula.txt
ren eula_accepted.txt eula.txt
@echo. ^| EULA accepted!
) else (
@echo. ^| Unable to automatically accept the EULA agreement, agreement not available
)
goto:eof
:startServer
call:setTitle "Starting %serverType% server..."
@echo. ^|
@echo. ^| Starting %serverType% server with 2GB RAM...
@echo. ^| Use the 'stop' command to properly shutdown the server.
@echo. ^|
@echo. ^+--------------------------------------------------------------------------^+
@echo.
call:setTitle "Running %serverType% server..."
java -Xmx2048M -jar "%filename%" -o true nogui
goto:eof
:serverStopped
@echo.
@echo.
@echo. ^+--------------------------------------------------------------------------^+
@echo. ^|
@echo. ^| The %serverType% server has been stopped!
goto:eof
:printFooter
@echo. ^| Press any key to close this window...
@echo. ^|
@echo. ^+--------------------------------------------------------------------------^+
@echo. ^|
@echo. ^| %appName% v%appVersion% by Tim Visee
@echo. ^| Copyright (c) Tim Visee 2014. All Rights Reserved.
@echo. ^|
@echo. ^+--------------------------------------------------------------------------^+
goto:eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment