找回密码
 立即注册

QQ登录

只需一步,快速开始

[1.16-1.19] ServerTap - 通过API获取玩家信息和操作服务器

Cnzw 2024-5-21 19:03:36 编程 阅读 108 来自 中国
服务器插件
中文名称: ServerTap
英文名称: ServerTap
插件来源: 转载
适用服务端: Spigot Paper Catserver Purpur 
插件类型: 前置API
语言支持: 英文 
适用版本: 1.16.x 1.17.x 1.18.x 1.19.x 1.20.x 
前置插件/mod:
下载地址: https://www.spigotmc.org/resources/servertap.79031/
原贴地址: https://github.com/servertap-io/servertap/releases

马上登录/注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 Cnzw 于 2024-5-23 18:33 编辑

upload_2021-12-16_17-2-4.png




插件简介

ServerTap 是一个支持 Bukkit、Spigot 和 Paper 服务器的 REST API 插件。 它允许通过 HTTP、Webhooks 和 Websockets 与服务器进行交互。

@Cnzw
该插件很适合用于 QQ 机器人和各种状态监测网页。

安装要求

  • Bukkit/Spigot/Paper 或其分支:1.16.5 或更高版本
  • Java:16 或更高版本
  • 无前置插件


如何使用

将本插件文件复制到服务器的 plugins 文件夹中即完成了安装。

然后可以使用 CurlPostman 或任意浏览器来访问 API。

例如,查询有关服务器信息的 API:
$ curl http: //localhost:4567/v1/server
{
    "name": "Paper",
    "motd": "This is my MOTD",
    "version": "git-Paper-89 (MC: 1.15.2)",
    "bukkitVersion": "1.15.2-R0.1-SNAPSHOT",
    "health": {
        "cpus": 4,
        "uptime": 744,
        "totalMemory": 2010644480,
        "maxMemory": 2010644480,
        "freeMemory": 1332389360
    },
    "bannedIps": [],
    "bannedPlayers": [{
        "target": "phybros",
        "source": "Server"
    }]
}

或查询在线玩家列表的 API:
$ curl http://localhost:4567/v1/players
[{
    "uuid": "55f584e4-f095-48e0-bb8a-eb5c87ffe494",
    "displayName": "phybros",
    "address": "localhost",
    "port": 58529,
    "exhaustion": 3.5640976,
    "exp": 0.45454547,
    "whitelisted": false,
    "banned": false,
    "op": true
}]

API 文档

插件自带 API 文档。可以在 http://服务器IP:4567/swagger 查看完整的 API 文档并且直接调试。

@Cnzw
我直接导出了API接口,在这里查看

API 验证

plugins/ServerTap/config.yml 文件中进行配置:
useKeyAuth: true
key: some-long-super-random-string
然后,在需要在请求头(Header)中包含 key 和对应的密钥。

WebHook

ServerTap 可以在服务器上发生事件时发送 WebHook 消息。

要使用 WebHook,需要配置 plugins/ServerTap/config.yml 文件:
webhooks:
  default:
    listener: "https://your-webhook-target.com/whatever"
    events:
    - PlayerJoin
    - PlayerQuit
目前可用的事件有:
  • PlayerJoin
  • PlayerDeath
  • PlayerChat
  • PlayerKick
  • PlayerQuit


WebHook 通过 POST 请求发送 JSON 数据:
{
  "player": {
    "uuid": "55f584e4-f095-48e0-bb8a-eb5c87ffe494",
    "displayName": "phybros",
    "address": "localhost",
    "port": 52809,
    "exhaustion": 0,
    "exp": 0.5714286,
    "whitelisted": true,
    "banned": false,
    "op": true
  },
  "joinMessage": "§ephybros joined the game",
  "eventType": "PlayerJoin"
}

Websockets

ServerTap 支持正向 WebSocket ,能够实时接收服务器日志。

一旦连接,服务器上通过正常日志过滤器的任何服务器日志行都会以类似这样的 JSON 对象形式通过 WebSocket 发送:
{
  "message": "§6/version: §fGets the version of this server including any plugins in use",
  "timestampMillis": 1631834015918,
  "loggerName": "",
  "level": "INFO"
}
WebSocket 地址是 ws://服务器IP:4567/v1/ws/console

最后 1000 条服务器日志消息将缓存并在客户端连接时发送。您可以通过更改 config.yml 中的 websocketConsoleBuffer 来配置服务器日志缓冲区的大小。

使用统计




更多

本插件已加入 插件搬运计划,会定期同步外网资源的更新。

搬运催更 & 问题反馈快速响应问卷 或在下方留下评论。
(1)
CnzwLv2-铁粒

相关推荐

参与人数 1人气 +1 钻石 +2 收起 理由
Ti_Avanti + 1 + 2

查看全部评分总评分 : 人气 +1 钻石 +2

帖子地址: 

发表回复

使用道具 举报