Grieflogger 回滚插件
此 NeoForge 插件从 SQLite(默认)或 MySQL/MariaDB 读取 GriefLogger 数据,并通过命令在游戏内撤销方块操作。它针对 NeoForge 21.1.213 / Minecraft 1.21.1,且仅限服务端使用:任何记录的方块放置或破坏均可选择性撤销。类似于 CoreProtect,但适用于模组服务器。
功能
- 根据 GriefLogger 数据库(
blocks 和 containers 表连接至 materials、users、levels 表)回滚方块变化及容器/物品栏变化。
- 支持按时间窗口、可选玩家名称以及以指令执行者为中心的可选半径进行筛选。
- 在更改方块前确保目标区块已加载。
- 每刻记录进度并分批处理,以保持服务器响应速度。
- 为所有指令和通知提供权限节点(支持 LuckPerms/其他权限模组,默认操作员等级回退值为 3)。
- 广播通知游戏内启动的回滚、通过 Web UI/API 触发的回滚,以及被阻止的未授权 Web 访问尝试。
- 如果启动时没有可用的数据库连接,插件会自动禁用自身。
- 高度可配置,通过
griefloggerrollbackaddon-common.toml 设置:数据库后端/凭据、Web UI/API 绑定地址/端口/令牌、回滚批次大小、进度间隔以及未授权访问日志选项。
要求
- NeoForge 21.1.213 / Minecraft 1.21.1。
- 一个 GriefLogger 数据库(可以是 GriefLogger 写入的 SQLite DB 文件,也可以是具有 GriefLogger 模式的 MySQL/MariaDB 数据库)。
- 具有读取权限的数据库凭据(用于 MySQL/MariaDB)。
- 配置文件
config/grieflogger/griefloggerrollbackaddon-common.toml 由首次服务器启动生成(设置数据库类型/连接、Web 选项和批次大小)。
- 如果启用了 Web UI/API:需要在绑定地址(
webApiBindAddress,默认 0.0.0.0)上有一个空闲的 TCP 端口(默认 8765),如果暴露到 localhost 之外,还需要配置令牌(webApiToken)以及适当的防火墙/端口转发。
- 权限模组(例如 LuckPerms)为可选;如果没有,只有操作员(op-level 3)可以运行指令/接收通知。
安装
- 将模组 JAR 文件和您后端的 JDBC 驱动程序(SQLite、MySQL 或 MariaDB)放入服务器
mods/ 文件夹中。
- 启动服务器一次以生成
config/grieflogger/griefloggerrollbackaddon-common.toml。
- 通过
dbType 选择后端(不区分大小写,默认 SQLITE)。对于 SQLite 设置 dbFile;对于 MySQL/MariaDB 设置主机/端口/名称/用户/密码。
- 检查日志中的
[griefloggerrollbackaddon] Database connection succeeded。如果失败,插件将保持禁用状态,直到连接成功。
配置 (config/grieflogger/griefloggerrollbackaddon-common.toml)
dbType (Enum, 默认 SQLITE): 选择 SQLITE, MYSQL 或 MARIADB(不区分大小写)。
dbFile (String, 默认 config/grieflogger/grieflogger.sqlite): 当 dbType=SQLITE 时的 SQLite 数据库文件路径。
dbHost (String, 默认 localhost): MySQL/MariaDB 主机。
dbPort (Int, 默认 3306): MySQL/MariaDB 端口。
dbName (String, 默认 grieflogger): MySQL/MariaDB 数据库名称。
dbUser (String, 默认 root): MySQL/MariaDB 数据库用户。
dbPassword (String, 默认空): MySQL/MariaDB 数据库密码。
rollbackBatchSize (Int, 默认 200): 每刻处理的动作数量。
progressTickInterval (Int, 默认 20): 进度日志消息之间的刻数间隔。
webApiEnabled (Boolean, 默认 false): 启动带有 Web UI 的小型 HTTP 服务器以触发回滚。
requireApiToken (Boolean, 默认 false): 如果为 true 且 webApiToken 为空,则 Web UI/API 将被禁用;否则每个请求都必须包含令牌。
webApiBindAddress (String, 默认 0.0.0.0): Web UI/API 的绑定地址。
webApiPort (Int, 默认 8765): Web UI/API 的端口。
webApiToken (String, 默认空): Web 请求所需的可选共享密钥。仅在 localhost 上留空。
logUnauthorizedWebAccess.enabled (Boolean, 默认 false): 将未授权的 Web 请求记录到数据库表 glra_web_unauthorized 中(保留最新的 1000 条条目)。
logUnauthorizedWebAccess.logHeaders (Boolean, 默认 false): 存储未授权 Web 请求的请求头。
logUnauthorizedWebAccess.logBody (Boolean, 默认 false): 存储未授权 Web 请求的请求体(可能包含令牌)。
logUnauthorizedWebAccess.logQuery (Boolean, 默认 true): 存储未授权 Web 请求的查询字符串。
指令: /gl rollback
语法: /gl rollback t:<time> [u:<player>] [r:<radius|c<chunks>>] [i|b]
t: 必需的回滚时间窗口。支持的单位:s(秒)、m(分)、h(小时)、d(天)、M(30 天)、y(年)。示例:t:30m、t:12h、t:90s。
u: 可选的精确玩家名称(匹配 users 表)。
r: 可选半径。默认使用方块单位(r:25)。前缀 c 切换为区块单位(r:c4 = 半径为 4 个区块)。前缀 b 强制使用方块单位(r:b40)。
i 可选标志:仅回滚物品栏/容器变化(物品)。
b 可选标志:仅回滚方块变化。如果未给出 i 或 b,则两者都会回滚。
示例
/gl rollback t:2h - 回滚过去 2 小时内的所有操作。
/gl rollback t:1d u:Griefer123 - 仅该玩家在最后 24 小时内的操作。
/gl rollback t:30m r:c2 - 在执行者周围 2 个区块范围内。
/gl rollback t:10m u:User r:20 - 玩家过滤加上 20 方块半径。
/gl rollback t:45m i - 仅回滚过去 45 分钟内的物品栏/容器变化。
/gl rollback t:10m b r:15 - 仅回滚过去 10 分钟内距离 15 方块内的方块变化。
附加命令
/gl web token add <player> — 为玩家创建/替换 Web API 令牌(可在聊天中复制)。
/gl web token remove <player> — 删除玩家的 Web API 令牌。
/gl web token list [page] — 列出令牌,并提供复制到剪贴板的提示。
/gl web start / /gl web stop — 启动/停止内置的 Web UI/API(遵循配置中的开关和令牌要求)。
/gl config reload — 重新加载插件配置(griefloggerrollbackaddon-common.toml),无需重启服务器。
Web UI / HTTP API
- 在配置中使用
webApiEnabled=true 启用。默认绑定地址为 0.0.0.0:8765;可根据需要修改 webApiBindAddress/webApiPort。
- 可选的安全设置:设置
webApiToken,并通过请求头 X-Auth-Token 或表单字段 token 传递该令牌。
- 访问
http://<bind>:<port>/ 以打开一个简单的表单:时间窗口(例如 30m)、可选的玩家名、用于选择方块/物品的复选框、可选半径以及中心坐标 X/Z/Y 和维度。该表单将 POST 请求发送至 /api/rollback。
- API 端点
/api/rollback 接受 application/x-www-form-urlencoded 格式的数据,包含相同的字段,并返回一个小型 JSON 状态响应。
- 未授权的请求可记录到数据库(可配置),并将向符合条件的玩家/管理员发送可读的通知消息。
权限节点
- 默认回退机制:如果未安装权限模组,则默认为操作者等级 3。
- 节点(命名空间
griefloggerrollbackaddon):
command.rollback
command.web.token
command.web.server
command.config.reload
notify.rollback(游戏内回滚命令)
notify.web.rollback(由 Web 触发的回滚)
notify.web.unauthorized(被拦截的 Web 请求)
使用你的权限模组(如 LuckPerms)来授予/拒绝权限;否则,只有操作者(等级 3)可以运行命令并接收通知。
工作原理
- 服务器启动:立即测试数据库连接。如果失败,插件将自动禁用(无命令/事件可用)。
- 命令:
/gl rollback ... 启动一个任务:
- 在后台线程中加载自指定时间以来
blocks 和 containers 表中的匹配条目,可选择按玩家和/或半径进行过滤。
- 根据坐标重建先前的方块状态(
oldMaterialName),以便正确反转放置和破坏操作。
- 将所有动作(方块 + 库存操作)入队处理,最新优先,以便最先撤销最新的更改。
- 服务器刻:每刻处理最多
rollbackBatchSize 个动作:
BREAK(破坏)日志从数据库条目中恢复被破坏的方块。
PLACE(放置)日志恢复先前的方块状态。
- 容器日志移除已插入的物品,并添加回被取走的物品(包括存储的 NBT 数据)。如果容器已满,溢出部分将在容器位置掉落为实体。
- 未知/其他代码默认恢复到先前状态(或空气)。
- 在设置方块之前会加载目标区块。
- 进度:每
progressTickInterval 刻记录一次队列大小和处理数量。当队列为空时,任务完成。
注意事项与限制
- 如果容器在恢复物品时没有空间,溢出的物品将作为物品实体掉落在容器旁边。
- 维度映射使用
levels.name(ResourceLocation),或者对 ID 1/2/3(主世界/末地/下界)进行降级处理。
- 无效或未知的方块名称默认设为
minecraft:air,并附带警告信息。
- JDBC 驱动程序未打包在模组 JAR 中;必须单独提供。
- 较大的时间窗口可能会产生庞大的队列。请调整
rollbackBatchSize 和半径以控制服务器负载。
开发/构建
- Java 21,包含 Gradle wrapper。使用
./gradlew build(Windows 下为 gradlew.bat build)进行本地构建。
- MariaDB、MySQL 和 SQLite 驱动被声明为
localRuntime;生产环境需单独提供驱动 JAR 包。
Grieflogger Rollback Addon
This NeoForge addon reads GriefLogger data from SQLite (default) or MySQL/MariaDB and reverts block actions in-game via command. It targets NeoForge 21.1.213 / Minecraft 1.21.1 and is server-side only: any logged block placements or breaks can be undone selectively. Its like CoreProtect, but for Modded Server.
Features
- Rollback of block changes and container/inventory changes from the GriefLogger database (
blocks + containers tables with joins to materials, users, levels).
- Filters by time window, optional player name, and optional radius around the command executor.
- Ensures target chunks are loaded before changing blocks.
- Progress logging and batch processing per tick to keep the server responsive.
- Permission nodes for all commands and notifications (LuckPerms/permission mods supported, default op-level fallback 3).
- Broadcast notifications for rollbacks started in-game, rollbacks triggered via web UI/API, and blocked/unauthorized web access attempts.
- Automatically disables itself on startup if no database connection is available.
- Highly configurable via
griefloggerrollbackaddon-common.toml: database backend/credentials, web UI/API bind/port/token, rollback batch size, progress interval, and unauthorized-access logging options.
Requirements
- NeoForge 21.1.213 / Minecraft 1.21.1.
- A GriefLogger database (either the SQLite DB file GriefLogger writes, or a MySQL/MariaDB database with the GriefLogger schema).
- Database credentials with read access (for MySQL/MariaDB).
- Config file
config/grieflogger/griefloggerrollbackaddon-common.toml generated by first server start (set DB type/connection, web options, and batch sizes).
- If the web UI/API is enabled: a free TCP port (default
8765) on the bind address (webApiBindAddress, default 0.0.0.0) and, if exposed beyond localhost, a configured token (webApiToken) and appropriate firewall/forwarding.
- Permission mod (e.g., LuckPerms) optional; without one, only operators (op-level 3) can run commands/receive notifications.
Installation
- Place the mod JAR and the JDBC driver for your backend (SQLite, MySQL, or MariaDB) into the server
mods/ folder.
- Start the server once to generate
config/grieflogger/griefloggerrollbackaddon-common.toml.
- Choose the backend via
dbType (case-insensitive, default SQLITE). For SQLite set dbFile; for MySQL/MariaDB set host/port/name/user/password.
- Check the log for
[griefloggerrollbackaddon] Database connection succeeded. If it fails, the addon remains disabled until the connection works.
Configuration (config/grieflogger/griefloggerrollbackaddon-common.toml)
dbType (Enum, default SQLITE): Choose SQLITE, MYSQL, or MARIADB (case-insensitive).
dbFile (String, default config/grieflogger/grieflogger.sqlite): SQLite database file path when dbType=SQLITE.
dbHost (String, default localhost): MySQL/MariaDB host.
dbPort (Int, default 3306): MySQL/MariaDB port.
dbName (String, default grieflogger): Database name for MySQL/MariaDB.
dbUser (String, default root): Database user for MySQL/MariaDB.
dbPassword (String, default empty): Database password for MySQL/MariaDB.
rollbackBatchSize (Int, default 200): Number of actions processed per tick.
progressTickInterval (Int, default 20): How many ticks between progress log messages.
webApiEnabled (Boolean, default false): Start a small HTTP server with a web UI to trigger rollbacks.
requireApiToken (Boolean, default false): If true and webApiToken is empty, the web UI/API is disabled; otherwise every request must include the token.
webApiBindAddress (String, default 0.0.0.0): Bind address for the web UI/API.
webApiPort (Int, default 8765): Port for the web UI/API.
webApiToken (String, default empty): Optional shared secret required for web requests. Leave empty only on localhost.
logUnauthorizedWebAccess.enabled (Boolean, default false): Log unauthorized web requests to DB table glra_web_unauthorized (keeps the latest 1000 entries).
logUnauthorizedWebAccess.logHeaders (Boolean, default false): Store request headers for unauthorized web requests.
logUnauthorizedWebAccess.logBody (Boolean, default false): Store request body for unauthorized web requests (may include tokens).
logUnauthorizedWebAccess.logQuery (Boolean, default true): Store query string for unauthorized web requests.
Command: /gl rollback
Syntax: /gl rollback t:<time> [u:<player>] [r:<radius|c<chunks>>] [i|b]
t: Required time window to roll back. Supported units: s, m, h, d, M (30 days), y. Examples: t:30m, t:12h, t:90s.
u: Optional exact player name (matches the users table).
r: Optional radius. Default uses blocks (r:25). Prefix c switches to chunks (r:c4 = radius of 4 chunks). Prefix b forces blocks (r:b40).
i Optional flag: only roll back inventory/container changes (items).
b Optional flag: only roll back block changes. If neither i nor b is given, both are rolled back.
Examples
/gl rollback t:2h - Roll back all actions from the last 2 hours.
/gl rollback t:1d u:Griefer123 - Only that player's actions in the last 24h.
/gl rollback t:30m r:c2 - Within 2 chunks around the executor.
/gl rollback t:10m u:User r:20 - Player filter plus 20-block radius.
/gl rollback t:45m i - Only inventory/container changes from the last 45 minutes.
/gl rollback t:10m b r:15 - Only block changes within 15 blocks from the last 10 minutes.
Additional Commands
/gl web token add <player> — Create/replace a web API token for a player (copyable in chat).
/gl web token remove <player> — Delete a player's web API token.
/gl web token list [page] — List tokens with copy-to-clipboard hints.
/gl web start / /gl web stop — Start/stop the built-in web UI/API (honors config toggles and token requirements).
/gl config reload — Reload the addon config (griefloggerrollbackaddon-common.toml) without restarting.
Web UI / HTTP API
- Enable in config with
webApiEnabled=true. Defaults to 0.0.0.0:8765; change webApiBindAddress/webApiPort as needed.
- Optional security: set
webApiToken and pass it as header X-Auth-Token or form field token.
- Open
http://<bind>:<port>/ for a minimal form: time window (e.g., 30m), optional player, checkboxes for blocks/items, optional radius plus center X/Z/Y and dimension. The form POSTs to /api/rollback.
- The API endpoint
/api/rollback accepts application/x-www-form-urlencoded with the same fields and returns a small JSON status.
- Unauthorized requests can be logged to the database (configurable) and will notify eligible players/ops with a readable message.
Permissions
- Default fallback: op-level 3 if no permission mod is present.
- Nodes (namespace
griefloggerrollbackaddon):
command.rollback
command.web.token
command.web.server
command.config.reload
notify.rollback (in-game rollback command)
notify.web.rollback (web-triggered rollback)
notify.web.unauthorized (blocked web requests)
Use your permission mod (e.g., LuckPerms) to grant/deny; otherwise only operators (level 3) can run commands and receive notifications.
How it works
- Server start: immediately tests a DB connection. On failure, the addon disables itself (no commands/events).
- Command:
/gl rollback ... starts a job:
- Loads matching entries from
blocks and containers since the given time in a background thread, optionally filtered by player and/or radius.
- Reconstructs the previous block state per coordinate (
oldMaterialName) so placements and breaks can be inverted correctly.
- Enqueues all actions (blocks + inventory operations) for processing, newest first so the latest change is undone first.
- Server ticks: up to
rollbackBatchSize actions are processed each tick:
BREAK logs restore the broken block from the DB entry.
PLACE logs restore the previous block state.
- Container logs remove items that were inserted and add back items (including stored NBT) that were taken. If a container is full, overflow is dropped at the container position.
- Unknown/other codes fall back to restoring the previous state (or air).
- The target chunk is loaded before setting the block.
- Progress: every
progressTickInterval ticks, the queue size and processed count are logged. When the queue is empty, the job finishes.
Notes and limitations
- If a container has no space while items are restored, the overflow is dropped as item entities next to the container.
- Dimension mapping uses
levels.name (ResourceLocation) or falls back for IDs 1/2/3 (Overworld/End/Nether).
- Invalid or unknown block names default to
minecraft:air with a warning.
- The JDBC driver is not bundled in the mod JAR; it must be provided separately.
- Large time windows can produce big queues. Adjust
rollbackBatchSize and radius to control server load.
Development/Building
- Java 21, Gradle wrapper included. Build locally with
./gradlew build (or gradlew.bat build on Windows).
- MariaDB, MySQL, and SQLite drivers are declared as
localRuntime; provide the driver JAR separately for production.
评论 0
登录后参与评分
还没有评论,来抢沙发吧