Skip to content

Instantly share code, notes, and snippets.

@stijnb1234
Last active October 11, 2024 15:01
Show Gist options
  • Select an option

  • Save stijnb1234/a72cfe8667c5ee50997ef79913b6cb6b to your computer and use it in GitHub Desktop.

Select an option

Save stijnb1234/a72cfe8667c5ee50997ef79913b6cb6b to your computer and use it in GitHub Desktop.
Auto-update PaperMc start script for testserver
#!/bin/bash
# NOTE: Requires jq to be installed (Ubuntu: sudo apt install jq -y)
# Change Minecraft version and amount of RAM to use here!
MC_VERSION="1.21.1"
MEMORY="5G"
## DO NOT TOUCH BELOW ##
# Set the title for the console
echo -e "\033]0;Minecraft Server Console [Testserver]\007"
clear
# Variables
PAPER_API="https://api.papermc.io/v2/projects/paper/versions/$MC_VERSION"
LATEST_BUILD=$(curl -s "$PAPER_API" | jq -r '.builds[-1]')
JAR_FILE="paper-$MC_VERSION-$LATEST_BUILD.jar"
# Check if the jar file already exists
if [ ! -f "$JAR_FILE" ]; then
echo "Downloading the latest PaperSpigot build ($LATEST_BUILD) for Minecraft $MC_VERSION..."
# Build URL for the latest jar
PAPER_JAR_URL="$PAPER_API/builds/$LATEST_BUILD/downloads/paper-$MC_VERSION-$LATEST_BUILD.jar"
# Download the latest build and save it with the correct name
curl -o "$JAR_FILE" "$PAPER_JAR_URL"
echo "Downloaded PaperSpigot build $LATEST_BUILD."
else
echo "You already have the latest PaperSpigot build ($LATEST_BUILD) for Minecraft $MC_VERSION."
fi
# Start the Spigot server using the latest jar file
java -Xms128M -Xmx$MEMORY -jar "$JAR_FILE" nogui
# Pause the script after server exit
read -rsp $'Press any key to continue...\n' -n1 key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment