services:
  mc:
    image: itzg/minecraft-server
    pull_policy: daily
    tty: true
    stdin_open: true
    depends_on:
      restore-backup:
        condition: service_completed_successfully
    user: "${UID}:${GID}"
    ports:
      - "${SERVER_PORT}:25565"
      - "${VOICE_CHAT_PORT}:24454/udp"
      - "${RCON_PORT}:25585"
      - "${BLUEMAP_PORT}:8080"
      - "${GEYSER_PORT}:19132/udp"
    environment:
      VERSION: "1.21.4"
      ANNOUNCE_PLAYER_ACHIEVEMENTS: false
      EULA: "TRUE"
      TYPE: "FOLIA"
      PLUGINS: |
        https://hangarcdn.papermc.io/plugins/henkelmax/SimpleVoiceChat/versions/bukkit-2.6.20/PAPER/voicechat-bukkit-2.6.20.jar
        https://download.geysermc.org/v2/projects/geyser/versions/latest/builds/latest/downloads/spigot
        https://download.geysermc.org/v2/projects/floodgate/versions/latest/builds/latest/downloads/spigot
        https://hangarcdn.papermc.io/plugins/froobynooby/SeeMore/versions/1.0.2/PAPER/SeeMore-1.0.2.jar
        https://hangarcdn.papermc.io/plugins/ViaVersion/ViaVersion/versions/5.11.0/PAPER/ViaVersion-5.11.0.jar
        https://hangarcdn.papermc.io/plugins/SRTeam/SkinsRestorer/versions/15.12.4/PAPER/SkinsRestorer.jar
        https://hangarcdn.papermc.io/plugins/jmp/squaremap/versions/1.3.14/PAPER/squaremap-paper-mc26.2-1.3.14.jar
      COPY_CONFIG_DEST: "/data"
      ONLINE_MODE: false
      RCON_PASSWORD: ${RCON_PASSWORD}
      RCON_PORT: ${RCON_PORT}
      MAX_MEMORY: "4G"
      SPAWN_PROTECTION: 0
      ENABLE_WHITELIST: true
    volumes:
      - ./mc-data:/data
      - ./mcserver:/config
      - ./plugins:/plugins
    restart: unless-stopped
    networks:
      - mc-network
  restore-backup:
    # Same image as mc, but any base image with bash and tar will work
    image: itzg/mc-backup
    restart: "no"
    entrypoint: restore-rsync-backup
    volumes:
      # Must be same mount as mc service, needs to be writable
      - ./mc-data:/data
      # Must be same mount as backups service, but can be read-only
      - ./mc-backups:/backups:ro
    networks:
      - mc-network
  backups:
    image: itzg/mc-backup
    depends_on:
      mc:
        condition: service_healthy
    restart: unless-stopped
    environment:
      BACKUP_INTERVAL: "24h"
      RCON_HOST: mc
      # since this service waits for mc to be healthy, no initial delay is needed
      INITIAL_DELAY: 0
      PRUNE_BACKUPS_COUNT: 3
      RCON_PASSWORD: ${RCON_PASSWORD}
      RCON_PORT: 25585
      BACKUP_METHOD: "rsync"
    volumes:
      - ./mc-data:/data:ro
      - ./mc-backups:/backups
    networks:
      - mc-network
  broadcaster:
    image: ghcr.io/mcxboxbroadcast/standalone:latest
    user: "${UID}:${GID}"
    depends_on:
      #proxy:
      #  condition: service_healthy
      mc:
        condition: service_healthy
    volumes:
      - ./mcxboxbroadcast/config:/opt/data/config
    networks:
      - mc-network
    restart: unless-stopped

networks:
  mc-network:
    driver: bridge