Skip to content

Instantly share code, notes, and snippets.

@phoenixthrush
Created April 12, 2024 18:42
Show Gist options
  • Save phoenixthrush/74dfdf7d0f8f23dcb755b09be86db19d to your computer and use it in GitHub Desktop.
Save phoenixthrush/74dfdf7d0f8f23dcb755b09be86db19d to your computer and use it in GitHub Desktop.
Quickly launch a paper server with TreeFeller Plugin
get_paper() {
PAPER_VERSION=$(curl -s https://api.papermc.io/v2/projects/paper | jq '.versions | .[-1]' | sed 's/^.\(.*\).$/\1/')
BUILD_VERSION=$(curl -s https://api.papermc.io/v2/projects/paper/versions/$PAPER_VERSION | jq '.builds | .[-1]')
for file in paper-*.jar; do
if [ $file = paper-$PAPER_VERSION-$BUILD_VERSION.jar ]; then
continue
fi
rm -f $file
done
if [ ! -f paper-$PAPER_VERSION-$BUILD_VERSION.jar ]; then
curl -so paper-$PAPER_VERSION-$BUILD_VERSION.jar https://api.papermc.io/v2/projects/paper/versions/$PAPER_VERSION/builds/$BUILD_VERSION/downloads/paper-$PAPER_VERSION-$BUILD_VERSION.jar
fi
}
###### DEBUG: Vanilla Server ######
get_server() {
curl -sLO $(curl -sA "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" https://www.minecraft.net/en-us/download/server | grep -o 'https://.*\.jar' | sed 's/".*//')
}
###################
config_paper() {
MEMORY_LEFT=$((($(free -k | awk 'NR==2{print $4 + $6}') / 1024 - 2048)))
SWAP_LEFT=$(free -m | awk '/Swap/ {print $4}')
TOTAL_MEMORY=$((MEMORY_LEFT + SWAP_LEFT))
if [ $MEMORY_LEFT -lt 2048 ]; then
if [ $SWAP_LEFT -eq 0 ]; then
echo -e "\e[31mError: Not enough memory available and no swap space available."
echo -e "Need at least 2048MiB of memory.\e[00m"
exit 1
fi
read -p "Not enough memory available, but swap space is present. Do you want to use swap space? [yes/no]: " USE_SWAP
if [ "$USE_SWAP" != "yes" ]; then
echo "Exiting..."
exit 1
fi
ALLOCATED_MEMORY=$((TOTAL_MEMORY - (2048 % 1024)))
if [ $ALLOCATED_MEMORY -lt 2048 ]; then
echo -e "\e[31mError: Not enough memory available even with swap."
echo -e "Exiting...\e[00m"
exit 1
fi
else
ALLOCATED_MEMORY=$((MEMORY_LEFT - (2048 % 1024)))
fi
read -p "Do you want to specify your own RAM value? [yes/no]: " SPECIFY_RAM
if [ "$SPECIFY_RAM" = "yes" ]; then
read -p "Enter the desired RAM value in MB: " CUSTOM_RAM
ALLOCATED_MEMORY=$(((CUSTOM_RAM + 1023) / 1024 * 1024))
if [ $ALLOCATED_MEMORY -gt $TOTAL_MEMORY ]; then
echo -e "\e[31mError: Specified RAM value exceeds available memory."
echo -e "Exiting...\e[00m"
exit 1
fi
if [ $ALLOCATED_MEMORY -lt 1024 ]; then
echo "Specified RAM value is less than 1GB. Setting allocated memory to 1GB."
ALLOCATED_MEMORY=1024
fi
echo "Allocating Memory: $ALLOCATED_MEMORY MB"
fi
if [ $ALLOCATED_MEMORY -eq 0 ]; then
ALLOCATED_MEMORY=$((MEMORY_LEFT - (2048 % 1024)))
if [ $ALLOCATED_MEMORY -lt 1024 ]; then
echo "Calculated allocated memory is less than 1GB. Setting allocated memory to 1GB."
ALLOCATED_MEMORY=1024
fi
fi
}
accept_eula() {
if [ ! -f "eula.txt" ]; then
echo -e "#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA).\n#$(date)\neula=true" >eula.txt
fi
}
config_server() {
if [ ! -f "server.properties" ]; then
echo I01pbmVjcmFmdCBzZXJ2ZXIgcHJvcGVydGllcwojKEZpbGUgbW9kaWZpY2F0aW9uIGRhdGUgYW5kIHRpbWUpCmVuYWJsZS1qbXgtbW9uaXRvcmluZz1mYWxzZQpyY29uLnBvcnQ9MjU1NzUKbGV2ZWwtc2VlZD0KZ2FtZW1vZGU9c3Vydml2YWwKZW5hYmxlLWNvbW1hbmQtYmxvY2s9ZmFsc2UKZW5hYmxlLXF1ZXJ5PWZhbHNlCmdlbmVyYXRvci1zZXR0aW5ncz17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zb2xlLXRvLW9wcz10cnVlCnNwYXduLW5wY3M9dHJ1ZQpzcGF3bi1hbmltYWxzPXRydWUKbG9nLWlwcz10cnVlCmZ1bmN0aW9uLXBlcm1pc3Npb24tbGV2ZWw9Mgppbml0aWFsLWVuYWJsZWQtcGFja3M9dmFuaWxsYQpsZXZlbC10eXBlPW1pbmVjcmFmdFw6bm9ybWFsCnRleHQtZmlsdGVyaW5nLWNvbmZpZz0Kc3Bhd24tbW9uc3RlcnM9dHJ1ZQplbmZvcmNlLXdoaXRlbGlzdD1mYWxzZQpzcGF3bi1wcm90ZWN0aW9uPTE2CnJlc291cmNlLXBhY2stc2hhMT0KbWF4LXdvcmxkLXNpemU9Mjk5OTk5ODQ= | base64 -d | tee server.properties
echo ""
read -p "Do you want to edit server.properties? [yes/no]: " EDIT_SERVER_PROPERTIES
fi
if [ "$EDIT_SERVER_PROPERTIES" = "yes" ]; then
if command -v nano &>/dev/null; then
editor="nano"
elif command -v vim &>/dev/null; then
editor="vim"
else
echo "No editor found. Cannot edit server.properties."
exit 1
fi
$editor server.properties
else
echo "Skipping server.properties editing."
fi
}
launch_paper() {
java -Xms1024M -Xmx${ALLOCATED_MEMORY}M -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 -Dusing.aikars.flags=https://mcflags.emc.gs \
-Daikars.new.flags=true -jar paper-$PAPER_VERSION-$BUILD_VERSION.jar --nogui
}
purge_all() {
for item in *; do
if [[ "$item" == "start.sh" || "$item" == "debug.sh" ]]; then
continue
fi
rm -rf "$item"
done
}
add_plugins() {
mkdir -p plugins; cd plugins
echo Adding TreeFeller Plugin
filename=$(curl -s https://dev.bukkit.org/projects/thizzyz-tree-feller | grep -o '>TreeFeller-*.*' | cut -c 2- | rev | cut -c 5- | rev)
rm TreeFeller-*.jar
wget -q -O $filename "https://dev.bukkit.org/projects/thizzyz-tree-feller/files/latest"
# Adding Spark Plugin
# filename=$(curl -s https://ci.lucko.me/job/spark/lastSuccessfulBuild/artifact/spark-bukkit/build/libs/ | grep -oP 'spark-.*?-bukkit\.jar' | head -n 1)
# rm spark-*.jar
# curl -sO "https://ci.lucko.me/job/spark/lastSuccessfulBuild/artifact/spark-bukkit/build/libs/$filename"
cd ..
}
if [[ "$1" == "--purge" ]]; then
purge_all
exit
fi
get_paper
config_paper
accept_eula
config_server
add_plugins
launch_paper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment