services:
  nationsglory-modded:
    image: itzg/minecraft-server:java7
    container_name: mc-nationsglory
    restart: unless-stopped
    network_mode: "host"
    
    env_file:
      - ../shared.env
      - .env
    environment:
      # IMPORTANT: Ne pas utiliser TYPE, utiliser CUSTOM_SERVER directement
      # Cela force le conteneur à utiliser le JAR local au lieu de télécharger
      SERVER_PORT: ${SERVER_PORT:-25565}
      RCON_PORT: ${RCON_PORT:-25575}
      RCON_PASSWORD: ${RCON_PASSWORD:-minecraft}
      ENABLE_RCON: ${ENABLE_RCON:-true}
      SKIP_HEALTH_CHECK: "true"
      ACCEPT_EULA: "TRUE"
      EULA: "TRUE"
      ONLINE_MODE: ${ONLINE_MODE:-FALSE}
      DIFFICULTY: ${DIFFICULTY:-1}
      GAMEMODE: ${GAMEMODE:-1}
      LEVEL_TYPE: ${LEVEL_TYPE:-FLAT}
      MEMORY: ${MEMORY:-2G}
      INIT_MEMORY: ${INIT_MEMORY:-1G}
      JVM_OPTS: ${JVM_OPTS:--XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200}
      # CRITICAL: Désactiver le download automatique
      SKIP_SERVER_PROPERTIES: "false"
      # Pointer directement au JAR local
      CUSTOM_SERVER: "/data/mcpc.jar"
    
    entrypoint: []
    command:
      - sh
      - -c
      - |
        cd /data
        # Copier le template server.properties si inexistant
        if [ ! -f server.properties ]; then
          cp server.properties.template server.properties 2>/dev/null || true
        fi
        exec java -Xms1G -Xmx2G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -jar mcpc.jar nogui
    
    volumes:
      - .:/data
    
    deploy:
      resources:
        limits:
          memory: 3G
        reservations:
          memory: 1G
    
    ulimits:
      nofile:
        soft: 65535
        hard: 65535
