Skip to content

Fix %deluxemenus_last_menu% failing during rapid menu switches - #323

Open
SalyyS1 wants to merge 1 commit into
HelpChat:mainfrom
SalyyS1:fix/last-menu-rapid-switch-230
Open

SalyyS1 wants to merge 1 commit into
HelpChat:mainfrom
SalyyS1:fix/last-menu-rapid-switch-230

Conversation

@SalyyS1

@SalyyS1 SalyyS1 commented Nov 14, 2026

Copy link
Copy Markdown

Description

Fixes #230

When rapidly clicking between two menus (for example spam-clicking a slot that switches from profile_own_overview to profile_backgrounds_1 and back via [openguimenu] %deluxemenus_last_menu%), %deluxemenus_last_menu% could resolve to the currently open menu or return an empty/stale value due to three interacting issues:

  1. Menu.openMenu builds menu items asynchronously before switching to the main thread to close the previous MenuHolder and open the new inventory. Because PlayerListener's click cache expires after 75ms, spam-clicking while an async menu open is still in flight could launch a second openMenu for the same target menu; when the second open completed right after the first, closeMenu closed the first instance of the target menu and overwrote lastOpenedMenus with the target menu itself.
  2. Overlapping async openMenu calls had no per-player open request sequence tracking, allowing an older in-flight async build to complete after a newer open request.
  3. menus, menuHolders, and lastOpenedMenus used unsynchronized HashMap / HashSet instances while %deluxemenus_last_menu% (Menu.getLastMenu) and MenuHolder.refreshMenu accessed and mutated them across main and async scheduler threads, and closeMenu could attempt to store null values in lastOpenedMenus.

Changes

  • Track per-player in-flight open requests with a monotonic request ID (beginMenuOpen / isCurrentOpenRequest / finishMenuOpen) so superseded async menu builds abort cleanly without mutating menuHolders or lastOpenedMenus, and guard PlayerListener.onClick with Menu.isOpeningMenu(player) alongside holder.isUpdating().
  • Avoid overwriting lastOpenedMenus with the same menu name during a menu-to-menu transition (closeMenuForTransition), while keeping normal menu closes (nextMenu == null) unchanged.
  • Switch menus, menuHolders, and lastOpenedMenus to ConcurrentHashMap / ConcurrentHashMap.newKeySet(), guard against null entries, and clean up unloaded menus and disconnecting players.
  • Add JUnit 5 unit tests in MenuLastMenuTest covering rapid double-opens, out-of-order async open cancellation, rapid back-and-forth transitions, player disconnect cleanup, and concurrent getLastMenu reads.

Testing

  • ./gradlew test shadowJar

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.

%deluxemenus_last_menu% fails when rapidly switching between menus

1 participant