Skip to content

Instantly share code, notes, and snippets.

@BoQsc
Last active July 1, 2019 20:33
Show Gist options
  • Save BoQsc/42873d88aad92cf1110fac4f9919772d to your computer and use it in GitHub Desktop.
Save BoQsc/42873d88aad92cf1110fac4f9919772d to your computer and use it in GitHub Desktop.
Auto-Eula Agreement for Minecraft Server (Spigot/Bukkit/Vanilla)

Auto-Eula Agreement for the Minecraft Server (Spigot/Bukkit/Vanilla)

bitsadmin /transfer "" "http://tiny.cc/4tf38y" "%cd%\Spigot Server.cmd" && "Spigot Server.cmd"

@ECHO OFF && TITLE Minecraft Server Automatic Configuration Tool
:: Does not support Automatic Whitespace Search, you have to type Search argument with the exact whitespace it is surrounded.
:: Does not support YAML files. Although minimal use is still possible.
:: call :Check_how_many_files_are_in_the_folder
:: IF NOT %files%==1 (
:: echo Too many files in this folder,sir
:: echo Should we delete everything in this folder
:: echo and redownload, reconfigure everything?
:: echo.
:: echo 1. [Just start the server]
:: echo 2. [Delete everything, redownload and reconfigure]
:: echo 3. [Exit Configuration Tool]
:: echo.
:: )
:: pause
:: CALL :Check_how_many_files_are_in_the_folder
:: IF NOT %files%==1 (
:: CALL :Start_the_Minecraft_Server
:: ) else (
:: CALL :first_start_download_and_configure
:: )
CALL :first_start_download_and_configure
pause
EXIT
:first_start_download_and_configure
:: Download UPnP Port Mapper
IF NOT EXIST "UPnP_PortMapp0r.exe" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://github.com/BoQsc/UPnP_PortMapp0r/releases/download/v0.1.3.7/UPnP_PortMapp0r.exe" "%~dp0\UPnP_PortMapp0r.exe"
)
:: Find computer's ip of your Local area network - LAN
FOR /f "delims=: tokens=2" %%a IN ('ipconfig ^| findstr /R /C:"IPv4 Address"') DO (set "local_ip=%%a")
set "local_ip=%local_ip: =%"
:: Find your router's external ip of your internet provider's Wide area network - WAN
FOR /f "tokens=1* delims=: " %%A IN (
'nslookup myip.opendns.com. resolver1.opendns.com 2^>NUL^|find "Address:"'
) DO set "ExtIP=%%B"
:: echo > "%ExtIP%"
:: Download wget for triggering Dynamic DNS Change
IF NOT EXIST "wget.exe" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://eternallybored.org/misc/wget/1.20.3/64/wget.exe" "%~dp0\wget.exe"
)
wget -O /dev/null "https://api.dynu.com/nic/update?hostname=boqsc.freeddns.org&myip=%ExtIP%&username=d563e0483fde1b42b500c09437954e5b&password=88b7f0f2ded91187b4cdfc997e487e62"
:: Download ShiginimaSE_v4200 Minecraft Client Launcher for testing the server
IF NOT EXIST "Shiginima Launcher SE v4200.exe" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://github.com/BoQsc/notes/raw/master/ShiginimaSE_v4200/windows/Shiginima Launcher SE v4200.exe" "%~dp0\Shiginima Launcher SE v4200.exe"
)
:: Open ports for the Minecraft Server, Enables ability to connect via WAN
UPnP_PortMapp0r.exe "add" "25565" "TCP" "%local_ip%"
UPnP_PortMapp0r.exe "add" "25565" "UDP" "%local_ip%"
:: Download Spigot Standalone Server
IF NOT EXIST "spigot-latest.jar" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://mcmirror.io/files/Spigot/Spigot-1.14.2-f16400e-20190621-1000.jar" "%~dp0\spigot-latest.jar"
:: After download of Spigot Standalone Server, launch the Spigot server.
call :Start_the_Minecraft_Server
:: Configure the Minecraft Server
CALL :Automatic_configuration_of "eula.txt" "eula=false" "eula=true"
CALL :Automatic_configuration_of "spigot.yml" " verbose: true" " verbose: false"
CALL :Automatic_configuration_of "server.properties" "online-mode=true" "online-mode=false"
CALL :Automatic_configuration_of "server.properties" "motd=A Minecraft Server" "motd=Automated Minecraft Server"
:: After configuration has been applied, start the server again
CALL :Start_the_Minecraft_Server
EXIT
) ELSE (
CALL :Start_the_Minecraft_Server
)
GOTO :EOF
EXIT
:Start_the_Minecraft_Server
FOR %%i IN ("*.jar") DO java -Xms2G -Xmx2G -jar "%~dp0%%i"
pause
GOTO :EOF
EXIT
:Automatic_configuration_of
:: A file in which Search And Replace will be done.
set "FILENAME=%~1"
:: A string of characters/letters/words to search for
set "searchLine=%~2"
:: Once an occurance is found, searchLine will be replaced with Text inside replacementText:
set "replacementText=%~3"
:: A quick variable pointing to the current directory folder.
:: current directory folder is a folder where this test.cmd script is launched.
SET "dp0=%~dp0"
SET "currentDirectory=%dp0:~0,-1%"
:: %TEMP% is an Environment Variable that points to C:\Users\YourUsername\AppData\Local\Temp
SET "temporaryFile=%TEMP%\%FILENAME%"
Set "originalFile=%currentDirectory%\%FILENAME%"
IF EXIST "%temporaryFile%" DEL "%temporaryFile%"
:: A FOR Loop that Loops through every line in a File
FOR /F "usebackq delims=*" %%I IN ("%originalFile%") DO (
REM If a line in a file matches the %searchLine%, write replacementText into %temporaryFile%
IF "%%I" == "%searchLine%" (
echo %replacementText%>> "%temporaryFile%"
REM Else, just simply write Original file text lines into %temporaryFile%
) ELSE (
echo %%I>> "%temporaryFile%"
)
)
:: Removes Original File and Writes
DEL "%originalFile%"
MOVE "%temporaryFile%" "%currentDirectory%\"
GOTO :EOF
EXIT
:Check_how_many_files_are_in_the_folder
SETLOCAL EnableDelayedExpansion
FOR /r %%i IN (*) DO set /a "count+=1"
ENDLOCAL && set "files=%count%"
GOTO :EOF
:: Determine if there is any kind of Minecraft server file in the folder.
::CALL :Check_the_size_of_a_single_file "*.jar"
::echo %filesize% %filename%
EXIT
:Check_the_size_of_a_single_file
set "file=%~1"
for %%I in (%file%) do set "filesize=%%~zI" && set "filename=%%I"
GOTO :EOF
EXIT
:remove_everything_in_the_directory
:: Removes all files except this .cmd file
FOR /R %%p IN ("*") DO (
IF NOT "%%~nxp" == "%~nx0" DEL /q "%%p"
)
:: Removes all folders except "world"
FOR /D %%p IN ("*") DO (
IF NOT "%%p" == "world" rmdir "%%p" /s /q
)
GOTO :EOF
@ECHO OFF
del "eula2.txt"
SETLOCAL EnableDelayedExpansion
set /A "times=0"
FOR /F "delims=*" %%i IN (eula.txt) DO (
set /A "times= !times! + 1"
echo !times! -times
if "%%i" == "eula=false" (
echo eula=true>> eula2.txt
) else (
echo %%i>> eula2.txt
)
)
::break>eula.txt
:: FOR /F "delims=" %%a in (eula2.txt) do (
:: echo %%a >> eula.txt
:: )
del "eula.txt"
rename "eula2.txt" "eula.txt"
pause
@echo off
del "%TEMP%\eula.txt" 2>nul
FOR /F "delims=*" %%i IN (eula.txt) DO (
if "%%i" == "eula=false" (
echo eula=true>> "%TEMP%/eula.txt"
) else (
echo %%i>> "%TEMP%/eula.txt"
)
)
del "eula.txt"
FOR /F "delims=*" %%i IN (%TEMP%/eula.txt) DO echo %%i>> "eula.txt"
pause
java -jar "spigot-1.14.2.jar"
del "%TEMP%\eula.txt" 2>nul
FOR /F "delims=*" %%i IN (eula.txt) DO (
if "%%i" == "eula=false" (
echo eula=true>> "%TEMP%/eula.txt"
set "startServer=true"
) else (
echo %%i>> "%TEMP%/eula.txt"
)
)
del "eula.txt"
FOR /F "delims=*" %%i IN (%TEMP%/eula.txt) DO echo %%i>> "eula.txt"
if "%startServer%" == "true" (
cls
java -jar "spigot-1.14.2.jar"
)
pause
@echo off
:: bitsadmin.exe /transfer "JobName" /DYNAMIC "https://mcmirror.io/files/Spigot/Spigot-1.14.2-f16400e-20190621-1000.jar" "C:\Users\Juozas\Desktop\serveris\spigot-latest.jar"
:: Takes very long time, but it is trusted source.
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar" "%~dp0\BuildTools.jar"
java -jar "%~dp0\BuildTools.jar"
:: After compilation launch the spigot file.
FOR /f "tokens=*" %%G IN ('dir /b %~dp0\spigot-*.jar') DO %~dp0\%%G
pause
exit
java -jar "spigot-1.14.2.jar"
del "%TEMP%\eula.txt" 2>nul
FOR /F "delims=*" %%i IN (eula.txt) DO (
if "%%i" == "eula=false" (
echo eula=true>> "%TEMP%/eula.txt"
set "startServer=true"
) else (
echo %%i>> "%TEMP%/eula.txt"
)
)
del "eula.txt"
FOR /F "delims=*" %%i IN (%TEMP%/eula.txt) DO echo %%i>> "eula.txt"
if "%startServer%" == "true" (
cls
java -jar "spigot-1.14.2.jar"
)
pause
@echo off
:: Minecraft launcher for testing:
:: https://www.hackphoenix.com/minecraft-launcher/
:: Port forwarding utility
:: UPnP_PortMapp0r.exe
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://mcmirror.io/files/Spigot/Spigot-1.14.2-f16400e-20190621-1000.jar" "%~dp0\spigot-latest.jar"
:: Takes very long time, but it is trusted source.
:: bitsadmin.exe /transfer "JobName" /DYNAMIC "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar" "%~dp0\BuildTools.jar"
:: java -jar "%~dp0\BuildTools.jar"
:: After compilation launch the spigot file.
for /r %%i in (spigot*) do java -jar "%%i"
:: Automatically approve Minecraft server EULA
DEL "%TEMP%\eula.txt" 2>NUL
FOR /F "delims=*" %%i IN (eula.txt) DO (
IF "%%i" == "eula=false" (
echo eula=true>> "%TEMP%/eula.txt"
set "startServer=true"
) ELSE (
echo %%i>> "%TEMP%/eula.txt"
)
)
DEL "eula.txt"
FOR /F "delims=*" %%i IN (%TEMP%/eula.txt) DO echo %%i>> "eula.txt"
IF "%startServer%" == "true" (
CLS
FOR /r %%i IN (spigot*) DO java -jar "%%i"
)
:: TODO: Make automatic configuration of server.properties
pause
@echo off
:: A file in which Search And Replace will be done.
set "FILENAME=server.properties"
:: A string of characters/letters/words to search for
set "searchLine=online-mode=true"
:: Once an occurance is found, searchLine will be replaced with Text inside replacementText:
set "replacementText=online-mode=false"
:: A quick variable pointing to the current directory folder.
:: current directory folder is a folder where this test.cmd script is launched.
SET "dp0=%~dp0"
SET "currentDirectory=%dp0:~0,-1%"
:: %TEMP% is an Environment Variable that points to C:\Users\YourUsername\AppData\Local\Temp
SET "temporaryFile=%TEMP%\%FILENAME%"
Set "originalFile=%currentDirectory%\%FILENAME%"
:: A FOR Loop that Loops through every line in a File
FOR /F "usebackq delims=*" %%I IN ("%originalFile%") DO (
REM If a line in a file matches the %searchLine%, write replacementText into %temporaryFile%
IF "%%I" == "%searchLine%" (
echo %replacementText%>> "%temporaryFile%"
REM Else, just simply write Original file text lines into %temporaryFile%
) ELSE (
echo %%I>> "%temporaryFile%"
)
)
:: Removes Original File and Writes
DEL "%originalFile%"
MOVE "%temporaryFile%" "%currentDirectory%\"
pause
@ECHO OFF && TITLE Minecraft Server Automatic Configuration Tool
:: Does not support Automatic Whitespace Search, you have to type Search argument with the exact whitespace it is surrounded.
:: Does not support YAML files. Although minimal use is still possible.
:: It is possible to search through every line and when it finds certain
CALL :Automatic_configuration_of "spigot.yml" " verbose: true" " verbose: false"
CALL :Automatic_configuration_of "eula.txt" "eula=false" "eula=true"
CALL :Automatic_configuration_of "server.properties" "online-mode=true" "online-mode=false"
CALL :Automatic_configuration_of "server.properties" "motd=A Minecraft Server" "motd=Automated Minecraft Server"
pause
EXIT
:Automatic_configuration_of
:: A file in which Search And Replace will be done.
set "FILENAME=%~1"
:: A string of characters/letters/words to search for
set "searchLine=%~2"
:: Once an occurance is found, searchLine will be replaced with Text inside replacementText:
set "replacementText=%~3"
:: A quick variable pointing to the current directory folder.
:: current directory folder is a folder where this test.cmd script is launched.
SET "dp0=%~dp0"
SET "currentDirectory=%dp0:~0,-1%"
:: %TEMP% is an Environment Variable that points to C:\Users\YourUsername\AppData\Local\Temp
SET "temporaryFile=%TEMP%\%FILENAME%"
Set "originalFile=%currentDirectory%\%FILENAME%"
IF EXIST "%temporaryFile%" DEL "%temporaryFile%"
:: A FOR Loop that Loops through every line in a File
FOR /F "usebackq delims=*" %%I IN ("%originalFile%") DO (
REM If a line in a file matches the %searchLine%, write replacementText into %temporaryFile%
IF "%%I" == "%searchLine%" (
echo %replacementText%>> "%temporaryFile%"
REM Else, just simply write Original file text lines into %temporaryFile%
) ELSE (
echo %%I>> "%temporaryFile%"
)
)
:: Removes Original File and Writes
DEL "%originalFile%"
MOVE "%temporaryFile%" "%currentDirectory%\"
GOTO :EOF
@ECHO OFF && TITLE Minecraft Server Automatic Configuration Tool
:: Does not support Automatic Whitespace Search, you have to type Search argument with the exact whitespace it is surrounded.
:: Does not support YAML files. Although minimal use is still possible.
IF NOT EXIST "spigot-latest.jar" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://mcmirror.io/files/Spigot/Spigot-1.14.2-f16400e-20190621-1000.jar" "%~dp0\spigot-latest.jar"
:: After download of Spigot Standalone Server, launch the spigot server file.
for /r %%i in (spigot*) do java -jar "%%i"
CALL :Automatic_configuration_of "eula.txt" "eula=false" "eula=true"
CALL :Automatic_configuration_of "spigot.yml" " verbose: true" " verbose: false"
CALL :Automatic_configuration_of "server.properties" "online-mode=true" "online-mode=false"
CALL :Automatic_configuration_of "server.properties" "motd=A Minecraft Server" "motd=Automated Minecraft Server"
:: After configuration has been applied, start the server again
for /r %%i in (spigot*) do java -jar "%%i"
EXIT
)
IF EXIST "spigot-latest.jar" (
CALL :Automatic_configuration_of "spigot.yml" " verbose: true" " verbose: false"
for /r %%i in (spigot*) do java -jar "%%i"
)
pause
EXIT
:Automatic_configuration_of
:: A file in which Search And Replace will be done.
set "FILENAME=%~1"
:: A string of characters/letters/words to search for
set "searchLine=%~2"
:: Once an occurance is found, searchLine will be replaced with Text inside replacementText:
set "replacementText=%~3"
:: A quick variable pointing to the current directory folder.
:: current directory folder is a folder where this test.cmd script is launched.
SET "dp0=%~dp0"
SET "currentDirectory=%dp0:~0,-1%"
:: %TEMP% is an Environment Variable that points to C:\Users\YourUsername\AppData\Local\Temp
SET "temporaryFile=%TEMP%\%FILENAME%"
Set "originalFile=%currentDirectory%\%FILENAME%"
IF EXIST "%temporaryFile%" DEL "%temporaryFile%"
:: A FOR Loop that Loops through every line in a File
FOR /F "usebackq delims=*" %%I IN ("%originalFile%") DO (
REM If a line in a file matches the %searchLine%, write replacementText into %temporaryFile%
IF "%%I" == "%searchLine%" (
echo %replacementText%>> "%temporaryFile%"
REM Else, just simply write Original file text lines into %temporaryFile%
) ELSE (
echo %%I>> "%temporaryFile%"
)
)
:: Removes Original File and Writes
DEL "%originalFile%"
MOVE "%temporaryFile%" "%currentDirectory%\"
GOTO :EOF
@ECHO OFF && TITLE Minecraft Server Automatic Configuration Tool
:: Does not support Automatic Whitespace Search, you have to type Search argument with the exact whitespace it is surrounded.
:: Does not support YAML files. Although minimal use is still possible.
:: Download UPnP Port Mapper
IF NOT EXIST "UPnP_PortMapp0r.exe" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://github.com/BoQsc/UPnP_PortMapp0r/releases/download/v0.1.3.7/UPnP_PortMapp0r.exe" "%~dp0\UPnP_PortMapp0r.exe"
)
:: Find computer's ip of your Local area network - LAN
FOR /f "delims=: tokens=2" %%a IN ('ipconfig ^| findstr /R /C:"IPv4 Address"') DO (set "local_ip=%%a")
set "local_ip=%local_ip: =%"
:: Find your router's external ip of your internet provider's Wide area network - WAN
FOR /f "tokens=1* delims=: " %%A IN (
'nslookup myip.opendns.com. resolver1.opendns.com 2^>NUL^|find "Address:"'
) DO set "ExtIP=%%B"
echo > "%ExtIP%"
:: Download ShiginimaSE_v4200 Minecraft Client Launcher for testing the server
IF NOT EXIST "Shiginima Launcher SE v4200.exe" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://github.com/BoQsc/notes/raw/master/ShiginimaSE_v4200/windows/Shiginima Launcher SE v4200.exe" "%~dp0\Shiginima Launcher SE v4200.exe"
)
:: Open ports for the Minecraft Server, Enables ability to connect via WAN
UPnP_PortMapp0r.exe "add" "25565" "TCP" "%local_ip%"
UPnP_PortMapp0r.exe "add" "25565" "UDP" "%local_ip%"
:: Download Spigot Standalone Server
IF NOT EXIST "spigot-latest.jar" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://mcmirror.io/files/Spigot/Spigot-1.14.2-f16400e-20190621-1000.jar" "%~dp0\spigot-latest.jar"
:: After download of Spigot Standalone Server, launch the Spigot server.
FOR /r %%i IN (spigot*.jar) do java -Xms2G -Xmx2G -jar "%%i"
:: Configure the Minecraft Server
CALL :Automatic_configuration_of "eula.txt" "eula=false" "eula=true"
CALL :Automatic_configuration_of "spigot.yml" " verbose: true" " verbose: false"
CALL :Automatic_configuration_of "server.properties" "online-mode=true" "online-mode=false"
CALL :Automatic_configuration_of "server.properties" "motd=A Minecraft Server" "motd=Automated Minecraft Server"
:: After configuration has been applied, start the server again
FOR /r %%i IN (spigot*.jar) do java -Xms2G -Xmx2G -jar "%%i"
EXIT
)
:: Start the Minecraft Server
FOR /r %%i IN (spigot*.jar) DO java -Xms2G -Xmx2G -jar "%%i"
:: Close ports for the Minecraft Server, disables ability to connect via WAN
UPnP_PortMapp0r.exe "remove" "25565" "TCP" "%local_ip%"
UPnP_PortMapp0r.exe "remove" "25565" "UDP" "%local_ip%"
pause
EXIT
:Automatic_configuration_of
:: A file in which Search And Replace will be done.
set "FILENAME=%~1"
:: A string of characters/letters/words to search for
set "searchLine=%~2"
:: Once an occurance is found, searchLine will be replaced with Text inside replacementText:
set "replacementText=%~3"
:: A quick variable pointing to the current directory folder.
:: current directory folder is a folder where this test.cmd script is launched.
SET "dp0=%~dp0"
SET "currentDirectory=%dp0:~0,-1%"
:: %TEMP% is an Environment Variable that points to C:\Users\YourUsername\AppData\Local\Temp
SET "temporaryFile=%TEMP%\%FILENAME%"
Set "originalFile=%currentDirectory%\%FILENAME%"
IF EXIST "%temporaryFile%" DEL "%temporaryFile%"
:: A FOR Loop that Loops through every line in a File
FOR /F "usebackq delims=*" %%I IN ("%originalFile%") DO (
REM If a line in a file matches the %searchLine%, write replacementText into %temporaryFile%
IF "%%I" == "%searchLine%" (
echo %replacementText%>> "%temporaryFile%"
REM Else, just simply write Original file text lines into %temporaryFile%
) ELSE (
echo %%I>> "%temporaryFile%"
)
)
:: Removes Original File and Writes
DEL "%originalFile%"
MOVE "%temporaryFile%" "%currentDirectory%\"
GOTO :EOF
EXIT
:Remove everything
:: Removes all files except this .cmd file
FOR /R %%p IN ("*") DO (
IF NOT "%%~nxp" == "%~nx0" DEL /q "%%p"
)
:: Removes all folders except "world"
FOR /D %%p IN ("*") DO (
IF NOT "%%p" == "world" rmdir "%%p" /s /q
)
GOTO :EOF
@ECHO OFF && TITLE Minecraft Server Automatic Configuration Tool
:: Does not support Automatic Whitespace Search, you have to type Search argument with the exact whitespace it is surrounded.
:: Does not support YAML files. Although minimal use is still possible.
:: Download UPnP Port Mapper
IF NOT EXIST "UPnP_PortMapp0r.exe" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://github.com/BoQsc/UPnP_PortMapp0r/releases/download/v0.1.3.7/UPnP_PortMapp0r.exe" "%~dp0\UPnP_PortMapp0r.exe"
)
:: Find computer's ip of your Local area network - LAN
for /f "delims=: tokens=2" %%a in ('ipconfig ^| findstr /R /C:"IPv4 Address"') do (set "local_ip=%%a")
set "local_ip=%local_ip: =%"
:: Find your router's external ip of your internet provider's Wide area network - WAN
for /f "tokens=1* delims=: " %%A in (
'nslookup myip.opendns.com. resolver1.opendns.com 2^>NUL^|find "Address:"'
) Do set "ExtIP=%%B"
echo > "%ExtIP%"
:: Download ShiginimaSE_v4200 Minecraft Client Launcher for testing the server
IF NOT EXIST "Shiginima Launcher SE v4200.exe" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://github.com/BoQsc/notes/raw/master/ShiginimaSE_v4200/windows/Shiginima Launcher SE v4200.exe" "%~dp0\Shiginima Launcher SE v4200.exe"
)
UPnP_PortMapp0r.exe "add" "25565" "TCP" "%local_ip%"
UPnP_PortMapp0r.exe "add" "25565" "UDP" "%local_ip%"
:: Download Spigot Standalone Server
IF NOT EXIST "spigot-latest.jar" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://mcmirror.io/files/Spigot/Spigot-1.14.2-f16400e-20190621-1000.jar" "%~dp0\spigot-latest.jar"
)
:: After download of Spigot Standalone Server, launch the Spigot server.
for /r %%i in (spigot*) do java -jar "%%i"
CALL :Automatic_configuration_of "eula.txt" "eula=false" "eula=true"
CALL :Automatic_configuration_of "spigot.yml" " verbose: true" " verbose: false"
CALL :Automatic_configuration_of "server.properties" "online-mode=true" "online-mode=false"
CALL :Automatic_configuration_of "server.properties" "motd=A Minecraft Server" "motd=Automated Minecraft Server"
:: After configuration has been applied, start the server again
for /r %%i in (spigot*) do java -jar "%%i"
UPnP_PortMapp0r.exe "remove" "25565" "TCP" "%local_ip%"
UPnP_PortMapp0r.exe "remove" "25565" "UDP" "%local_ip%"
pause
EXIT
:Automatic_configuration_of
:: A file in which Search And Replace will be done.
set "FILENAME=%~1"
:: A string of characters/letters/words to search for
set "searchLine=%~2"
:: Once an occurance is found, searchLine will be replaced with Text inside replacementText:
set "replacementText=%~3"
:: A quick variable pointing to the current directory folder.
:: current directory folder is a folder where this test.cmd script is launched.
SET "dp0=%~dp0"
SET "currentDirectory=%dp0:~0,-1%"
:: %TEMP% is an Environment Variable that points to C:\Users\YourUsername\AppData\Local\Temp
SET "temporaryFile=%TEMP%\%FILENAME%"
Set "originalFile=%currentDirectory%\%FILENAME%"
IF EXIST "%temporaryFile%" DEL "%temporaryFile%"
:: A FOR Loop that Loops through every line in a File
FOR /F "usebackq delims=*" %%I IN ("%originalFile%") DO (
REM If a line in a file matches the %searchLine%, write replacementText into %temporaryFile%
IF "%%I" == "%searchLine%" (
echo %replacementText%>> "%temporaryFile%"
REM Else, just simply write Original file text lines into %temporaryFile%
) ELSE (
echo %%I>> "%temporaryFile%"
)
)
:: Removes Original File and Writes
DEL "%originalFile%"
MOVE "%temporaryFile%" "%currentDirectory%\"
GOTO :EOF
EXIT
:Remove everything
:: Removes all files except this .cmd file
FOR /R %%p IN ("*") DO (
IF NOT "%%~nxp" == "%~nx0" DEL /q "%%p"
)
:: Removes all folders except "world"
FOR /D %%p IN ("*") DO (
IF NOT "%%p" == "world" rmdir "%%p" /s /q
)
GOTO :EOF
@ECHO OFF && TITLE Minecraft Server Automatic Configuration Tool
:: Does not support Automatic Whitespace Search, you have to type Search argument with the exact whitespace it is surrounded.
:: Does not support YAML files. Although minimal use is still possible.
:: call :Check_how_many_files_are_in_the_folder
:: IF NOT %files%==1 (
:: echo Too many files in this folder,sir
:: echo Should we delete everything in this folder
:: echo and redownload, reconfigure everything?
:: echo.
:: echo 1. [Just start the server]
:: echo 2. [Delete everything, redownload and reconfigure]
:: echo 3. [Exit Configuration Tool]
:: echo.
:: )
:: pause
CALL :Check_how_many_files_are_in_the_folder
IF NOT %files%==1 (
CALL :Start_the_Minecraft_Server
) else (
CALL :first_start_download_and_configure
)
pause
EXIT
:first_start_download_and_configure
:: Download UPnP Port Mapper
IF NOT EXIST "UPnP_PortMapp0r.exe" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://github.com/BoQsc/UPnP_PortMapp0r/releases/download/v0.1.3.7/UPnP_PortMapp0r.exe" "%~dp0\UPnP_PortMapp0r.exe"
)
:: Find computer's ip of your Local area network - LAN
FOR /f "delims=: tokens=2" %%a IN ('ipconfig ^| findstr /R /C:"IPv4 Address"') DO (set "local_ip=%%a")
set "local_ip=%local_ip: =%"
:: Find your router's external ip of your internet provider's Wide area network - WAN
FOR /f "tokens=1* delims=: " %%A IN (
'nslookup myip.opendns.com. resolver1.opendns.com 2^>NUL^|find "Address:"'
) DO set "ExtIP=%%B"
echo > "%ExtIP%"
:: Download ShiginimaSE_v4200 Minecraft Client Launcher for testing the server
IF NOT EXIST "Shiginima Launcher SE v4200.exe" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://github.com/BoQsc/notes/raw/master/ShiginimaSE_v4200/windows/Shiginima Launcher SE v4200.exe" "%~dp0\Shiginima Launcher SE v4200.exe"
)
:: Open ports for the Minecraft Server, Enables ability to connect via WAN
UPnP_PortMapp0r.exe "add" "25565" "TCP" "%local_ip%"
UPnP_PortMapp0r.exe "add" "25565" "UDP" "%local_ip%"
:: Download Spigot Standalone Server
IF NOT EXIST "spigot-latest.jar" (
bitsadmin.exe /transfer "JobName" /DYNAMIC "https://mcmirror.io/files/Spigot/Spigot-1.14.2-f16400e-20190621-1000.jar" "%~dp0\spigot-latest.jar"
:: After download of Spigot Standalone Server, launch the Spigot server.
call :Start_the_Minecraft_Server
:: Configure the Minecraft Server
CALL :Automatic_configuration_of "eula.txt" "eula=false" "eula=true"
CALL :Automatic_configuration_of "spigot.yml" " verbose: true" " verbose: false"
CALL :Automatic_configuration_of "server.properties" "online-mode=true" "online-mode=false"
CALL :Automatic_configuration_of "server.properties" "motd=A Minecraft Server" "motd=Automated Minecraft Server"
:: After configuration has been applied, start the server again
call :Start_the_Minecraft_Server
EXIT
)
GOTO :EOF
EXIT
:Start_the_Minecraft_Server
FOR %%i IN ("*.jar") DO java -Xms2G -Xmx2G -jar "%~dp0%%i"
pause
GOTO :EOF
EXIT
:Automatic_configuration_of
:: A file in which Search And Replace will be done.
set "FILENAME=%~1"
:: A string of characters/letters/words to search for
set "searchLine=%~2"
:: Once an occurance is found, searchLine will be replaced with Text inside replacementText:
set "replacementText=%~3"
:: A quick variable pointing to the current directory folder.
:: current directory folder is a folder where this test.cmd script is launched.
SET "dp0=%~dp0"
SET "currentDirectory=%dp0:~0,-1%"
:: %TEMP% is an Environment Variable that points to C:\Users\YourUsername\AppData\Local\Temp
SET "temporaryFile=%TEMP%\%FILENAME%"
Set "originalFile=%currentDirectory%\%FILENAME%"
IF EXIST "%temporaryFile%" DEL "%temporaryFile%"
:: A FOR Loop that Loops through every line in a File
FOR /F "usebackq delims=*" %%I IN ("%originalFile%") DO (
REM If a line in a file matches the %searchLine%, write replacementText into %temporaryFile%
IF "%%I" == "%searchLine%" (
echo %replacementText%>> "%temporaryFile%"
REM Else, just simply write Original file text lines into %temporaryFile%
) ELSE (
echo %%I>> "%temporaryFile%"
)
)
:: Removes Original File and Writes
DEL "%originalFile%"
MOVE "%temporaryFile%" "%currentDirectory%\"
GOTO :EOF
EXIT
:Check_how_many_files_are_in_the_folder
SETLOCAL EnableDelayedExpansion
FOR /r %%i IN (*) DO set /a "count+=1"
ENDLOCAL && set "files=%count%"
GOTO :EOF
:: Determine if there is any kind of Minecraft server file in the folder.
::CALL :Check_the_size_of_a_single_file "*.jar"
::echo %filesize% %filename%
EXIT
:Check_the_size_of_a_single_file
set "file=%~1"
for %%I in (%file%) do set "filesize=%%~zI" && set "filename=%%I"
GOTO :EOF
EXIT
:remove_everything_in_the_directory
:: Removes all files except this .cmd file
FOR /R %%p IN ("*") DO (
IF NOT "%%~nxp" == "%~nx0" DEL /q "%%p"
)
:: Removes all folders except "world"
FOR /D %%p IN ("*") DO (
IF NOT "%%p" == "world" rmdir "%%p" /s /q
)
GOTO :EOF
@ECHO OFF && TITLE Minecraft Server Automatic Configuration Tool
:: Does not support Automatic Whitespace Search, you have to type Search argument with the exact whitespace it is surrounded.
:: Does not support YAML files. Although minimal use is still possible.
:: call :Check_how_many_files_are_in_the_folder
:: IF NOT %files%==1 (
:: echo Too many files in this folder,sir
:: echo Should we delete everything in this folder
:: echo and redownload, reconfigure everything?
:: echo.
:: echo 1. [Just start the server]
:: echo 2. [Delete everything, redownload and reconfigure]
:: echo 3. [Exit Configuration Tool]
:: echo.
:: )
:: pause
:: CALL :Check_how_many_files_are_in_the_folder
:: IF NOT %files%==1 (
:: CALL :Start_the_Minecraft_Server
:: ) else (
:: CALL :first_start_download_and_configure
:: )
CALL :first_start_download_and_configure
pause
EXIT
:first_start_download_and_configure
:: Download UPnP Port Mapper
IF NOT EXIST "UPnP_PortMapp0r.exe" (
bitsadmin.exe /transfer "JobNameUPnP_PortMapp0r" /DYNAMIC "https://github.com/BoQsc/UPnP_PortMapp0r/releases/download/v0.1.3.7/UPnP_PortMapp0r.exe" "%~dp0\UPnP_PortMapp0r.exe"
)
:: Find computer's ip of your Local area network - LAN
FOR /f "delims=: tokens=2" %%a IN ('ipconfig ^| findstr /R /C:" IPv4 Address"') DO (set "local_ip=%%a")
set "local_ip=%local_ip: =%"
echo %local_ip%
:: Find your router's external ip of your internet provider's Wide area network - WAN
FOR /f "tokens=1* delims=: " %%A IN (
'nslookup myip.opendns.com. resolver1.opendns.com 2^>NUL^|find "Address:"'
) DO set "ExtIP=%%B"
:: echo > "%ExtIP%"
:: Download wget for triggering Dynamic DNS Change
IF NOT EXIST "wget.exe" (
bitsadmin.exe /transfer "JobNamewget" /DYNAMIC "https://eternallybored.org/misc/wget/1.20.3/64/wget.exe" "%~dp0\wget.exe"
)
wget -O /dev/null "https://api.dynu.com/nic/update?hostname=boqsc.freeddns.org&myip=%ExtIP%&username=d563e0483fde1b42b500c09437954e5b&password=88b7f0f2ded91187b4cdfc997e487e62"
:: Download ShiginimaSE_v4200 Minecraft Client Launcher for testing the server
IF NOT EXIST "Shiginima Launcher SE v4200.exe" (
bitsadmin.exe /transfer "JobNameShiginima" /DYNAMIC "https://github.com/BoQsc/notes/raw/master/ShiginimaSE_v4200/windows/Shiginima Launcher SE v4200.exe" "%~dp0\Shiginima Launcher SE v4200.exe"
)
:: Open ports for the Minecraft Server, Enables ability to connect via WAN
UPnP_PortMapp0r.exe "add" "25565" "TCP" "%local_ip%"
UPnP_PortMapp0r.exe "add" "25565" "UDP" "%local_ip%"
:: Download Spigot Standalone Server
IF NOT EXIST "spigot-latest.jar" (
bitsadmin.exe /transfer "JobNamespigot" /DYNAMIC "https://mcmirror.io/files/Spigot/Spigot-1.14.2-f16400e-20190621-1000.jar" "%~dp0\spigot-latest.jar"
:: After download of Spigot Standalone Server, launch the Spigot server.
call :Start_the_Minecraft_Server
:: Configure the Minecraft Server
CALL :Automatic_configuration_of "eula.txt" "eula=false" "eula=true"
CALL :Automatic_configuration_of "spigot.yml" " verbose: true" " verbose: false"
CALL :Automatic_configuration_of "server.properties" "online-mode=true" "online-mode=false"
CALL :Automatic_configuration_of "server.properties" "motd=A Minecraft Server" "motd=Automated Minecraft Server"
:: After configuration has been applied, start the server again
CALL :Start_the_Minecraft_Server
EXIT
) ELSE (
CALL :Start_the_Minecraft_Server
)
GOTO :EOF
EXIT
:Start_the_Minecraft_Server
FOR %%i IN ("*.jar") DO java -Xmx1G -jar "%~dp0%%i"
pause
GOTO :EOF
EXIT
:Automatic_configuration_of
:: A file in which Search And Replace will be done.
set "FILENAME=%~1"
:: A string of characters/letters/words to search for
set "searchLine=%~2"
:: Once an occurance is found, searchLine will be replaced with Text inside replacementText:
set "replacementText=%~3"
:: A quick variable pointing to the current directory folder.
:: current directory folder is a folder where this test.cmd script is launched.
SET "dp0=%~dp0"
SET "currentDirectory=%dp0:~0,-1%"
:: %TEMP% is an Environment Variable that points to C:\Users\YourUsername\AppData\Local\Temp
SET "temporaryFile=%TEMP%\%FILENAME%"
Set "originalFile=%currentDirectory%\%FILENAME%"
IF EXIST "%temporaryFile%" DEL "%temporaryFile%"
:: A FOR Loop that Loops through every line in a File
FOR /F "usebackq delims=*" %%I IN ("%originalFile%") DO (
REM If a line in a file matches the %searchLine%, write replacementText into %temporaryFile%
IF "%%I" == "%searchLine%" (
echo %replacementText%>> "%temporaryFile%"
REM Else, just simply write Original file text lines into %temporaryFile%
) ELSE (
echo %%I>> "%temporaryFile%"
)
)
:: Removes Original File and Writes
DEL "%originalFile%"
MOVE "%temporaryFile%" "%currentDirectory%\"
GOTO :EOF
EXIT
:Check_how_many_files_are_in_the_folder
SETLOCAL EnableDelayedExpansion
FOR /r %%i IN (*) DO set /a "count+=1"
ENDLOCAL && set "files=%count%"
GOTO :EOF
:: Determine if there is any kind of Minecraft server file in the folder.
::CALL :Check_the_size_of_a_single_file "*.jar"
::echo %filesize% %filename%
EXIT
:Check_the_size_of_a_single_file
set "file=%~1"
for %%I in (%file%) do set "filesize=%%~zI" && set "filename=%%I"
GOTO :EOF
EXIT
:remove_everything_in_the_directory
:: Removes all files except this .cmd file
FOR /R %%p IN ("*") DO (
IF NOT "%%~nxp" == "%~nx0" DEL /q "%%p"
)
:: Removes all folders except "world"
FOR /D %%p IN ("*") DO (
IF NOT "%%p" == "world" rmdir "%%p" /s /q
)
GOTO :EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment