Restauradores-modpack/recreate_world.sh
2026-06-21 21:00:37 +02:00

76 lines
2.1 KiB
Bash

#!/bin/bash
# ==========================================
# CONFIGURATION
# ==========================================
CONTAINER_NAME="game-servers-mc-1"
# Path to your world folder on the HOST machine (Change this to your actual path!)
WORLD_PATH="./world"
# ==========================================
echo "==> Stopping container: $CONTAINER_NAME"
docker stop "$CONTAINER_NAME"
echo "==> Waiting for container to close completely..."
docker wait "$CONTAINER_NAME" > /dev/null
echo "==> Deleting the old world folder..."
if [ -d "$WORLD_PATH" ]; then
rm -rf "$WORLD_PATH"
echo " Success: World folder deleted."
else
echo " Warning: World folder not found at $WORLD_PATH."
echo " Please verify the WORLD_PATH variable inside this script!"
fi
# Capture the current time (in seconds since epoch) BEFORE starting
BOOT_TIME=$(date +%s)
echo "==> Starting container: $CONTAINER_NAME"
docker start "$CONTAINER_NAME"
echo "==> Waiting for Minecraft server and BlueMap to fully load..."
sleep 3
# Loop until BOTH "Done" and "[BlueMap/]: Loaded!" appear in the logs
while true; do
# Fetch logs since boot time once per loop iteration
CURRENT_LOGS=$(docker logs --since "$BOOT_TIME" "$CONTAINER_NAME" 2>&1)
# Check for both strings
echo "$CURRENT_LOGS" | grep -q -E "Done \("
MC_DONE=$?
echo "$CURRENT_LOGS" | grep -q "\[BlueMap/\]: Loaded!"
BM_DONE=$?
# If both grep commands succeeded (exit code 0), break the loop
if [ $MC_DONE -eq 0 ] && [ $BM_DONE -eq 0 ]; then
break
fi
echo -n "."
sleep 3
done
echo -e "\n==> Server and BlueMap are up! Connecting and executing commands..."
# Helper function to send commands using your exact docker rcon command
send_cmd() {
echo " Sending: /$1"
docker exec -i "$CONTAINER_NAME" rcon-cli "$1"
sleep 0.5
}
# Executing commands in strict order
send_cmd "worldborder center 0 0"
send_cmd "worldborder set 15000"
send_cmd "chunky world world"
send_cmd "chunky worldborder"
send_cmd "chunky radius +25c"
send_cmd "chunky start"
send_cmd "chunky confirm"
send_cmd "bluemap purge world"
echo "==> All tasks completed successfully!"