Enhance PacketLoreListener with improved lore and snapshot management#249
Conversation
…imize lore handler registration
|
This PR contains changes that modified the public API. To update the reference ABI dumps: ./gradlew updateLegacyAbi
git add **/api/**
git commit -m "Update ABI reference"
git pushAfter updating, the CI will pass. Make sure the changes are backward compatible. |
There was a problem hiding this comment.
Pull request overview
This PR refactors the Bukkit packet lore handling system to be plugin-aware and more efficient by introducing per-plugin handler storage with snapshot-based reads, plus automatic cleanup when plugins are disabled.
Changes:
- Refactored
PacketLoreListenerto store keyed/global handlers per plugin using fastutil collections and volatile snapshots for read-side performance. - Updated
SurfBukkitPacketApi(and impl) to support registering keyed lore handlers with an explicitPlugin, while keeping a convenience overload that infers the calling plugin. - Added a
PluginDisableEventlistener to automatically unregister lore handlers for plugins as they are disabled, and wired it into the packet subsystem loader.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/packet/lore/PluginDisablePacketLoreListener.kt | Adds listener to unregister lore handlers on plugin disable. |
| surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/packet/lore/PacketLoreListener.kt | Implements per-plugin handler storage, snapshots, and optimized item copying/lore updates. |
| surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/packet/PacketApiLoader.kt | Registers/unregisters the new plugin-disable listener in the packet lifecycle. |
| surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/impl/packet/SurfBukkitPacketApiImpl.kt | Routes API registration through the new plugin-aware PacketLoreListener.register(...). |
| surf-api-bukkit/surf-api-bukkit-api/src/main/kotlin/dev/slne/surf/surfapi/bukkit/api/packet/SurfBukkitPacketApi.kt | Adds plugin-aware overloads and calling-plugin defaults for keyed lore handler registration. |
...server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/packet/lore/PacketLoreListener.kt
Outdated
Show resolved
Hide resolved
...server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/packet/lore/PacketLoreListener.kt
Show resolved
Hide resolved
...server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/packet/lore/PacketLoreListener.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e5c9b6c27
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
...pi-bukkit-api/src/main/kotlin/dev/slne/surf/surfapi/bukkit/api/packet/SurfBukkitPacketApi.kt
Outdated
Show resolved
Hide resolved
|
This PR contains changes that modified the public API. To update the reference ABI dumps: ./gradlew updateLegacyAbi
git add **/api/**
git commit -m "Update ABI reference"
git pushAfter updating, the CI will pass. Make sure the changes are backward compatible. |
This pull request introduces significant improvements to the lore packet handler system in the Bukkit API. The core changes revolve around making packet lore handler registration and unregistration plugin-aware, improving performance and thread safety, and ensuring proper cleanup when plugins are disabled. The code now uses more efficient data structures, supports per-plugin handler management, and avoids unnecessary work when no handlers are present.
Lore Handler Registration and Management Improvements:
PacketLoreListenerto manage lore handlers per-plugin using fastutil collections, with thread-safe snapshots for keyed and global handlers. Registration and unregistration now require specifying the plugin, preventing handler collisions and enabling better lifecycle management. [1] [2]SurfBukkitPacketApiinterface and its implementation to add overloads for registering lore handlers with an explicitPluginparameter, and defaulting to the calling plugin when not specified. [1] [2] [3]PluginDisablePacketLoreListenerwhich listens forPluginDisableEventand automatically unregisters all lore handlers associated with the disabled plugin, ensuring clean resource management. [1] [2]Performance and Correctness Enhancements:
General Codebase Improvements:
ConcurrentHashMapand other standard collections with fastutil collections for improved performance and memory usage in handler storage.These changes collectively make the lore packet handling system more robust, efficient, and maintainable, especially in environments with multiple plugins registering lore handlers.
References: [1] [2] [3] [4] [5] [6] [7] [8]