Last active
June 28, 2025 16:46
-
-
Save krisstibex/7537eadc1f83c4c8279de5af20466b40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo -ne "\033]0;Minecraft Server Launcher\a" | |
| cd "$(dirname "$0")" || exit 1 | |
| umask 022 | |
| green() { echo -e "\033[32m$1\033[0m"; } | |
| red() { echo -e "\033[31m$1\033[0m"; } | |
| green " | |
| __ ____ ______ | |
| / |/ (_)___ ___ ______________ _/ __/ /_ | |
| / /|_/ / / __ \/ _ \/ ___/ ___/ __ \`/ /_/ __/ | |
| / / / / / / / / __/ /__/ / / /_/ / __/ /_ | |
| /_/ /_/_/_/ /_/\___/\___/_/ \__,_/_/ \__/ | |
| " | |
| JAVA_HOME="/Library/Java/JavaVirtualMachines/zulu-21.jdk/Contents/Home" | |
| export JAVA_HOME | |
| export PATH="$JAVA_HOME/bin:$PATH" | |
| JAR_FILE="server.jar" | |
| JAVA_FLAGS="-Xms2G -Xmx2G -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:+ParallelRefProcEnabled -XX:+PerfDisableSharedMem -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1HeapRegionSize=8M -XX:G1HeapWastePercent=5 -XX:G1MaxNewSizePercent=40 -XX:G1MixedGCCountTarget=4 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1NewSizePercent=30 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:G1ReservePercent=20 -XX:InitiatingHeapOccupancyPercent=15 -XX:MaxGCPauseMillis=200 -XX:MaxTenuringThreshold=1 -XX:SurvivorRatio=32" | |
| if [ ! -f "$JAR_FILE" ]; then | |
| red "[错误] 找不到 $JAR_FILE" | |
| exit 1 | |
| fi | |
| echo "eula=true" > eula.txt | |
| GUI_FLAG="nogui" | |
| if [ -t 0 ]; then | |
| case "$1" in | |
| gui) GUI_FLAG="";; | |
| nogui) GUI_FLAG="nogui";; | |
| *) read -p "使用 GUI 模式?(y/N): " yn | |
| [[ $yn =~ ^[Yy]$ ]] && GUI_FLAG="" || GUI_FLAG="nogui" | |
| ;; | |
| esac | |
| fi | |
| trap 'echo; red "[中断] 已终止脚本"; exit 0' SIGINT | |
| green "[启动] Java 版本:" | |
| java -version 2>&1 | while read -r line; do green " $line"; done | |
| green "[启动] 正在运行服务器..." | |
| while true; do | |
| clear | |
| green " | |
| __ ____ ______ | |
| / |/ (_)___ ___ ______________ _/ __/ /_ | |
| / /|_/ / / __ \/ _ \/ ___/ ___/ __ \`/ /_/ __/ | |
| / / / / / / / / __/ /__/ / / /_/ / __/ /_ | |
| /_/ /_/_/_/ /_/\___/\___/_/ \__,_/_/ \__/ | |
| " | |
| echo "[$(date '+%H:%M:%S')] 启动中..." | |
| java $JAVA_FLAGS -jar "$JAR_FILE" $GUI_FLAG | |
| echo | |
| echo "[$(date '+%H:%M:%S')] 服务器已关闭,10 秒后重启... (Ctrl+C 退出)" | |
| sleep 10 | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| cd "$(dirname "$0")" | |
| CONFIG_FILE="server.properties" | |
| if [ ! -f "$CONFIG_FILE" ]; then | |
| echo "❌ 找不到 server.properties,请确认你在服务端根目录下运行此脚本。" | |
| exit 1 | |
| fi | |
| # 获取 online-mode 当前状态 | |
| current_mode=$(grep -E "^online-mode=" "$CONFIG_FILE" | cut -d'=' -f2) | |
| if [ -z "$current_mode" ]; then | |
| echo "❌ 未找到 online-mode 设置项。" | |
| exit 1 | |
| fi | |
| echo "✅ 当前 Online Mode 状态为:$current_mode" | |
| # 切换目标状态 | |
| if [ "$current_mode" = "true" ]; then | |
| new_mode="false" | |
| else | |
| new_mode="true" | |
| fi | |
| # 确认切换 | |
| echo -n "❓ 是否要切换为 $new_mode? (y/n): " | |
| read -r confirm | |
| if [[ "$confirm" =~ ^[Yy]$ ]]; then | |
| # 判断系统平台,选择合适的 sed 命令 | |
| if [[ "$OSTYPE" == "darwin"* ]]; then | |
| sed -i '' "s/^online-mode=.*/online-mode=$new_mode/" "$CONFIG_FILE" | |
| else | |
| sed -i "s/^online-mode=.*/online-mode=$new_mode/" "$CONFIG_FILE" | |
| fi | |
| echo "✅ 已切换 Online Mode 为:$new_mode" | |
| else | |
| echo "ℹ️ 操作取消,未进行更改。" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment