-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClickMe.bat
119 lines (95 loc) · 4.11 KB
/
ClickMe.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
@REM ---------------------------- Console ----------------------------
::: Script to start the Minecraft server
:: Creates a new window with the title "Pitufialdea"
@echo off
title Pitufialdea
color 3f
@REM ---------------------------- Console ----------------------------
@REM ---------------------------- Update ----------------------------
::: Updates the server to the latest version
:: The folder directory is the current directory
set folder_directory=%cd%
:: Checks if server.jar exists
if not exist "server.jar" goto :download
::: Outputs the latest server version from the Mojang website
:: The latest server version is saved in the version.txt file
powershell -Command "(Invoke-RestMethod -Uri 'https://launchermeta.mojang.com/mc/game/version_manifest.json').latest.release" > version.txt
:: The server version is saved in the server_version variable
set /p server_version=<version.txt
:: The version.txt file is deleted
del version.txt
:: Separator
echo ------------------------------
:: The server version is displayed in the console
echo Latest server version: %server_version%
:: Tells the current version from the folder's name folder_directory\versions\{folder name}
:: Only outputs {folder name}
for /d %%a in ("%folder_directory%\versions\*") do set current_version=%%~nxa
:: The current version is displayed in the console
echo Current server version: %current_version%
:: Checks if current version is the same as server version
if "%server_version%"=="%current_version%" goto :backup
:: Asks the user if they want to upgrade the server
choice /C:yn /T:9999 /D:y /M "Upgrade server?"
if errorlevel 2 goto :start
:: Removes the old server.jar file
del "server.jar"
:: Downloads the new server.jar file from the Mojang website
:: Edit if deprecated
:download
curl "https://piston-data.mojang.com/v1/objects/59353fb40c36d304f2035d51e7d6e6baa98dc05c/server.jar" --output server.jar
@REM ---------------------------- Update ----------------------------
@REM ---------------------------- Backup ----------------------------
:backup
::: Script that creates a backup of the world folder using 7zip
:: Checks if %folder_directory%\world exists
if not exist "%folder_directory%\world" goto :start
:: The backup is saved in the backup folder with the current date and time as the file name
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
:: The date and time are saved in the YYYY, MM, DD, HH, Min, and Sec variables
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%
:: The stamp is the current date and time in the format HH-Min-Sec_DD-MM-YYYY
set stamp=%HH%-%Min%-%Sec%_%DD%-%MM%-%YYYY%
:: Creates a backup of the world folder using 7zip
7zG.exe a "%folder_directory%\backup\world_%stamp%.zip" "%folder_directory%\world"
:: Separator
echo ------------------------------
:: Tells the user the backup is complete
echo Backup complete
@REM ---------------------------- Backup ----------------------------
@REM ---------------------------- Start ----------------------------
::: Script to start the Minecraft server
:start
:: Separator
echo ------------------------------
:: Starts the Minecraft server
java -Xms6G -Xmx6G -XX:+UseG1GC -jar server.jar nogui
@REM ---------------------------- Start ----------------------------
@REM ---------------------------- Restart ----------------------------
::: Script to restart the Minecraft server
:restart
:: Separator
echo ------------------------------
:: Asks the user if they want to restart the server
choice /C:yn /T:9999 /D:y /M "Restart server?"
if errorlevel 2 goto :exit
:: Restarts the server
goto :start
@REM ---------------------------- Restart ----------------------------
@REM ---------------------------- Exit ----------------------------
::: Script to exit the Minecraft server
:exit
:: Separator
echo ------------------------------
:: Tells the user the server is exiting
echo Exiting server...
timeout /T 2
:: Exits the server
exit
```
@REM ---------------------------- Exit ----------------------------