fix:itemdecoration和worldedit - #1187
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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>帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
ACaiCat
approved these changes
Jul 27, 2026
THEXN
force-pushed
the
fix/itemdecoration-chat
branch
from
July 27, 2026 15:59
d56aacc to
df9f186
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
更新插件/修复BUG
Summary by Sourcery
更新 ItemDecoration 中的聊天处理逻辑,并增强 WorldEdit 初始化和数据库清理的可靠性。
Bug 修复:
/help 2这样的数字命令。改进:
DROP TABLE IF EXISTS WorldEdit使 WorldEdit 的数据表删除操作具备幂等性。文档:
Original summary in English
Summary by Sourcery
Update chat handling in ItemDecoration and harden WorldEdit initialization and database cleanup logic.
Bug Fixes:
/help 2by switching to the PlayerChat hook and using raw chat text.Enhancements:
DROP TABLE IF EXISTS WorldEdit.Documentation: