-
-
Notifications
You must be signed in to change notification settings - Fork 267
Minecraft Java Server: Various improvements #2994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
25ea096
0728712
371288b
d090e8a
0f69420
98ce117
c989eec
6fb2ab3
52afa82
48b4bff
b4c8e9d
483f178
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,11 +15,26 @@ fi | |
| # add jq to use in script | ||
| install_packages jq || exit 1 | ||
|
|
||
| mkdir -p "$HOME/Minecraft-Java-Server" | ||
| cd "$HOME/Minecraft-Java-Server" || error "Could not enter Minecraft-Java-Server folder." | ||
| # using the mcserdir.txt file or creating it | ||
| mkdir -p "$HOME/Documents" | ||
| cd "$HOME/Documents" || error "Could not enter Documents folder." | ||
| if [ -f "mcserdir.txt" ];then | ||
| # read mcserdir.txt | ||
| directory=$(cat "mcserdir.txt") | ||
| # make sure the user wants to install the server in the saved directory, as mcserdir.txt persists on uninstall | ||
| text="Using the $directory directory.\nIf you would like to use a different directory,\nexit the script and delete the $HOME/Documents/mcserdir.txt file." | ||
| userinput_func "$text" "Continue with the $directory directory" | ||
| else | ||
| # allow user to select directory | ||
| directory=$(yad --center --wrap --text "Choose directory:\nDefault is $directory.\nMake sure it ends with Minecraft-Java-Server if you don't want it to fail." --entry --entry-text="$directory" --button="Submit":0) | ||
| # store directory in $HOME/Documents so it can be used later | ||
| echo "$directory" > mcserdir.txt | ||
| fi | ||
| mkdir -p "$directory" || error "$directory is invalid or privileged." | ||
| cd "$directory" || error "Could not enter $directory folder." | ||
|
|
||
| description="What type of Minecraft server\ndo you want to run?" | ||
| table=("Vanilla" "Fabric" "Forge" "Paper" "Purpur") | ||
| table=("Vanilla" "Fabric" "Forge" "Paper" "Folia" "Purpur") | ||
| userinput_func "$description" "${table[@]}" | ||
| server_category="$output" | ||
|
|
||
|
|
@@ -55,15 +70,26 @@ case "$server_category" in | |
| wget -O "$server_jar" "https://maven.minecraftforge.net/net/minecraftforge/forge/$installer_version/forge-$installer_version-installer.jar" || exit 1 | ||
| ;; | ||
| "Paper") | ||
| available_versions=$(wget -O- https://api.papermc.io/v2/projects/paper/ | jq -r '.versions | .[]') | ||
| available_versions=$(wget -O- https://fill.papermc.io/v3/projects/paper/versions | jq -r '.versions.[].version.id') | ||
| description="What version of $server_category do you want to run?" | ||
| table=($available_versions) | ||
| userinput_func "$description" "${table[@]}" | ||
| server_version="$output" | ||
| status "Selected $server_category version $server_version" | ||
| version_info=$(wget -O- https://api.papermc.io/v2/projects/paper/versions/$server_version/builds | jq -r '.builds | [last]') | ||
| server_jar="$(echo "$version_info" | jq -r '.[].downloads.application.name')" | ||
| wget -O "$server_jar" "https://api.papermc.io/v2/projects/paper/versions/$server_version/builds/$(echo "$version_info" | jq -r '.[].build')/downloads/$server_jar" || exit 1 | ||
| version_info=$(wget -O- https://fill.papermc.io/v3/projects/paper/versions/$server_version/builds/latest | jq -r '.downloads."server:default"') | ||
| server_jar="$(echo "$version_info" | jq -r '.name')" | ||
| wget -O "$server_jar" "$(echo "$version_info" | jq -r '.url')" || exit 1 | ||
| ;; | ||
| "Folia") | ||
| available_versions=$(wget -O- https://fill.papermc.io/v3/projects/folia/versions | jq -r '.versions.[].version.id') | ||
| description="What version of $server_category do you want to run?" | ||
| table=($available_versions) | ||
| userinput_func "$description" "${table[@]}" | ||
| server_version="$output" | ||
| status "Selected $server_category version $server_version" | ||
| version_info=$(wget -O- https://fill.papermc.io/v3/projects/folia/versions/$server_version/builds/latest | jq -r '.downloads."server:default"') | ||
| server_jar="$(echo "$version_info" | jq -r '.name')" | ||
| wget -O "$server_jar" "$(echo "$version_info" | jq -r '.url')" || exit 1 | ||
| ;; | ||
| "Purpur") | ||
| available_versions=$(wget -O- https://api.purpurmc.org/v2/purpur/ | jq -r '.versions | .[]') | ||
|
|
@@ -94,7 +120,7 @@ esac | |
|
|
||
| while [[ ! -a $(echo ${server_jar}) ]]; do | ||
| description="Please use the website which has opened to download your chosen version of the Minecraft Java Server.\ | ||
| \nAdd your ${server_jar} file to the folder opened $HOME/Minecraft-Java-Server and press OK.\ | ||
| \nAdd your ${server_jar} file to the folder opened $directory and press OK.\ | ||
| \n\nYou have not added a ${server_jar}." | ||
| table=("OK") | ||
| userinput_func "$description" "${table[@]}" | ||
|
|
@@ -104,26 +130,31 @@ done | |
| server_jar=$(echo ${server_jar}) | ||
|
|
||
| if [ -z "$server_version" ]; then | ||
| # tell user to choose java 8, 17, or 21 | ||
| # tell user to choose java 8, 17, 21, or 25 | ||
| description="In order to run Minecraft, the game requires a specific version of Java.\ | ||
| \nPlease choose below which version of java the server of your choice should run with.\ | ||
| \nJava versions can be 8, 17, or 21.\ | ||
| \nJava versions can be 8, 17, 21, or 25.\ | ||
| \n\nAll versions of Minecraft before and including Minecraft 1.16.5 should use Java 8.\ | ||
| \nMinecraft 1.17-1.20 should use java 17.\ | ||
| \nMinecraft 1.21+ should use java 21." | ||
| table=("Java 21" "Java 17" "Java 8") | ||
| \nMinecraft 1.21-1.21.11 should use java 21.\ | ||
| \nMinecraft 26.1+ should use java 25." | ||
| table=("Java 25" "Java 21" "Java 17" "Java 8") | ||
| userinput_func "$description" "${table[@]}" | ||
| java_selection="$output" | ||
| else | ||
| # we know the version of minecraft in use | ||
| # choose the appropriate version of java based on that | ||
| # version <= 1.16.5 java 8 | ||
| # 1.17 <= version < 1.21 java 17 | ||
| # version >= 1.21 java 21 | ||
| # 1.21 <= version < 26.1 java 21 | ||
| # version >= 26.1 java 25 | ||
| function version { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; } | ||
| if [ $(version $server_version) -le $(version "1.16.5") ]; then | ||
| echo "Using Java 8 by default" | ||
| java_selection="Java 8" | ||
| elif [ $(version $server_version) -ge $(version "26.1") ]; then | ||
| echo "Using Java 25 by default" | ||
| java_selection="Java 25" | ||
| elif [ $(version $server_version) -ge $(version "1.21") ]; then | ||
| echo "Using Java 21 by default" | ||
| java_selection="Java 21" | ||
|
|
@@ -134,11 +165,12 @@ else | |
| description="WARNING: We don't know how you got here... your version $server_version does not seem to be a normal minecraft format.\ | ||
| \n\nIn order to run Minecraft, the game requires a specific version of Java.\ | ||
| \nPlease choose below which version of java the server of your choice should run with.\ | ||
| \nJava versions can be 8, 17, or 21.\ | ||
| \nJava versions can be 8, 17, 21, or 25.\ | ||
| \n\nAll version of Minecraft before and including Minecraft 1.16.5 should use Java 8.\ | ||
| \nMinecraft 1.17-1.20 should use java 17.\ | ||
| \nMinecraft 1.21+ should use java 21." | ||
| table=("Java 21" "Java 17" "Java 8") | ||
| \nMinecraft 1.21-1.21.11 should use java 21.\ | ||
| \nMinecraft 26.1+ should use java 25." | ||
| table=("Java 25" "Java 21" "Java 17" "Java 8") | ||
| userinput_func "$description" "${table[@]}" | ||
| java_selection="$output" | ||
| fi | ||
|
|
@@ -147,10 +179,10 @@ fi | |
| install_packages lsb-release wget gpg screen || exit 1 | ||
|
|
||
| case "$java_selection" in | ||
| "Java 21") | ||
| "Java 21"|"Java 25") | ||
| case "$arch" in | ||
| "32") | ||
| error "User error: Java 21 is not available for your platform from Adoptium. All 32-bit based architectures are being deprecated and removed by Java. Please use a 64-bit OS. Exiting the script." | ||
| error "User error: Java 21+ is not available for your platform from Adoptium. All 32-bit based architectures are being deprecated and removed by Java. Please use a 64-bit OS. Exiting the script." | ||
| ;; | ||
| *) | ||
| adoptium_installer || exit 1 | ||
|
|
@@ -194,13 +226,21 @@ case "$java_selection" in | |
| fi | ||
| java_location="/usr/lib/jvm/temurin-21-jre-$dpkg_arch/bin/java" | ||
| ;; | ||
| "Java 25") | ||
| if package_available temurin-25-jre ;then | ||
| install_packages temurin-25-jre || exit 1 | ||
| else | ||
| error "Java 25 is not available for your platform from Adoptium. Exiting the script." | ||
| fi | ||
| java_location="/usr/lib/jvm/temurin-25-jre-$dpkg_arch/bin/java" | ||
| ;; | ||
| esac | ||
|
|
||
| jvm_test="1" | ||
| jvm_args="" | ||
| while [[ $jvm_test != 0 ]]; do | ||
| # userinput jvm_args | ||
| jvm_args=$(yad --center --wrap --text "Would you like to input any JVM Arguments?\nA defaut list is prepopulated in the text box below.\n\nThe most inportant arguments -XmxXXXXM -XmsXXXXM are at the beginning and define how much ram for your server to use.\nHint, use your keyboard Home key to see the start of this list" --entry --entry-text="-Xmx1200M -Xms1200M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1" --button="Validate JVM Arguments":0) | ||
| jvm_args=$(yad --center --wrap --text "Would you like to input any JVM Arguments?\nA default list is prepopulated in the text box below.\n\nThe most important arguments, -Xmx and -Xms, are at the beginning and define the max RAM and initial RAM, respectively.\nYou should specify a value slightly less than your total RAM in bytes, kilobytes(k), megabytes(m), or gigabytes(g).\nHint, use your keyboard Home key to see the start of this list." --entry --entry-text="-Xmx1200m -Xms1200m -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1" --button="Validate JVM Arguments":0) | ||
|
theofficialgman marked this conversation as resolved.
Outdated
|
||
| $java_location $jvm_args -version | ||
| jvm_test="$?" | ||
| if [[ $jvm_test != 0 ]]; then | ||
|
|
@@ -212,7 +252,7 @@ done | |
| if [[ "$server_category" == "Forge" ]]; then | ||
| # run the server installer | ||
| rm -f start-server.sh | ||
| $java_location -jar $HOME/Minecraft-Java-Server/${server_jar} --installServer || error "Failed to install forge server" | ||
| $java_location -jar $directory/${server_jar} --installServer || error "Failed to install forge server" | ||
| rm -f ${server_jar} | ||
|
|
||
| # forge has MANY ways to launch depending on the version | ||
|
|
@@ -242,10 +282,10 @@ if [[ "$server_category" == "Forge" ]]; then | |
| fi | ||
|
|
||
| if [ -n "$server_jar" ]; then | ||
| sh -c "cat > $HOME/Minecraft-Java-Server/start-server.sh << _EOF_ | ||
| sh -c "cat > $directory/start-server.sh << _EOF_ | ||
| #!/bin/bash | ||
| echo 'Minecraft Server starting' | ||
| $java_location $jvm_args -jar $HOME/Minecraft-Java-Server/${server_jar} nogui || (echo -e '\e[91mMinecraft Server has crashed or could not start\e[0m'; sleep 10) | ||
| $java_location $jvm_args -jar $directory/${server_jar} nogui || (echo -e '\e[91mMinecraft Server has crashed or could not start\e[0m'; sleep 10) | ||
| echo 'Minecraft Server has stopped' | ||
| sleep 3 | ||
| _EOF_" | ||
|
|
@@ -263,7 +303,7 @@ tee "$HOME/.local/share/applications/Minecraft-Java-Server.desktop" <<EOF | |
| [Desktop Entry] | ||
| Name=Minecraft Java Server | ||
| Exec=bash -c "sudo systemctl start minecraft-server; sleep 3; screen -r Minecraft_Server; if [ \$? == 1 ]; then echo 'The minecraft server has exited without the service stopping, restarting the service for you'; sudo systemctl restart minecraft-server; sleep 5; screen -r Minecraft_Server; fi" | ||
| Path=$HOME/Minecraft-Java-Server | ||
| Path=$directory | ||
| Icon=${DIRECTORY}/apps/Minecraft Java Server/icon-64.png | ||
| Type=Application | ||
| Categories=Game | ||
|
|
@@ -273,13 +313,14 @@ EOF | |
| screen_location=$(which screen) | ||
| sleep_location=$(which sleep) | ||
|
|
||
| sudo tee "/etc/systemd/system/minecraft-server.service" <<EOF | ||
| # this is equivalent to using tee "/etc/systemd/system/minecraft-server.service" and then systemctl daemon-reload | ||
| sudo systemctl edit --stdin --full --force minecraft-server <<EOF | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either a new/old feature of systemd or AI hallucination. Please revert back to what this was before. No issue with it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm I guess it's sorta new |
||
| [Service] | ||
| RemainAfterExit=yes | ||
| WorkingDirectory=$HOME/Minecraft-Java-Server | ||
| WorkingDirectory=$directory | ||
| User=$USER | ||
| # Start Screen, Java, and Minecraft | ||
| ExecStart=$screen_location -S Minecraft_Server -U -d -m $HOME/Minecraft-Java-Server/start-server.sh | ||
| ExecStart=$screen_location -S Minecraft_Server -U -d -m $directory/start-server.sh | ||
| # Tell Minecraft to gracefully stop. | ||
| # Ending Minecraft will terminate Java | ||
| # systemd will kill Screen after the 10-second delay. No explicit kill for Screen needed | ||
|
|
@@ -292,10 +333,6 @@ WantedBy=multi-user.target | |
| EOF | ||
| echo | ||
|
|
||
| # update services | ||
| sudo systemctl daemon-reload | ||
| sudo systemctl disable minecraft-server | ||
|
|
||
|
Comment on lines
-295
to
-298
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs to be re-added. see above |
||
| status "Your IP address is one of the following: | ||
| $(hostname -I | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')" | ||
| status "The IP address is used to play on your local network | ||
|
|
@@ -307,5 +344,5 @@ Attach to a server in the background with: screen -r Minecraft_Server | |
| Detach from a running server session with: CTRL+A then D | ||
| To start from a terminal: sudo systemctl start minecraft-server | ||
| To stop the server: sudo systemctl stop minecraft-server | ||
| To start on automatically on boot and stop on shutdown: sudo systemctl enable minecraft-server | ||
| To start now, start on boot, and stop on shutdown: sudo systemctl enable --now minecraft-server | ||
| " | ||
Uh oh!
There was an error while loading. Please reload this page.