BuildContest 插件
BuildContest 是一个 Velocity 插件,用于简化建筑竞赛中为每个团队设立专用服务器的设置流程。该插件使用 Docker Compose 启动子服务器,并自动将玩家转移至对应的子服务器参与竞赛。团队配置和服务器信息会持久化存储。
功能特性
- 自动创建子服务器:通过 HTTP API 调用 Docker Compose 创建团队服务器,并将其注册到 Velocity。
- 自动玩家转移:当玩家加入主服务器时,会自动被转移到其所属的子服务器。
- 权限控制:使用 Bearer Token 对 HTTP 请求进行身份验证。
- 防止重复参与:在添加团队时,如果某玩家已存在于其他团队,则无法加入其他团队。
安装步骤
-
准备环境
- 安装 Velocity 代理服务器。
- 确保已安装并正确配置 Docker 和 Docker Compose。
-
创建 Minecraft 竞赛服务器镜像(子服务器)
- 建议使用 Little Wrench 作为服务器基础。
- 将端口设置为
25565,并确保通过代理可以正确访问,包括正确的 forwarding-mode 设置。
- 创建一个用于构建服务器镜像的 Dockerfile。
- 构建镜像,例如执行
docker build -t minecraft-contest:latest .
- 创建一个
docker-compose.yml 文件以启动子服务器。
-
下载插件
-
配置插件
- 将插件 jar 文件放入 Velocity 的
plugins/ 目录中。
- 首次启动 Velocity 服务器以生成配置文件,然后停止服务器进行调整。
-
配置文件说明
- 修改
plugins/BuilderContest/ 目录下的 config.yml 以设置端口和其他参数。
- 将
docker-compose-default.yml 放置在插件目录中,作为启动子服务器的模板。
-
启动服务器
- 启动服务器,并从生成的
config.yml 中获取 bearer-token。
配置文件说明
config.yml
ktor:
http-port: 8080 # HTTP 服务端口。
port-start: 30000 # 子服务器的起始端口。
bearer-token: # Bearer Token;首次使用时请留空。
allow-host: "*" # 允许的宿主地址。
docker-compose-default.yml 示例
- 使用
#SERVER_NAME_PLACEHOLDER 作为 Docker 容器名称的占位符。
- 使用
#SERVER_PORT_PLACEHOLDER 作为端口的占位符。
version: '3.8'
services:
minecraft_server:
image: minecraft-contest:latest
container_name: "#SERVER_NAME_PLACEHOLDER"
ports:
- #SERVER_PORT_PLACEHOLDER:25565
volumes:
# 将本地世界目录挂载到容器内的指定路径
- ./worlds/#SERVER_NAME_PLACEHOLDER/world:/app/world
environment:
EULA: "TRUE"
restart: unless-stopped
使用说明
HTTP API
- 插件启动后,默认会在端口
8080 上启动一个 HTTP 服务。
- 关键 API 端点:
- 添加团队:
POST /team/add,需要 Bearer Token 认证,载荷字段包括 teamId、teamName 和 members。
请求示例
curl --location --request POST 'http://localhost:8080/team/add' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer sSCj4piDoEfV2zIo_C8lD7S4ul0YlVOyBr2BkKpdsTI (从 config.yml 中获取)' \
--data-raw '{
"teamId": "team_1",
"teamName": "Team 1",
"members": ["Hanamizu_", "user1"]
}'
BuildContest Plugin
BuildContest is a Velocity plugin that simplifies the setup of dedicated servers for each team in a building contest. The plugin uses Docker Compose to start sub-servers and automatically transfers players to their respective sub-servers for the contest. Team configurations and server information are persistently stored.
Features
- Automatic Sub-Server Creation: Create team servers using HTTP API calls with Docker Compose, and register them with Velocity.
- Automatic Player Transfer: Players are automatically transferred to their corresponding sub-servers when joining the main server.
- Permission Control: Authenticate HTTP requests using Bearer Token.
- Prevent Duplicate Participation: When adding a team, if a player already exists in another team, they cannot join other teams.
Installation Steps
-
Prepare the Environment
- Install Velocity proxy server.
- Ensure Docker and Docker Compose are installed and properly configured.
-
Create a Minecraft Contest Server Image (Sub-Server)
- It's recommended to use Little Wrench as the server base.
- Set the port to
25565 and ensure it can be accessed correctly via the proxy, including proper forwarding-mode settings.
- Create a Dockerfile for building the server image.
- Build the image, e.g.,
docker build -t minecraft-contest:latest .
- Create a
docker-compose.yml file for starting the sub-server.
-
Download the Plugin
-
Configure the Plugin
- Place the plugin jar file in the
plugins/ directory of Velocity.
- Start the Velocity server once to generate the configuration files, then stop the server to adjust settings.
-
Configure Files
- Modify
config.yml in the plugins/BuilderContest/ directory to set up ports and other settings.
- Place
docker-compose-default.yml in the plugin directory as the template for starting sub-servers.
-
Start the Server
- Start the server and retrieve the
bearer-token from the generated config.yml.
Configuration File Description
config.yml
ktor:
http-port: 8080 # HTTP service port.
port-start: 30000 # Starting port for sub-servers.
bearer-token: # Bearer Token; leave this empty on first use.
allow-host: "*" # Allowed host addresses.
docker-compose-default.yml Example
- Use
#SERVER_NAME_PLACEHOLDER as the placeholder for the Docker container name.
- Use
#SERVER_PORT_PLACEHOLDER as the placeholder for the port.
version: '3.8'
services:
minecraft_server:
image: minecraft-contest:latest
container_name: "#SERVER_NAME_PLACEHOLDER"
ports:
- #SERVER_PORT_PLACEHOLDER:25565
volumes:
# Mount the local world directory to the specified path in the container
- ./worlds/#SERVER_NAME_PLACEHOLDER/world:/app/world
environment:
EULA: "TRUE"
restart: unless-stopped
Usage Instructions
HTTP API
- After the plugin starts, an HTTP service will be launched on port
8080 by default.
- Key API endpoint:
- Add Team:
POST /team/add, requires Bearer Token authentication, with teamId, teamName, and members as payload fields.
Example Request
curl --location --request POST 'http://localhost:8080/team/add' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer sSCj4piDoEfV2zIo_C8lD7S4ul0YlVOyBr2BkKpdsTI (Retrieve this from config.yml)' \
--data-raw '{
"teamId": "team_1",
"teamName": "Team 1",
"members": ["Hanamizu_", "user1"]
}'
评论 0
登录后参与评分
还没有评论,来抢沙发吧