Skip to content

Commit

Permalink
Minecraft Java Server: support new forge jar format
Browse files Browse the repository at this point in the history
also improve user experience during updates and uninstallation to prompt and wait for user input
  • Loading branch information
theofficialgman committed Jan 6, 2024
1 parent ee49cfc commit 8dcfdf4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 55 deletions.
56 changes: 16 additions & 40 deletions apps/Minecraft Java Server/install
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,19 @@

status "This script helps you setup a Minecraft-Java-Server (for any version)."

#allow user to skip installation if executed from an update
if [[ "$1" == "update" ]];then
description="The Minecraft Java Server script was executed as part of an update to improve platform support.\nWould you like to check for newer versions of Minecraft to upgrade your server to or exit now?"
userinput_func "$description" "Yes, check for newer Minecraft versions and upgrade my install" "No, leave my install alone and exit now"
if [ "$output" == "No, leave my install alone and exit now" ]; then
status "User chose to exit the Minecraft Java Server script as part of an update without reinstallation."
exit 0
fi
fi

# add jq to use in script
install_packages jq || exit 1

# userinput function to display yad prompts to the user
function userinput_func {
unset uniq_selection
if [[ "${#@}" == "2" ]];then
echo -e "$1" | yad --no-escape --undecorated --show-uri --center --image "dialog-information" --borders="20" --title "User Info Prompt" \
--text-info --fontname="@font@ 11" --wrap --width=800 --height=200 --window-icon="${DIRECTORY}/apps/Minecraft Java Server/icon-64.png" \
--show-uri \
--button="$2":0
output="$2"
else
for string in "${@:2}"; do
uniq_selection+=(FALSE "$string")
done
uniq_selection[0]=TRUE
output=$(
yad --no-escape --undecorated --center \
--borders="20" \
--window-icon="${DIRECTORY}/apps/Minecraft Java Server/icon-64.png" \
--text "$1" \
--list \
--no-headers \
--radiolist \
--center \
--fixed \
--height="400" \
--column "" \
--column "Selection" \
--print-column=2 \
--separator='' \
--button="Ok":0 \
"${uniq_selection[@]}"
)
fi
}

mkdir -p "$HOME/Minecraft-Java-Server"
cd "$HOME/Minecraft-Java-Server" || error "Could not enter Minecraft-Java-Server folder."

Expand Down Expand Up @@ -125,7 +100,7 @@ done
server_jar=$(echo ${server_jar})

if [ -z "$server_version" ]; then
# tell user to choose java 8, 16, or 17
# tell user to choose java 8 or 17
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 or 17.\
Expand All @@ -138,8 +113,7 @@ 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.16.5 < version <= 1.17.1 java 16
# version >= 1.18 java 17
# version >= 1.17 java 17
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"
Expand All @@ -151,9 +125,9 @@ 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, 16, or 17.\
\nJava versions can be 8 or 17.\
\n\nAll version of Minecraft before and including Minecraft 1.16.5 should use Java 8.\
\nMinecraft 1.17.X should use java 16 and Minecraft 1.18+ should use java 17."
\nMinecraft 1.17+ should use java 17."
table=("Java 17" "Java 8")
userinput_func "$description" "${table[@]}"
java_selection="$output"
Expand Down Expand Up @@ -221,6 +195,8 @@ if [[ "$server_category" == "Forge" ]]; then
server_jar="minecraftforge-universal-$installer_version.jar"
elif [[ -f "forge-$installer_version-universal.jar" ]]; then
server_jar="forge-$installer_version-universal.jar"
elif [[ -f "forge-$installer_version-shim.jar" ]]; then
server_jar="forge-$installer_version-shim.jar"
elif [[ -f "forge-$installer_version.jar" ]]; then
server_jar="forge-$installer_version.jar"
elif [[ -f "run.sh" ]]; then
Expand Down
32 changes: 17 additions & 15 deletions apps/Minecraft Java Server/uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ shopt -s extglob

#skip uninstallation if executed from an update
if [[ "$1" != "update" ]];then
cd $HOME/Minecraft-Java-Server && rm -rf !(world|mods|versions)
rm -rf $HOME/.local/share/applications/Minecraft-Java-Server.desktop || error "Failed to remove the desktop file"
# stop the server
sudo systemctl stop minecraft-server
# disable server from starting on boot
sudo systemctl disable minecraft-server

# remove the systemd service
sudo rm -f /etc/systemd/system/minecraft-server.service
sudo systemctl daemon-reload

purge_packages || error "Dependencies failed to uninstall"
rm_external_repo "adoptium"
remove_repofile_if_unused /etc/apt/sources.list.d/adoptopenjdk.list
text="You chose to uninstall the Minecraft Java Server script.\nAll files within your $HOME/Minecraft-Java-Server folder will be deleted except the worlds, mods, and versions subfolders.\nIf you would like to backup any other files/folders do that NOW before clicking the prompt."
userinput_func "$text" "Ok, I have made any backups I wish, continue"
cd $HOME/Minecraft-Java-Server && rm -rf !(world|mods|versions)
rm -rf $HOME/.local/share/applications/Minecraft-Java-Server.desktop || error "Failed to remove the desktop file"
# stop the server
sudo systemctl stop minecraft-server
# disable server from starting on boot
sudo systemctl disable minecraft-server

# remove the systemd service
sudo rm -f /etc/systemd/system/minecraft-server.service
sudo systemctl daemon-reload

purge_packages || error "Dependencies failed to uninstall"
rm_external_repo "adoptium"
remove_repofile_if_unused /etc/apt/sources.list.d/adoptopenjdk.list
else
echo "Uninstall skipped because run from the updater"
echo "Uninstall skipped because run from the updater"
fi

0 comments on commit 8dcfdf4

Please sign in to comment.