# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: MCBE Server
spec:
    description: Minecraft Bedrock Edition Server with automatic version management and easy configuration
    icon: https://builditapp.com/wp-content/uploads/2022/05/Grass-Block-1.svg
    readme: |
        ### Bedrock Edition (`itzg/minecraft-bedrock-server`)

        This image supports **automatic mapping**: any key in `server.properties` can be used as an environment variable by converting it to **UPPERCASE** and replacing hyphens `-` with underscores `_`.

        Bedrock Edition variables are relatively fewer, mainly centering around the official BDS software configuration.

        #### 1. Container & Basic Control

        | Variable | Values | Description |
        | :--- | :--- | :--- |
        | **`EULA`** | `TRUE` | **Required**. |
        | **`VERSION`** | `LATEST`, `1.20.50` | Specify Bedrock version. |
        | **`PREVIEW`** | `true`, `false` | Set to `true` to install the Preview/Beta version. |
        | **`OPS`** | `XUID1,XUID2` | Comma-separated list of XUIDs to automatically op (console setup recommended). |
        | **`ALLOW_LIST_USERS`**| `Name1,Name2` | List of names to allow joining. |
        | **`UID` / `GID`** | `1000` | Specify user ID/group ID. |
        | **`TZ`** | `Asia/Shanghai` | Container timezone. |

        #### 2. `server.properties` Mapping (Bedrock Specific)
        These variables directly modify `server.properties`. If not listed, you can still add them using the "UPPERCASE+underscore" rule.

        | Environment Variable | server.properties | Values | Description |
        | :--- | :--- | :--- | :--- |
        | `SERVER_NAME` | server-name | String | Server title message. |
        | `LEVEL_NAME` | level-name | String | World folder name. |
        | `GAMEMODE` | gamemode | `survival`, `creative`, `adventure` | Game mode. |
        | `DIFFICULTY` | difficulty | `peaceful`, `easy`, `normal`, `hard` | Difficulty. |
        | `ALLOW_CHEATS` | allow-cheats | `true`, `false` | **Critical**: Allow cheat commands. |
        | `ONLINE_MODE` | online-mode | `true`, `false` | Xbox login verification. |
        | `MAX_PLAYERS` | max-players | `10` | Max players. |
        | `VIEW_DISTANCE` | view-distance | `32` | View distance (Bedrock usually allows larger values). |
        | `TICK_DISTANCE` | tick-distance | `4` - `12` | Simulation distance (affects Redstone/mob spawning). |
        | `PLAYER_IDLE_TIMEOUT`| player-idle-timeout| `30` | Idle kick timeout (minutes). |
        | `TEXTUREPACK_REQUIRED`| texturepack-required | `true`, `false` | Force players to download resource packs. |
        | `CONTENT_LOG_FILE_ENABLED`| content-log-file-enabled | `true`, `false` | Log content errors. |
        | `COMPRESSION_THRESHOLD`| compression-threshold | `1` | Network packet compression threshold (0-65535). |
        | `SERVER_AUTHORITATIVE_MOVEMENT`| server-authoritative-movement | `client-auth`, `server-auth` | Movement authority (anti-cheat). |

        #### 3. Run commands in the server console (`send-command`)
        Bedrock Dedicated Server does not use `rcon-cli` like Java Edition. This image provides a helper script named `send-command` to send commands to the server console.

        **How to use in Zeabur:**
        1. Open the Zeabur service console page
        2. Click the **Command** button
        3. Run commands using this format: `send-command <command> [args...]`

        **Examples:**
        - `send-command list`
        - `send-command op xxxx`
        - `send-command gamerule dofiretick false`

        Note: For cheat-related commands, ensure `ALLOW_CHEATS=true` if required by the server.

        #### 4. Start the container without starting the server (for file management)
        If you want to use Zeabur’s file manager without launching the Bedrock server, you can keep the container running with a sleep command.

        1. Go to Zeabur service settings
        2. Find the **Startup Command** field
        3. Set it to `sleep infinity` (or `sleep 365d`)
        4. Redeploy/restart the service, then manage files under `/data`

        After finishing file operations, restore/clear the startup command so the server can start normally.

        #### 5. Find the Server Address and Port
        Zeabur automatically forwards UDP ports but may not display them in the UI. You need to check the forwarding rules via SSH.

        **Steps:**
        1. Connect to the service via **SSH**.
        2. Run this command: `kubectl get services --all-namespaces`
        3. Find your service in the list (look for `19132/UDP`). Check the `PORT(S)` column.
           - Example: `19132:31234/UDP`
           - The number after the colon (**31234**) is your public connection port.
    services:
        - name: MCBE Server
          icon: https://builditapp.com/wp-content/uploads/2022/05/Grass-Block-1.svg
          template: PREBUILT_V2
          spec:
            id: mcbe-server
            source:
                image: itzg/minecraft-bedrock-server:latest
            ports:
                - id: minecraft
                  port: 19132
                  type: UDP
            volumes:
                - id: data
                  dir: /data
            env:
                ALLOW_CHEATS:
                    default: "true"
                EULA:
                    default: "TRUE"
                TZ:
                    default: Asia/Shanghai
                VERSION:
                    default: LATEST
            portForwarding:
                enabled: true
localization:
    zh-CN:
        description: Minecraft 基岩版服务器，支持自动版本管理和简易配置
        readme: |
            ### 基岩版 (`itzg/minecraft-bedrock-server`)

            此镜像支持**自动映射**机制：任何 `server.properties` 中的键，只要转为**大写**并把横杠 `-` 换成下划线 `_`，即可作为环境变量使用。

            基岩版变量相对较少，主要围绕官方 BDS 软件的配置。

            #### 1. 容器与基础控制

            | 变量名 | 可选值 | 说明 |
            | :--- | :--- | :--- |
            | **`EULA`** | `TRUE` | **必须**。 |
            | **`VERSION`** | `LATEST`, `1.20.50` | 指定基岩版版本。 |
            | **`PREVIEW`** | `true`, `false` | 设为 `true` 以安装预览版/测试版 (Preview/Beta)。 |
            | **`OPS`** | `XUID1,XUID2` | 自动设置为管理员的 XUID 列表 (建议用控制台设置)。 |
            | **`ALLOW_LIST_USERS`**| `Name1,Name2` | 允许进入服务器的玩家名称列表。 |
            | **`UID` / `GID`** | `1000` | 指定运行用户的 ID/组 ID。 |
            | **`TZ`** | `Asia/Shanghai` | 容器时区。 |

            #### 2. `server.properties` 映射 (Bedrock 专用)
            以下变量直接修改 `server.properties`。如果这里没列出，你依然可以按照"大写+下划线"规则自行添加。

            | 环境变量 | 对应 server.properties | 可选值 | 说明 |
            | :--- | :--- | :--- | :--- |
            | `SERVER_NAME` | server-name | 字符串 | 服务器标题信息。 |
            | `LEVEL_NAME` | level-name | 字符串 | 存档文件夹名称。 |
            | `GAMEMODE` | gamemode | `survival`, `creative`, `adventure` | 模式。 |
            | `DIFFICULTY` | difficulty | `peaceful`, `easy`, `normal`, `hard` | 难度。 |
            | `ALLOW_CHEATS` | allow-cheats | `true`, `false` | **关键**：是否允许作弊指令。 |
            | `ONLINE_MODE` | online-mode | `true`, `false` | Xbox 登录验证。 |
            | `MAX_PLAYERS` | max-players | `10` | 最大人数。 |
            | `VIEW_DISTANCE` | view-distance | `32` | 视距 (基岩版通常可设置更大)。 |
            | `TICK_DISTANCE` | tick-distance | `4` - `12` | 模拟距离 (影响红石/刷怪范围)。 |
            | `PLAYER_IDLE_TIMEOUT`| player-idle-timeout| `30` | 挂机踢出时间 (分钟)。 |
            | `TEXTUREPACK_REQUIRED`| texturepack-required | `true`, `false` | 强制玩家下载资源包。 |
            | `CONTENT_LOG_FILE_ENABLED`| content-log-file-enabled | `true`, `false` | 是否记录内容错误日志。 |
            | `COMPRESSION_THRESHOLD`| compression-threshold | `1` | 网络包压缩阈值 (0-65535)。 |
            | `SERVER_AUTHORITATIVE_MOVEMENT`| server-authoritative-movement | `client-auth`, `server-auth` | 移动判定方式 (防作弊)。 |

            #### 3. 在控制台执行服务器命令（`send-command`）
            基岩版与 Java 版不同：这里不使用 `rcon-cli`，而是通过镜像内置的 `send-command` 将指令发送到服务器控制台。

            **使用方法：**
            1. 在 Zeabur 项目中进入该服务的控制台页面
            2. 点击控制台工具栏中的 **命令（Command）** 按钮
            3. 按以下格式输入：`send-command <命令> [参数...]`

            **示例：**
            - `send-command list`
            - `send-command op xxxx`
            - `send-command gamerule dofiretick false`

            提示：若要执行作弊相关指令，请按需设置 `ALLOW_CHEATS=true`。

            #### 4. 仅启动容器而不启动服务器（用于文件管理）
            当你只想使用 Zeabur 的文件管理器修改配置或上传文件，但暂时不需要启动基岩版服务器时，可以让容器保持空转状态。

            **配置步骤：**
            1. 前往 Zeabur 中该服务的 **设置（Settings）** 页面
            2. 找到 **启动命令（Startup Command）** 配置项
            3. 输入 `sleep infinity`（如环境要求可改用 `sleep 365d`）
            4. 保存并重新部署/重启服务
            5. 此时容器会保持在线但不启动服务器，你可以安全地通过文件管理器操作 `/data` 目录

            **注意：** 文件操作完成后，务必清空或恢复启动命令为默认值，否则下次重启时服务器仍不会自动启动。

            #### 5. 获取服务器公网 UDP 端口
            由于 Zeabur 控制台目前暂不直接显示 UDP 端口映射，你需要通过 SSH 查询系统转发规则来获取真实的公网连接端口。

            **查询步骤：**
            1. 通过 SSH 连接到服务器。
            2. 执行以下命令：`kubectl get services --all-namespaces`
            3. 在输出列表中找到你的服务（通常标记为 `19132/UDP`）。查看 `PORT(S)` 列，格式如 `19132:31234/UDP`，其中冒号后面的 **31234** 即为你的公网连接端口。
    zh-TW:
        description: Minecraft 基岩版伺服器，支援自動版本管理及簡易設定
        readme: |
            ### 基岩版 (`itzg/minecraft-bedrock-server`)

            此映像支援**自動映射**機制：任何 `server.properties` 中的鍵，只要轉為**大寫**並把橫槓 `-` 換成底線 `_`，即可作為環境變數使用。

            基岩版變數相對較少，主要圍繞官方 BDS 軟體的設定。

            #### 1. 容器與基礎控制

            | 變數名 | 可選值 | 說明 |
            | :--- | :--- | :--- |
            | **`EULA`** | `TRUE` | **必須**。 |
            | **`VERSION`** | `LATEST`, `1.20.50` | 指定基岩版版本。 |
            | **`PREVIEW`** | `true`, `false` | 設定為 `true` 以安裝預覽版/測試版 (Preview/Beta)。 |
            | **`OPS`** | `XUID1,XUID2` | 自動設定為管理員的 XUID 列表 (建議用控制台設定)。 |
            | **`ALLOW_LIST_USERS`**| `Name1,Name2` | 允許進入伺服器的玩家名稱列表。 |
            | **`UID` / `GID`** | `1000` | 指定執行使用者的 ID/組 ID。 |
            | **`TZ`** | `Asia/Shanghai` | 容器時區。 |

            #### 2. `server.properties` 映射 (Bedrock 專用)
            以下變數直接修改 `server.properties`。如果這裡沒列出，你依然可以按照「大寫+底線」規則自行新增。

            | 環境變數 | 對應 server.properties | 可選值 | 說明 |
            | :--- | :--- | :--- | :--- |
            | `SERVER_NAME` | server-name | 字串 | 伺服器標題資訊。 |
            | `LEVEL_NAME` | level-name | 字串 | 存檔資料夾名稱。 |
            | `GAMEMODE` | gamemode | `survival`, `creative`, `adventure` | 模式。 |
            | `DIFFICULTY` | difficulty | `peaceful`, `easy`, `normal`, `hard` | 難度。 |
            | `ALLOW_CHEATS` | allow-cheats | `true`, `false` | **關鍵**：是否允許作弊指令。 |
            | `ONLINE_MODE` | online-mode | `true`, `false` | Xbox 登入驗證。 |
            | `MAX_PLAYERS` | max-players | `10` | 最大人數。 |
            | `VIEW_DISTANCE` | view-distance | `32` | 視距 (基岩版通常可設定更大)。 |
            | `TICK_DISTANCE` | tick-distance | `4` - `12` | 模擬距離 (影響紅石/刷怪範圍)。 |
            | `PLAYER_IDLE_TIMEOUT`| player-idle-timeout| `30` | 掛機踢出時間 (分鐘)。 |
            | `TEXTUREPACK_REQUIRED`| texturepack-required | `true`, `false` | 強制玩家下載資源包。 |
            | `CONTENT_LOG_FILE_ENABLED`| content-log-file-enabled | `true`, `false` | 是否記錄內容錯誤日誌。 |
            | `COMPRESSION_THRESHOLD`| compression-threshold | `1` | 網路封包壓縮閾值 (0-65535)。 |
            | `SERVER_AUTHORITATIVE_MOVEMENT`| server-authoritative-movement | `client-auth`, `server-auth` | 移動判定方式 (防作弊)。 |

            #### 3. 在控制台執行伺服器指令（`send-command`）
            基岩版與 Java 版不同：這裡不使用 `rcon-cli`，而是透過映像內建的 `send-command` 將指令送到伺服器控制台。

            **使用方法：**
            1. 在 Zeabur 專案中進入該服務的控制台頁面
            2. 點擊控制台工具列中的 **命令（Command）** 按鈕
            3. 依以下格式輸入：`send-command <指令> [參數...]`

            **範例：**
            - `send-command list`
            - `send-command op xxxx`
            - `send-command gamerule dofiretick false`

            提示：若要執行作弊相關指令，請按需設定 `ALLOW_CHEATS=true`。

            #### 4. 僅啟動容器而不啟動伺服器（用於檔案管理）
            當你只想使用 Zeabur 的檔案管理器修改設定或上傳檔案，但暫時不需要啟動基岩版伺服器時，可以讓容器保持空轉狀態。

            **設定步驟：**
            1. 前往 Zeabur 中該服務的 **設定（Settings）** 頁面
            2. 找到 **啟動命令（Startup Command）** 欄位
            3. 輸入 `sleep infinity`（如環境要求可改用 `sleep 365d`）
            4. 儲存並重新部署/重啟服務
            5. 此時容器會保持在線但不啟動伺服器，你可以安全地透過檔案管理器操作 `/data` 目錄

            **注意：** 檔案操作完成後，務必清空或恢復啟動命令為預設值，否則下次重啟時伺服器仍不會自動啟動。

            #### 5. 獲取伺服器公網 UDP 連接埠
            由於 Zeabur 控制台目前暫不直接顯示 UDP 連接埠映射，你需要透過 SSH 查詢系統轉發規則來獲取真實的公網連接埠。

            **查詢步驟：**
            1. 透過 SSH 連線到伺服器。
            2. 執行以下指令：`kubectl get services --all-namespaces`
            3. 在輸出列表中找到你的服務（通常標記為 `19132/UDP`）。查看 `PORT(S)` 欄位，格式如 `19132:31234/UDP`，其中冒號後面的 **31234** 即為你的公網連接埠。
