Skip to content

Enhance PacketLoreListener with improved lore and snapshot management#249

Merged
twisti-dev merged 5 commits intoversion/1.21.11from
perf/optimize-packet-lore-listener
Mar 15, 2026
Merged

Enhance PacketLoreListener with improved lore and snapshot management#249
twisti-dev merged 5 commits intoversion/1.21.11from
perf/optimize-packet-lore-listener

Conversation

@twisti-dev
Copy link
Contributor

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:

  • Refactored PacketLoreListener to 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]
  • Updated the SurfBukkitPacketApi interface and its implementation to add overloads for registering lore handlers with an explicit Plugin parameter, and defaulting to the calling plugin when not specified. [1] [2] [3]
  • Added a new PluginDisablePacketLoreListener which listens for PluginDisableEvent and automatically unregisters all lore handlers associated with the disabled plugin, ensuring clean resource management. [1] [2]

Performance and Correctness Enhancements:

  • Optimized lore modification logic to avoid copying or modifying item stacks unless at least one handler will actually run and produce a change, reducing unnecessary allocations and improving efficiency.
  • Ensured that lore handlers are only invoked when relevant, and that item stacks are only updated if the lore actually changes, preserving original lore using a unique key for restoration when needed. [1] [2]

General Codebase Improvements:

  • Replaced usage of ConcurrentHashMap and other standard collections with fastutil collections for improved performance and memory usage in handler storage.
  • Improved event listener logic to check for the presence of handlers before processing, further reducing overhead when no handlers are registered.

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]

@twisti-dev twisti-dev self-assigned this Mar 15, 2026
Copilot AI review requested due to automatic review settings March 15, 2026 11:14
@github-actions
Copy link
Contributor

⚠️ API/ABI changes detected!

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 push

After updating, the CI will pass. Make sure the changes are backward compatible.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 PacketLoreListener to 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 explicit Plugin, while keeping a convenience overload that infers the calling plugin.
  • Added a PluginDisableEvent listener 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.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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".

@twisti-dev twisti-dev merged commit 9fc6ea5 into version/1.21.11 Mar 15, 2026
4 checks passed
@twisti-dev twisti-dev deleted the perf/optimize-packet-lore-listener branch March 15, 2026 11:33
@github-actions
Copy link
Contributor

⚠️ API/ABI changes detected!

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 push

After updating, the CI will pass. Make sure the changes are backward compatible.

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