diff --git a/scripts/start-setupWorld b/scripts/start-setupWorld index dc3901e9..10c9b486 100755 --- a/scripts/start-setupWorld +++ b/scripts/start-setupWorld @@ -37,11 +37,7 @@ if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] ); exit 1 fi - if [ "$FAMILY" = "SPIGOT" ]; then - baseDirs=$(find /tmp/world-data -name "level.dat" -not -path "*_nether*" -not -path "*_the_end*" -exec dirname "{}" \;) - else - baseDirs=$(find /tmp/world-data -name "level.dat" -exec dirname "{}" \;) - fi + baseDirs=$(find /tmp/world-data -name "level.dat" -exec dirname "{}" \;) if ! [[ $baseDirs ]]; then log "ERROR world content is not valid since level.dat could not be found" @@ -50,20 +46,65 @@ if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] ); count=$(echo "$baseDirs" | wc -l) if [[ $count -gt 1 ]]; then - baseDir="$(echo "$baseDirs" | sed -n ${WORLD_INDEX:-1}p)" - baseName=$(basename "$baseDir") - log "WARN multiple levels found, picking: $baseName" + baseDirsNoSpigotSuffix=$(echo "$baseDirs" | sed -re 's:(_nether|_the_end)/?$::' | sort -u) + if [ $(echo "$baseDirsNoSpigotSuffix" | wc -l) -eq 1 ]; then + baseDir="$baseDirsNoSpigotSuffix" + baseName=$(basename "$baseDir") + log "Found Spigot naming conventions, taking $baseName as main dimension" + else + baseDir="$(echo "$baseDirs" | sed -n ${WORLD_INDEX:-1}p)" + baseName=$(basename "$baseDir") + log "WARN multiple levels found, picking: $baseName" + fi elif [[ $count -gt 0 ]]; then baseDir="$baseDirs" else log "ERROR invalid world content" exit 1 fi + + if [ -d "${baseDir}_nether/DIM-1" ]; then + if [ -d "$baseDir/DIM-1" ]; then + log "WARN found Nether dimension in both $baseDir and ${baseDir}_nether, picking ${baseDir}_nether" + rm -r "$baseDir/DIM-1" + fi + fi + if [ -d "${baseDir}_the_end/DIM1" ]; then + if [ -d "$baseDir/DIM1" ]; then + log "WARN found End dimension in both $baseDir and ${baseDir}_the_end, picking ${baseDir}_the_end" + rm -r "$baseDir/DIM1" + fi + fi + + log "Copying world..." rsync --remove-source-files --recursive --delete "$baseDir/" "$worldDest" + if [ "$FAMILY" = "SPIGOT" ]; then - log "Copying end and nether ..." - [ -d "${baseDir}_nether" ] && rsync --remove-source-files --recursive --delete "${baseDir}_nether/" "${worldDest}_nether" - [ -d "${baseDir}_the_end" ] && rsync --remove-source-files --recursive --delete "${baseDir}_the_end/" "${worldDest}_the_end" + if [ -d "${baseDir}_nether" ]; then + log "Copying Spigot Nether..." + rsync --remove-source-files --recursive --delete "${baseDir}_nether/" "${worldDest}_nether" + elif [ -d "$worldDest/DIM-1" ]; then + log "Moving Nether to Spigot location..." + mkdir -p "${worldDest}_nether" + mv -f "$worldDest/DIM-1" "${worldDest}_nether/" + fi + if [ -d "${baseDir}_the_end" ]; then + log "Copying Spigot End..." + rsync --remove-source-files --recursive --delete "${baseDir}_the_end/" "${worldDest}_the_end" + elif [ -d "$worldDest/DIM1" ]; then + log "Moving End to Spigot location..." + mkdir -p "${worldDest}_the_end" + mv -f "$worldDest/DIM1" "${worldDest}_the_end/" + fi + else + if [ -d "${baseDir}_nether/DIM-1" ]; then + log "Copying Spigot Nether to vanilla location..." + rsync --remove-source-files --recursive --delete "${baseDir}_nether/DIM-1" "${worldDest}/" + fi + if [ -d "${baseDir}_the_end/DIM1" ]; then + log "Copying Spigot End to vanilla location..." + rsync --remove-source-files --recursive --delete "${baseDir}_the_end/DIM1" "${worldDest}/" + fi fi elif [ -d "$WORLD" ]; then log "Cloning world directory from $WORLD ..." diff --git a/tests/setuponlytests/conflicting_world_for_spigot_server/docker-compose.yml b/tests/setuponlytests/conflicting_world_for_spigot_server/docker-compose.yml new file mode 100644 index 00000000..b8172d99 --- /dev/null +++ b/tests/setuponlytests/conflicting_world_for_spigot_server/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3" + +services: + mc: + restart: "no" + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + environment: + EULA: "TRUE" + SETUP_ONLY: "TRUE" + VERSION: ${MINECRAFT_VERSION:-LATEST} + TYPE: "PAPER" + WORLD: /worlds/world-for-testing.zip + volumes: + - ./worlds:/worlds:ro + - ./data:/data diff --git a/tests/setuponlytests/conflicting_world_for_spigot_server/verify.sh b/tests/setuponlytests/conflicting_world_for_spigot_server/verify.sh new file mode 100644 index 00000000..75daef8d --- /dev/null +++ b/tests/setuponlytests/conflicting_world_for_spigot_server/verify.sh @@ -0,0 +1,5 @@ +mc-image-helper assert fileExists world/level.dat && \ +mc-image-helper assert fileExists world_nether/DIM-1/some_spigot_nether_file && \ +mc-image-helper assert fileExists world_the_end/DIM1/some_spigot_end_file && \ +! mc-image-helper assert fileExists world_nether/DIM-1/some_vanilla_nether_file && \ +! mc-image-helper assert fileExists world_the_end/DIM1/some_vanilla_end_file diff --git a/tests/setuponlytests/conflicting_world_for_spigot_server/worlds/world-for-testing.zip b/tests/setuponlytests/conflicting_world_for_spigot_server/worlds/world-for-testing.zip new file mode 100644 index 00000000..20520f02 Binary files /dev/null and b/tests/setuponlytests/conflicting_world_for_spigot_server/worlds/world-for-testing.zip differ diff --git a/tests/setuponlytests/conflicting_world_for_vanilla_server/docker-compose.yml b/tests/setuponlytests/conflicting_world_for_vanilla_server/docker-compose.yml new file mode 100644 index 00000000..4a30460e --- /dev/null +++ b/tests/setuponlytests/conflicting_world_for_vanilla_server/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3" + +services: + mc: + restart: "no" + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + environment: + EULA: "TRUE" + SETUP_ONLY: "TRUE" + VERSION: ${MINECRAFT_VERSION:-LATEST} + WORLD: /worlds/world-for-testing.zip + volumes: + - ./worlds:/worlds:ro + - ./data:/data diff --git a/tests/setuponlytests/conflicting_world_for_vanilla_server/verify.sh b/tests/setuponlytests/conflicting_world_for_vanilla_server/verify.sh new file mode 100644 index 00000000..020b8637 --- /dev/null +++ b/tests/setuponlytests/conflicting_world_for_vanilla_server/verify.sh @@ -0,0 +1,5 @@ +mc-image-helper assert fileExists world/level.dat && \ +mc-image-helper assert fileExists world/DIM-1/some_spigot_nether_file && \ +mc-image-helper assert fileExists world/DIM1/some_spigot_end_file && \ +! mc-image-helper assert fileExists world/DIM-1/some_vanilla_nether_file && \ +! mc-image-helper assert fileExists world/DIM1/some_vanilla_end_file diff --git a/tests/setuponlytests/conflicting_world_for_vanilla_server/worlds/world-for-testing.zip b/tests/setuponlytests/conflicting_world_for_vanilla_server/worlds/world-for-testing.zip new file mode 100644 index 00000000..20520f02 Binary files /dev/null and b/tests/setuponlytests/conflicting_world_for_vanilla_server/worlds/world-for-testing.zip differ diff --git a/tests/setuponlytests/spigot_world_for_spigot_server/docker-compose.yml b/tests/setuponlytests/spigot_world_for_spigot_server/docker-compose.yml new file mode 100644 index 00000000..b8172d99 --- /dev/null +++ b/tests/setuponlytests/spigot_world_for_spigot_server/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3" + +services: + mc: + restart: "no" + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + environment: + EULA: "TRUE" + SETUP_ONLY: "TRUE" + VERSION: ${MINECRAFT_VERSION:-LATEST} + TYPE: "PAPER" + WORLD: /worlds/world-for-testing.zip + volumes: + - ./worlds:/worlds:ro + - ./data:/data diff --git a/tests/setuponlytests/spigot_world_for_spigot_server/verify.sh b/tests/setuponlytests/spigot_world_for_spigot_server/verify.sh new file mode 100644 index 00000000..233a8497 --- /dev/null +++ b/tests/setuponlytests/spigot_world_for_spigot_server/verify.sh @@ -0,0 +1,4 @@ +mc-image-helper assert fileExists world/level.dat && \ +mc-image-helper assert fileExists world/some_overworld_file && \ +mc-image-helper assert fileExists world_nether/DIM-1/some_nether_file && \ +mc-image-helper assert fileExists world_the_end/DIM1/some_end_file diff --git a/tests/setuponlytests/spigot_world_for_spigot_server/worlds/world-for-testing.zip b/tests/setuponlytests/spigot_world_for_spigot_server/worlds/world-for-testing.zip new file mode 100644 index 00000000..8f779b16 Binary files /dev/null and b/tests/setuponlytests/spigot_world_for_spigot_server/worlds/world-for-testing.zip differ diff --git a/tests/setuponlytests/spigot_world_for_vanilla_server/docker-compose.yml b/tests/setuponlytests/spigot_world_for_vanilla_server/docker-compose.yml new file mode 100644 index 00000000..4a30460e --- /dev/null +++ b/tests/setuponlytests/spigot_world_for_vanilla_server/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3" + +services: + mc: + restart: "no" + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + environment: + EULA: "TRUE" + SETUP_ONLY: "TRUE" + VERSION: ${MINECRAFT_VERSION:-LATEST} + WORLD: /worlds/world-for-testing.zip + volumes: + - ./worlds:/worlds:ro + - ./data:/data diff --git a/tests/setuponlytests/spigot_world_for_vanilla_server/verify.sh b/tests/setuponlytests/spigot_world_for_vanilla_server/verify.sh new file mode 100644 index 00000000..a0d1a149 --- /dev/null +++ b/tests/setuponlytests/spigot_world_for_vanilla_server/verify.sh @@ -0,0 +1,4 @@ +mc-image-helper assert fileExists world/level.dat && \ +mc-image-helper assert fileExists world/some_overworld_file && \ +mc-image-helper assert fileExists world/DIM-1/some_nether_file && \ +mc-image-helper assert fileExists world/DIM1/some_end_file diff --git a/tests/setuponlytests/spigot_world_for_vanilla_server/worlds/world-for-testing.zip b/tests/setuponlytests/spigot_world_for_vanilla_server/worlds/world-for-testing.zip new file mode 100644 index 00000000..8f779b16 Binary files /dev/null and b/tests/setuponlytests/spigot_world_for_vanilla_server/worlds/world-for-testing.zip differ diff --git a/tests/setuponlytests/vanilla_world_for_spigot_server/docker-compose.yml b/tests/setuponlytests/vanilla_world_for_spigot_server/docker-compose.yml new file mode 100644 index 00000000..b8172d99 --- /dev/null +++ b/tests/setuponlytests/vanilla_world_for_spigot_server/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3" + +services: + mc: + restart: "no" + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + environment: + EULA: "TRUE" + SETUP_ONLY: "TRUE" + VERSION: ${MINECRAFT_VERSION:-LATEST} + TYPE: "PAPER" + WORLD: /worlds/world-for-testing.zip + volumes: + - ./worlds:/worlds:ro + - ./data:/data diff --git a/tests/setuponlytests/vanilla_world_for_spigot_server/verify.sh b/tests/setuponlytests/vanilla_world_for_spigot_server/verify.sh new file mode 100644 index 00000000..89a74836 --- /dev/null +++ b/tests/setuponlytests/vanilla_world_for_spigot_server/verify.sh @@ -0,0 +1,3 @@ +mc-image-helper assert fileExists world/level.dat && \ +mc-image-helper assert fileExists world_nether/DIM-1/some_nether_file && \ +mc-image-helper assert fileExists world_the_end/DIM1/some_end_file diff --git a/tests/setuponlytests/vanilla_world_for_spigot_server/worlds/world-for-testing.zip b/tests/setuponlytests/vanilla_world_for_spigot_server/worlds/world-for-testing.zip new file mode 100644 index 00000000..cfdd882e Binary files /dev/null and b/tests/setuponlytests/vanilla_world_for_spigot_server/worlds/world-for-testing.zip differ diff --git a/tests/setuponlytests/vanilla_world_for_vanilla_server/docker-compose.yml b/tests/setuponlytests/vanilla_world_for_vanilla_server/docker-compose.yml new file mode 100644 index 00000000..4a30460e --- /dev/null +++ b/tests/setuponlytests/vanilla_world_for_vanilla_server/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3" + +services: + mc: + restart: "no" + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + environment: + EULA: "TRUE" + SETUP_ONLY: "TRUE" + VERSION: ${MINECRAFT_VERSION:-LATEST} + WORLD: /worlds/world-for-testing.zip + volumes: + - ./worlds:/worlds:ro + - ./data:/data diff --git a/tests/setuponlytests/vanilla_world_for_vanilla_server/verify.sh b/tests/setuponlytests/vanilla_world_for_vanilla_server/verify.sh new file mode 100644 index 00000000..82e2044c --- /dev/null +++ b/tests/setuponlytests/vanilla_world_for_vanilla_server/verify.sh @@ -0,0 +1,3 @@ +mc-image-helper assert fileExists world/level.dat && \ +mc-image-helper assert fileExists world/DIM-1/some_nether_file && \ +mc-image-helper assert fileExists world/DIM1/some_end_file diff --git a/tests/setuponlytests/vanilla_world_for_vanilla_server/worlds/world-for-testing.zip b/tests/setuponlytests/vanilla_world_for_vanilla_server/worlds/world-for-testing.zip new file mode 100644 index 00000000..cfdd882e Binary files /dev/null and b/tests/setuponlytests/vanilla_world_for_vanilla_server/worlds/world-for-testing.zip differ