Skip to content

fix:itemdecoration和worldedit - #1187

Merged
THEXN merged 2 commits into
UnrealMultiple:masterfrom
THEXN:fix/itemdecoration-chat
Jul 27, 2026
Merged

fix:itemdecoration和worldedit#1187
THEXN merged 2 commits into
UnrealMultiple:masterfrom
THEXN:fix/itemdecoration-chat

Conversation

@THEXN

@THEXN THEXN commented Jul 27, 2026

Copy link
Copy Markdown
Member

更新插件/修复BUG

  • 插件已修改版本号
  • 更新插件README.md中的更新日志
  • 插件可以正常工作

Summary by Sourcery

更新 ItemDecoration 中的聊天处理逻辑,并增强 WorldEdit 初始化和数据库清理的可靠性。

Bug 修复:

  • 通过切换到 PlayerChat 钩子并使用原始聊天文本,防止 ItemDecoration 拦截类似 /help 2 这样的数字命令。
  • 通过空值检查和异常处理来保护 WorldEdit 的数据库表清理和初始化逻辑,避免在存储配置或数据库访问失败时导致崩溃。

改进:

  • 通过使用 DROP TABLE IF EXISTS WorldEdit 使 WorldEdit 的数据表删除操作具备幂等性。
  • 在数据库、生物群系和颜色配置等方面,使用顶层 try/catch 和控制台日志,提升 WorldEdit 初始化过程的健壮性。

文档:

  • 为 ItemDecoration 3.0.2 版本添加更新日志条目,说明聊天命令拦截问题的修复。
Original summary in English

Summary by Sourcery

Update chat handling in ItemDecoration and harden WorldEdit initialization and database cleanup logic.

Bug Fixes:

  • Prevent ItemDecoration from intercepting numeric commands like /help 2 by switching to the PlayerChat hook and using raw chat text.
  • Guard WorldEdit database table cleanup and initialization with null checks and exception handling to avoid crashes when storage configuration or database access fails.

Enhancements:

  • Make WorldEdit table drop operation idempotent by using DROP TABLE IF EXISTS WorldEdit.
  • Improve robustness of WorldEdit initialization around database, biome, and color setup with a top-level try/catch and console logging.

Documentation:

  • Add ItemDecoration changelog entry for version 3.0.2 describing the chat command interception fix.

@THEXN
THEXN requested a review from a team as a code owner July 27, 2026 15:51

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了 1 个问题,并给出了一些总体反馈:

  • 在 ItemDecoration.Plugin 中,你现在订阅了 PlayerHooks.PlayerChat,但似乎没有在任何地方(例如在 Dispose/DeInitialize 中)取消订阅,这可能会导致处理程序在重载之间残留;建议添加对应的 -= 取消订阅。
  • 在 WorldEdit.OnInitialize 中新增的那个大型 try/catch 块包裹了很多不相关的初始化逻辑,这会使调试变得更困难,并掩盖具体的失败原因;建议将 try/catch 的范围缩小到你预期可能失败的数据库/撤销表相关处理上。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- 在 ItemDecoration.Plugin 中,你现在订阅了 PlayerHooks.PlayerChat,但似乎没有在任何地方(例如在 Dispose/DeInitialize 中)取消订阅,这可能会导致处理程序在重载之间残留;建议添加对应的 -= 取消订阅。
- 在 WorldEdit.OnInitialize 中新增的那个大型 try/catch 块包裹了很多不相关的初始化逻辑,这会使调试变得更困难,并掩盖具体的失败原因;建议将 try/catch 的范围缩小到你预期可能失败的数据库/撤销表相关处理上。

## Individual Comments

### Comment 1
<location path="src/ItemDecoration/Plugin.cs" line_range="32-36" />
<code_context>
     public override void Initialize()
     {
-        ServerApi.Hooks.ServerChat.Register(this, this.OnServerChat);
+        PlayerHooks.PlayerChat += this.OnPlayerChat;
         Hooks.MessageBuffer.InvokeGetData += this.MessageBuffer_InvokeGetData;
     }
</code_context>
<issue_to_address>
**suggestion (bug_risk):** 在释放时从 PlayerHooks.PlayerChat 取消订阅,可以避免潜在的事件处理程序泄漏。

既然我们订阅了 `PlayerHooks.PlayerChat`,请确保在插件的拆卸阶段(例如 `Dispose`/`DeInitialize`)中进行取消订阅,这样在重载或插件被禁用时,处理程序就不会残留。

```suggestion
    public override void Initialize()
    {
        PlayerHooks.PlayerChat += this.OnPlayerChat;
        Hooks.MessageBuffer.InvokeGetData += this.MessageBuffer_InvokeGetData;
    }

    public override void DeInitialize()
    {
        PlayerHooks.PlayerChat -= this.OnPlayerChat;
        Hooks.MessageBuffer.InvokeGetData -= this.MessageBuffer_InvokeGetData;
    }
```
</issue_to_address>

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • In ItemDecoration.Plugin, you’re now subscribing to PlayerHooks.PlayerChat but don’t appear to unsubscribe anywhere (e.g., in Dispose/DeInitialize), which can cause handlers to linger across reloads; consider adding the corresponding -= unsubscription.
  • The large try/catch block added in WorldEdit.OnInitialize wraps a lot of unrelated initialization logic, which can make debugging harder and mask specific failures; consider narrowing the try/catch to just the database/undo-table handling you expect to fail.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In ItemDecoration.Plugin, you’re now subscribing to PlayerHooks.PlayerChat but don’t appear to unsubscribe anywhere (e.g., in Dispose/DeInitialize), which can cause handlers to linger across reloads; consider adding the corresponding -= unsubscription.
- The large try/catch block added in WorldEdit.OnInitialize wraps a lot of unrelated initialization logic, which can make debugging harder and mask specific failures; consider narrowing the try/catch to just the database/undo-table handling you expect to fail.

## Individual Comments

### Comment 1
<location path="src/ItemDecoration/Plugin.cs" line_range="32-36" />
<code_context>
     public override void Initialize()
     {
-        ServerApi.Hooks.ServerChat.Register(this, this.OnServerChat);
+        PlayerHooks.PlayerChat += this.OnPlayerChat;
         Hooks.MessageBuffer.InvokeGetData += this.MessageBuffer_InvokeGetData;
     }
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Unsubscribing from PlayerHooks.PlayerChat on disposal would avoid potential event handler leaks.

Since we’re subscribing to `PlayerHooks.PlayerChat`, make sure to unsubscribe in the plugin teardown (e.g., `Dispose`/`DeInitialize`) so handlers don’t linger across reloads or when the plugin is disabled.

```suggestion
    public override void Initialize()
    {
        PlayerHooks.PlayerChat += this.OnPlayerChat;
        Hooks.MessageBuffer.InvokeGetData += this.MessageBuffer_InvokeGetData;
    }

    public override void DeInitialize()
    {
        PlayerHooks.PlayerChat -= this.OnPlayerChat;
        Hooks.MessageBuffer.InvokeGetData -= this.MessageBuffer_InvokeGetData;
    }
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/ItemDecoration/Plugin.cs
@THEXN
THEXN force-pushed the fix/itemdecoration-chat branch from d56aacc to df9f186 Compare July 27, 2026 15:59
@THEXN
THEXN added this pull request to the merge queue Jul 27, 2026
Merged via the queue into UnrealMultiple:master with commit 8da79e3 Jul 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants