# -*- mode: shell-script -*- MINECRAFT_PATH="$SERVICE_CONFIGSTORE/opt/apps/minecraft" MINECRAFT_DATA="/var/lib/minecraft" minecraft:init-binary() { local version="$1" MINECRAFT_BINARY="${MINECRAFT_PATH}/minecraft_server.${version}.jar" if ! [ -f "$MINECRAFT_BINARY" ]; then mkdir -p "${MINECRAFT_PATH}" wget "https://docker.0k.io/downloads/minecraft_server.${version}.jar" \ -O "$MINECRAFT_BINARY" fi init-config-add " $SERVICE_NAME: volumes: - \"${MINECRAFT_BINARY}:${MINECRAFT_DATA}/server.jar\" " } minecraft:init-command() { local threads="${1:-4}" mem="${2:-2048M}" init-config-add " $SERVICE_NAME: command: - java - -Xmx${mem} - -Xms${mem} - -XX:ParallelGCThreads=${threads} - -jar - server.jar - nogui " echo "eula=TRUE" > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/eula.txt" } minecraft:make-whitelist() { local whitelist="$1" { e "$whitelist" | yq -o=json \ 'to_entries | map({"uuid": .key, "name": .value})' } > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/whitelist.json" } minecraft:make-ops() { local ops="$1" { e "$ops" | yq -o=json \ 'to_entries | map({ "uuid": .value.uuid, "name": .key, "level": .value.level, "bypassesPlayerLimit": .value.bypassesPlayerLimit })' } > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/ops.json" } minecraft:make-properties() { local properties="$1" { e "$properties" | yq 'to_entries | map(.key + "=" + .value) | .[]' } > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/server.properties" } minecraft:config-hash() { local opts="$1" debug "Adding config hash to enable recreating upon config change." config_hash=$(e "$opts" | md5_compat) || exit 1 init-config-add " $SERVICE_NAME: labels: - compose.config_hash=$config_hash " }