Skip to content

Add packet-based GUI backend#1

Open
Keviro wants to merge 15 commits into
masterfrom
packet-guis
Open

Add packet-based GUI backend#1
Keviro wants to merge 15 commits into
masterfrom
packet-guis

Conversation

@Keviro
Copy link
Copy Markdown

@Keviro Keviro commented May 25, 2026

Summary

This pull request adds an optional packet-based GUI backend for InventoryFramework.

The goal is to render GUI contents as virtual packet items instead of placing real items into Bukkit inventories. This makes GUI item rendering safer against duplication issues while keeping the existing InventoryFramework API unchanged for consumers.

PacketEvents is used as the packet abstraction layer, with the Bukkit inventory backend remaining available as a fallback. The packet backend is designed to work on the current Paper/SurfCanvas/Folia runtime and keeps player-facing inventory state synchronized through packet updates.

Motivation

Inventory GUIs should not need to store their visual items as real server-side inventory contents. Rendering them through packets allows the framework to display the same GUI items to players without making those items physically exist in the server inventory state.

This improves safety for GUI-heavy plugins and provides a cleaner backend model for future inventory rendering behavior.

Notes

  • Existing InventoryFramework API usage should continue to work unchanged.
  • Bukkit inventory rendering remains available as fallback.
  • Packet mode is the recommended backend for fake-item GUI rendering.
  • PacketEvents is required at runtime for packet mode.
  • Folia/Canvas-compatible scheduling is preserved.

@Keviro Keviro marked this pull request as ready for review May 25, 2026 21:37
Copilot AI review requested due to automatic review settings May 25, 2026 21:37
Copy link
Copy Markdown

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 introduces an internal “packet GUI” backend for the Bukkit platform, intended to render chest-style GUIs using PacketEvents (with a fallback to standard Bukkit inventories when unavailable or unsupported).

Changes:

  • Adds a GuiBackend abstraction with a default Bukkit implementation and an optional PacketEvents-driven packet backend.
  • Introduces packet GUI session/render/click tracking to open/update/close GUIs via packets.
  • Adds PacketEvents as an optional (soft) dependency and updates build configuration to include the required repository and version catalog entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread patches/0006-add-internal-packet-gui-backend.patch
Comment thread patches/0006-add-internal-packet-gui-backend.patch
Comment thread patches/0006-add-internal-packet-gui-backend.patch
Keviro and others added 7 commits May 25, 2026 23:46
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- add handling for closing inventory sessions based on user actions
- improve session management by ensuring proper windowId checks
- update session inventory state after closing to reflect changes
- implement normalization for item display names and lore
- utilize reflection to access ItemMeta properties
- ensure non-italic display names for better consistency
Adds coalesced SetSlot-based updates and per-session item conversion caching so normal GUI interactions no longer rebuild and resend the full window. Keeps full WindowItems only for open/reopen/hard repair paths, preserves Folia-safe scheduling, and maintains PacketEvents as the packet API.

This massively reduces repeated ItemStack conversion and fullResync overhead during clicks, pagination, and dynamic shop GUI updates.
@Keviro Keviro requested a review from Copilot May 26, 2026 10:30
Copy link
Copy Markdown

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.

Copilot wasn't able to review any files in this pull request.

Keviro added 4 commits May 26, 2026 14:51
Handle QUICK_MOVE, SWAP, and CLONE click actions in the packet GUI backend while keeping unsafe drag/drop/double-click actions cancelled and repaired. Shift and keyboard-style clicks now enter the normal click pipeline and trigger a hard repair to avoid client-side ghost item movement.
Handle server-side close packets without sending an extra close packet or forcing updateInventory, preventing packet GUI cleanup from immediately closing dialogs opened from click handlers.
Force a post-click repair for normal left/right PICKUP clicks so client-side prediction cannot leave fake GUI items missing or stuck on the cursor. Keeps shift, swap, clone, and unsafe click repair behavior intact.
Ensure offhand swap clicks repair the client-side offhand slot and cursor so fake GUI items cannot appear as ghost items in the player's hand.
@Keviro Keviro requested a review from Copilot May 26, 2026 14:20
Copy link
Copy Markdown

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.

Copilot wasn't able to review any files in this pull request.

@Keviro Keviro requested a review from twisti-dev May 26, 2026 14:21
@Keviro Keviro changed the title Add internal packet GUI backend Add packet-based GUI backend May 26, 2026
@Keviro
Copy link
Copy Markdown
Author

Keviro commented May 26, 2026

Die neuste Version ist auf dem Dev Survival Server zum Testen

Keviro added 3 commits May 26, 2026 19:38
Replace normal-click full window repairs with targeted slot/cursor repair scopes, reduce full WindowItems usage, and simplify packet item caching to avoid expensive render hashing.
Avoid expensive full window item resyncs during normal GUI clicks,
remove debug toString calls from hotpaths, and batch packet writes
through a guarded send plan.
Build packet GUI render/repair plans on the player scheduler, but move
the expensive Bukkit-to-PacketEvents item conversion onto dedicated worker
threads.

This keeps GUI state access Folia-safe while reducing region thread load
from PacketItemConverter/SpigotConversionUtil during packet GUI renders
and click repairs. Async conversion is enabled by default and logs a
warning when disabled.
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