1+ @ echo off
2+ title Checking dependencies...
3+ set scriptversion = 0.1
4+
5+ REM Check if the scripts utility folder exists, if not, create it.
6+ if not exist " config" (
7+ mkdir config
8+ echo Created config folder
9+ )
10+
11+ REM Check if script config file exists, if not, go to create it.
12+ if not exist .\config\StartupScript.conf (
13+ goto initialSetup
14+ ) else (
15+ goto initiateServer
16+ )
17+
18+ REM Set restart counter variables
19+ set " restartCount = 0"
20+ set " restartTime = No restarts yet..."
21+
22+
23+
24+ :initiateServer
25+ title Initiating server...
26+ REM Check EULA exists, if not, go to create it (and accept it)
27+ if not exist " eula.txt" (
28+ goto eula
29+ )
30+
31+ REM Reads the startup config file and fetches the variables from the config file and ignores "#" comments
32+ for /f " tokens=*" %%i in ('type .\config\StartupScript.conf ^ | findstr /V " ^#" ') do (
33+ for /f " tokens=1,2 delims==" %%a in (" %%i " ) do (
34+ set " %%a = %%b "
35+ )
36+ )
37+
38+ REM Display config info on startup
39+ echo [1;32m.............................................[0m
40+ echo [1;4;33mServer[0m: [33m%serverName% [0m
41+ echo [1;4;33mInitial RAM[0m: [33m%iniRam% [0;1m^ | [1;4;33mMaximum RAM[0m: [33m%maxRam% [0m
42+ echo [1;4;33mAuto-restart[0m: [33m%autoRestart% [0m
43+ echo [1;4;33mServer GUI[0m: [33m%GUI% [0m
44+ echo [1;32m.............................................[0m
45+
46+ REM Set RAM values
47+ set RAM = -Xmx%maxRam% -Xms%iniRam%
48+ REM Set GUI value
49+ if " %GUI% " == " true" set GUI =
50+ if " %GUI% " == " false" set GUI = --nogui
51+ REM Check for JVM args file
52+ if exist " .\config\jvm_args.txt" (
53+ echo [32mJVM args file found.[0m
54+ set args = @.\config\jvm_args.txt
55+ ) else (
56+ echo [31mJVM args file not found![0m
57+ (
58+ echo -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+AlwaysActAsServerClassMachine -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:NmethodSweepActivity=1 -XX:ReservedCodeCacheSize=400M -XX:NonNMethodCodeHeapSize=12M -XX:ProfiledCodeHeapSize=194M -XX:NonProfiledCodeHeapSize=194M -XX:-DontCompileHugeMethods -XX:MaxNodeLimit=240000 -XX:NodeLimitFudgeFactor=8000 -XX:+UseVectorCmov -XX:+PerfDisableSharedMem -XX:+UseFastUnorderedTimeStamps -XX:+UseCriticalJavaThreadPriority -XX:ThreadPriorityPolicy=1 -XX:AllocatePrefetchStyle=3 -XX:+UseG1GC -XX:MaxGCPauseMillis=130 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=28 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=20 -XX:G1MixedGCCountTarget=3 -XX:InitiatingHeapOccupancyPercent=10 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=0 -XX:SurvivorRatio=32 -XX:MaxTenuringThreshold=1 -XX:G1SATBBufferEnqueueingThresholdPercent=30 -XX:G1ConcMarkStepDurationMillis=5 -XX:G1ConcRefinementServiceIntervalMillis=150 -XX:G1ConcRSHotCardLimit=16
59+ set args = @.\config\jvm_args.txt
60+ ) > .\config\jvm_args.txt
61+ echo [32mJVM args file created successfully.[0m
62+ )
63+ REM Check auto-restart value
64+ if " %autoRestart% " == " true" (
65+ GOTO runRestart
66+ ) ELSE (
67+ GOTO runNoRestart
68+ )
69+
70+ :runRestart
71+ title %Title% ^ | Restarted: %restartCount% times
72+ java %RAM% %args% -jar %serverName% %GUI%
73+ echo .
74+ echo .
75+ set /A restartCount += 1
76+ set " restartTime = %TIME% , %DATE% "
77+ echo Server has closed or crashed...restarting now...
78+ echo Server has restarted %restartCount% times. Last restart: %restartTime%
79+ goto initiateServer
80+
81+ :runNoRestart
82+ title %Title%
83+ java %RAM% %args% -jar %serverName% %GUI%
84+ echo .
85+ echo .
86+ echo Server has closed or crashed.
87+ CHOICE /N /C YN /M " Do you want to restart the server? (Y/N): "
88+ if %errorlevel% == 1 goto initiateServer
89+ if %errorlevel% == 2 (
90+ echo You chose not to restart the server.
91+ echo Press any key to exit.
92+ pause > nul
93+ exit /b
94+ )
95+
96+
97+
98+
99+ :initialSetup
100+ title Running through initial config...
101+ :serverName
102+ cls
103+ REM Let user define the title of their server jar file
104+ echo [1mEnter the filename of your server .jar file [0m(Eg: purpur-1.20.4-2155.jar)
105+ set /p " serverName = Server .jar name: "
106+ if " %serverName:~-4 % " neq " .jar" (
107+ echo Error: File must end with .jar extension.
108+ goto :serverName
109+ )
110+ REM Check if the file exists
111+ if not exist " %serverName% " (
112+ echo Error: File " %serverName% " not found.
113+ echo Press any key to retry...
114+ pause > nul
115+ goto :serverName
116+ )
117+ goto :maxRam
118+ :maxRam
119+ cls
120+ REM Let user configure maximum RAM for the server.
121+ echo [1mEnter Maximum Ram Allocation for Minecraft Server. [0m^ (Eg:1G,1024M^ )
122+ echo ^ (Must have M or G for Megabytes and Gigabytes respectively^ )
123+ set /p maxRam = Maximum RAM:
124+ if " %maxRam% " == " " set maxRam = 1G
125+ if defined maxRam (
126+ if not " %maxRam:~-1 % " == " M" if not " %maxRam:~-1 % " == " G" (
127+ echo Invalid input, input should be one or more numbers followed by " M" or " G" .
128+ echo Press any key to retry...
129+ pause > nul
130+ goto maxRam
131+ )
132+ )
133+ goto iniRam
134+ :iniRam
135+ cls
136+ REM Let user configure maximum initial RAM for the server. Should be same as max RAM, unless on low-RAM system.
137+ echo [1mEnter Initial RAM Allocation for Minecraft Server. [0m^ (Eg:1G,1024M^ )
138+ echo ^ (Must have M or G for Megabytes and Gigabytes respectively.^ )
139+ set /p iniRam = Initial RAM:
140+ if " %iniRam% " == " " set iniRam = 1G
141+ if defined iniRam (
142+ if not " %iniRam:~-1 % " == " M" if not " %iniRam:~-1 % " == " G" (
143+ echo Invalid input, input should be one or more numbers followed by " M" or " G" .
144+ echo Press any key to retry...
145+ pause > nul
146+ goto iniRam
147+ )
148+ )
149+ cls
150+ REM Let user configure whether the server auto-restarts
151+ echo [1mAuto-restart the Minecraft Server on crash or ^ /restart[0m
152+ CHOICE /N /C:YN /M " Auto-restart (Y/N): "
153+ if %errorlevel% == 1 set autoRestart = true
154+ if %errorlevel% == 2 set autoRestart = false
155+ cls
156+ REM Let user configure whether to use customised JVM arguments
157+ echo [1mUse optimised JVM args?[0m
158+ CHOICE /N /C:YN /M " Optimised JVM args (Y/N): "
159+ if %errorlevel% == 1 set optArgs = true
160+ if %errorlevel% == 2 set optArgs = false
161+ cls
162+ REM Let user configure whether to use default server GUI
163+ echo [1mEnable server GUI?[0m
164+ CHOICE /N /T 5 /D N /C:YN /M " GUI (Y/N): "
165+ if %errorlevel% == 1 set GUI = true
166+ if %errorlevel% == 2 set GUI = false
167+ REM Confirm user choices
168+ cls
169+ echo [1;32m.............................................[0m
170+ echo [1;4;33mServer[0m: [33m%serverName% [0m
171+ echo [1;4;33mInitial RAM[0m: [33m%iniRam% [0;1m^ | [1;4;33mMaximum RAM[0m: [33m%maxRam% [0m
172+ echo [1;4;33mAuto-restart[0m: [33m%autoRestart% [0m
173+ echo [1;4;33mServer GUI[0m: [33m%GUI% [0m
174+ echo [1;32m.............................................[0m
175+ CHOICE /N /C:YN /M " These are your desired settings? (Y/N): "
176+ if %errorlevel% == 1 goto saveSetup
177+ if %errorlevel% == 2 goto initialSetup
178+
179+ :saveSetup
180+ title Saving setup...
181+ echo # > .\config\StartupScript.conf
182+ echo # --------------------------------------------------------------------------------------------------------------------------- >> .\config\StartupScript.conf
183+ echo # Change the values in the section below >> .\config\StartupScript.conf
184+ echo # --------------------------------------------------------------------------------------------------------------------------- >> .\config\StartupScript.conf
185+ echo # >> .\config\StartupScript.conf
186+ echo # Define server file name here >> .\config\StartupScript.conf
187+ echo serverName=%serverName% >> .\config\StartupScript.conf
188+ echo . >> .\config\StartupScript.conf
189+ echo # Define RAM allocation amount here you can use G for Gigabytes or M for Megabytes >> .\config\StartupScript.conf
190+ echo # Maximum memory allocation pool >> .\config\StartupScript.conf
191+ echo maxRam=%maxRam% >> .\config\StartupScript.conf
192+ echo # Initial memory allocation pool >> .\config\StartupScript.conf
193+ echo iniRam=%iniRam% >> .\config\StartupScript.conf
194+ echo . >> .\config\StartupScript.conf
195+ echo # Restart mode on crash or /restart ^ (true/false^ ) default = true >> .\config\StartupScript.conf
196+ echo autoRestart=%autoRestart% >> .\config\StartupScript.conf
197+ echo . >> .\config\StartupScript.conf
198+ echo # Vanilla server GUI ^ (true/false^ ) >> .\config\StartupScript.conf
199+ echo GUI=%GUI% >> .\config\StartupScript.conf
200+ echo . >> .\config\StartupScript.conf
201+ echo # Set console title here >> .\config\StartupScript.conf
202+ echo Title=Minecraft Server >> .\config\StartupScript.conf
203+ echo . >> .\config\StartupScript.conf
204+ echo Config variables successfully saved to StartupScript.conf
205+
206+ REM Write Java Args to .\config\jvm_args.txt
207+ if %optArgs% == true (
208+ echo -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+AlwaysActAsServerClassMachine -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:NmethodSweepActivity=1 -XX:ReservedCodeCacheSize=400M -XX:NonNMethodCodeHeapSize=12M -XX:ProfiledCodeHeapSize=194M -XX:NonProfiledCodeHeapSize=194M -XX:-DontCompileHugeMethods -XX:MaxNodeLimit=240000 -XX:NodeLimitFudgeFactor=8000 -XX:+UseVectorCmov -XX:+PerfDisableSharedMem -XX:+UseFastUnorderedTimeStamps -XX:+UseCriticalJavaThreadPriority -XX:ThreadPriorityPolicy=1 -XX:AllocatePrefetchStyle=3 -XX:+UseG1GC -XX:MaxGCPauseMillis=130 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=28 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=20 -XX:G1MixedGCCountTarget=3 -XX:InitiatingHeapOccupancyPercent=10 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=0 -XX:SurvivorRatio=32 -XX:MaxTenuringThreshold=1 -XX:G1SATBBufferEnqueueingThresholdPercent=30 -XX:G1ConcMarkStepDurationMillis=5 -XX:G1ConcRefinementServiceIntervalMillis=150 -XX:G1ConcRSHotCardLimit=16>> .\config\jvm_args.txt
209+ ) else (
210+ echo . >> .\config\jvm_args.txt
211+ )
212+ echo [32mJVM arguments file successfully created[0m
213+ goto eula
214+
215+ :eula
216+ REM Set EULA to true
217+ cd %localhost%
218+ if exist eula.txt (del eula.txt)
219+ echo #By changing the setting below to TRUE you are indicating your agreement to our EULA ^ (https://aka.ms/MinecraftEULA^ )^ .>> eula.txt
220+ echo #Auto-accepted EULA with startup script made by Garn Servo. >> eula.txt
221+ echo eula=true>> eula.txt
222+ echo [32mEULA created and accepted.[0m
223+
224+ goto initiateServer
0 commit comments