Minecraft 服务器公屏聊天的只读接口
最近的公屏消息,按时间正序返回。
| 参数 | 说明 |
|---|---|
limit | 要多少条,默认 300,最多 1000 |
before | 只要比这个时间戳(毫秒)更早的,用来往上翻页 |
{
"ok": true,
"chat": [
{ "t": 1793173903582, "from": "Six_eggs", "text": "...", "type": "chat" }
],
"last": 1793173903582,
"total": 5000
}
| 字段 | 说明 |
|---|---|
t | 毫秒时间戳 |
from | 玩家名(游戏昵称,不含 QQ 号) |
text | 消息内容 |
type | chat 普通发言 / join 上线 / leave 下线 / death 死亡 |
last | 本次最后一条的时间戳,下次当 before 用 |
total | 服务端归档总条数 |
SSE 实时流,新消息一产生就推一条 data: {...},字段同 /api/chat 里的单条。适合做实时看板。
// 浏览器 const es = new EventSource("https://api.trinitymc.site/events"); es.onmessage = e => console.log(JSON.parse(e.data));
存活检查。{"ok":true,"clients":0,"feed":300},clients 是当前 SSE 连接数。
取玩家头像(服务端代理,不暴露上游地址)。
浏览器里直接 fetch,跨域已放开。
// 拿最近 20 条 const r = await fetch("https://api.trinitymc.site/api/chat?limit=20"); const { chat } = await r.json(); chat.forEach(m => console.log(m.from, ":", m.text)); // 往上翻页(拿比 last 更早的 20 条) const r2 = await fetch(`https://api.trinitymc.site/api/chat?limit=20&before=${chat[0].t}`);
429。轮询别太勤,实时需求请用 /events。完整聊天墙网页在 msg.trinitymc.site
三一社区 · trinitymc.site