事件阶段系统(后端概览)
用途:
允许 Paper 插件的事件系统在 /event start 执行后,按时间间隔在控制台中运行命令。
概述
- 事件开始
- 玩家传送
- 从配置文件中加载阶段
- 每个阶段使用 Bukkit 调度器进行安排
- 在指定的刻数时执行控制台命令
配置结构 (config.yml)
start:
phases:
- after: <ticks>
commands:
- "command 1"
- "command 2"
- after: <ticks>
commands:
- "command 3"
注意:
- phases 是一个列表(不是映射)
- 每个条目都是一个独立的时间阶段
- after = 从事件开始计算的延迟刻数
- commands = 控制台命令列表
管理员命令
-
设置中心位置
/event cornucopia center
- 将圆的中心设置为玩家当前位置
- 这是所有生成点计算的原点
-
设置半径
/event cornucopia radius <number>
示例:
/event cornucopia radius 15
- 控制从中心到每个生成点的距离
- 更大的半径 = 玩家分布更分散
- 更小的半径 = 更紧凑的角斗场
-
启用自动模式
/event mode auto
- 将生成系统从手动坐标切换到生成的圆形生成
- 必须启用此功能才能激活角斗场系统
/event mode manual
- 开始事件
/event start
行为:
- 统计在线玩家数量
- 在圆上生成 N 个均匀分布的点
- 将每个玩家传送到唯一的位置
- 生成点使用角度间距进行分配
后端逻辑
-
玩家运行:
/event start
-
EventManager.startEvent() 执行:
- 传送玩家(手动或自动圆形)
- 调用 runStartPhases()
-
runStartPhases():
遍历配置文件中的 "start.phases" 中的每个阶段:
读取:
delay = phase.after
commands = phase.commands
安排任务:
BukkitScheduler.runTaskLater(plugin, task, delay)
-
当延迟过期时:
遍历阶段命令中的每个命令:
Bukkit.dispatchCommand(CONSOLE, command)
调度行为
示例:
阶段 A:
after: 1
commands:
- "pvp disable"
阶段 B:
after: 20
commands:
- "say Event started"
结果:
第 1 刻 -> PVP 禁用
第 20 刻 -> 广播消息
重要提示:
- 延迟是相对于事件开始的
- 阶段不会自动连锁执行
- 每个阶段独立调度
常见错误修复
错误(无效的 YAML):
start:
phases:
after: 1
commands:
after: 20
commands:
原因:
正确示例:
start:
phases:
- after: 1
commands:
- "clear"
- after: 20
commands:
- "say This is 1 second after the event start!"
EVENT PHASE SYSTEM (BACKEND OVERVIEW)
PURPOSE:
Allows a Paper plugin event system to execute console commands at timed intervals after /event start.
SUMMARY
- Event starts
- Players teleported
- Phases loaded from config
- Each phase scheduled using Bukkit scheduler
- Console commands executed at defined ticks
CONFIG STRUCTURE (config.yml)
start:
phases:
- after: <ticks>
commands:
- "command 1"
- "command 2"
- after: <ticks>
commands:
- "command 3"
NOTES:
- phases is a LIST (not a map)
- each entry is an independent timed phase
- after = delay in ticks from event start
- commands = list of console commands
ADMIN COMMANDS
-
SET CENTER POSITION
/event cornucopia center
- Sets the center of the circle to the player's current location
- This is the origin point for all spawn calculations
-
SET RADIUS
/event cornucopia radius <number>
Example:
/event cornucopia radius 15
- Controls distance from center to each spawn point
- Larger radius = more spread out players
- Smaller radius = tighter cornucopia
-
ENABLE AUTO MODE
/event mode auto
- Switches spawn system from manual coordinates to generated circle spawns
- Required for cornucopia system to activate
/event mode manual
- Disables circle generation and uses saved spawn points instead
- START EVENT
/event start
BEHAVIOR:
- Counts online players
- Generates N evenly spaced points on a circle
- Teleports each player to a unique position
- Spawns are distributed using angular spacing
BACKEND
-
Player runs:
/event start
-
EventManager.startEvent() executes:
- Teleports players (manual or auto circle)
- Calls runStartPhases()
-
runStartPhases():
FOR each phase in config "start.phases":
read:
delay = phase.after
commands = phase.commands
schedule task:
BukkitScheduler.runTaskLater(plugin, task, delay)
-
When delay expires:
FOR each command in phase.commands:
Bukkit.dispatchCommand(CONSOLE, command)
SCHEDULING BEHAVIOR
Example:
phase A:
after: 1
commands:
- "pvp disable"
phase B:
after: 20
commands:
- "say Event started"
RESULT:
tick 1 -> pvp disabled
tick 20 -> message broadcast
IMPORTANT:
- delays are relative to EVENT START
- phases do NOT chain automatically
- each phase schedules independently
COMMON ERRORS FIXED
WRONG (invalid YAML):
start:
phases:
after: 1
commands:
after: 20
commands:
CAUSE:
- duplicate keys
- not a list structure
CORRECT EXAMPLE:
start:
phases:
- after: 1
commands:
- "clear"
- after: 20
commands:
- "say This is 1 second after the event start!"
评论 0
登录后参与评分
还没有评论,来抢沙发吧