Class MenuHandle
java.lang.Object
nl.pim16aap2.lightkeeper.framework.MenuHandle
Handle for an open player menu.
Menu actions (clickAtIndex(int), clickItem(String), dragWithMaterial(java.lang.String, int...)) auto-wait for
an open menu (bounded, default 10 seconds) before acting. This is the one deliberate implicit wait in the
framework API: waiting for the menu is the only correct behavior before interacting with it. Probes and
verifications (e.g. isOpen(), snapshot(), verifyMenuName(java.lang.String), verifyMenuClosed(),
hasTitle(java.lang.String), hasItemAt(int, java.lang.String)) never wait; the explicit andWaitForMenuClose() waits for the
opposite transition.
-
Method Summary
Modifier and TypeMethodDescriptionWaits until the menu closes using the default timeout.andWaitForMenuClose(Duration timeout) Waits until the menu closes.andWaitTicks(int ticks) Waits for the requested number of ticks.clickAtIndex(int slot) Clicks a slot in the open menu, auto-waiting for an open menu first (bounded, default 10 seconds).Clicks the first menu item whose display name contains the given fragment, auto-waiting for an open menu first (bounded, default 10 seconds).dragWithMaterial(String materialKey, int... slots) Performs a drag operation using a material over the provided slots, auto-waiting for an open menu first (bounded, default 10 seconds).booleanChecks whether a slot contains a matching material key.booleanhasItemAt(int slot, org.bukkit.inventory.ItemStack itemStack) Checks whether a slot matches an expected item stack snapshot.booleanChecks whether the current open menu has the expected title.booleanisOpen()Checks whether an actionable menu is currently open.player()Gets the player associated with this menu handle.snapshot()Retrieves the latest menu snapshot.Asserts that no menu is currently open.verifyMenuName(String expectedTitle) Asserts that the menu is open and has the expected title.
-
Method Details
-
player
Gets the player associated with this menu handle.- Returns:
- The associated player.
-
snapshot
Retrieves the latest menu snapshot.- Returns:
- The current menu snapshot.
-
verifyMenuName
Asserts that the menu is open and has the expected title.- Parameters:
expectedTitle- Expected title text.- Returns:
- This handle.
-
isOpen
public boolean isOpen()Checks whether an actionable menu is currently open. An instant probe suitable forwaitUntil(...)conditions; never waits.- Returns:
truewhen a menu is open.
-
clickAtIndex
Clicks a slot in the open menu, auto-waiting for an open menu first (bounded, default 10 seconds).- Parameters:
slot- Inventory slot index.- Returns:
- This handle.
- Throws:
IllegalStateException- When no menu opens within the wait bound.
-
clickItem
Clicks the first menu item whose display name contains the given fragment, auto-waiting for an open menu first (bounded, default 10 seconds).- Parameters:
displayNameFragment- Fragment to match against item display names (case-sensitive contains).- Returns:
- This handle.
- Throws:
IllegalStateException- When no menu opens within the wait bound, or no item in the open menu matches the fragment.
-
dragWithMaterial
Performs a drag operation using a material over the provided slots, auto-waiting for an open menu first (bounded, default 10 seconds).- Parameters:
materialKey- Material identifier.slots- Target slot indices.- Returns:
- This handle.
- Throws:
IllegalStateException- When no menu opens within the wait bound.
-
andWaitTicks
Waits for the requested number of ticks.- Parameters:
ticks- Tick count.- Returns:
- This handle.
-
andWaitForMenuClose
Waits until the menu closes using the default timeout.- Returns:
- This handle.
-
andWaitForMenuClose
Waits until the menu closes.- Parameters:
timeout- Maximum wait duration.- Returns:
- This handle.
-
verifyMenuClosed
Asserts that no menu is currently open.- Returns:
- This handle.
-
hasTitle
Checks whether the current open menu has the expected title.- Parameters:
expectedTitle- Expected title text.- Returns:
truewhen the menu is open with the expected title.
-
hasItemAt
Checks whether a slot contains a matching material key.- Parameters:
slot- Inventory slot index.materialKey- Expected material key.- Returns:
truewhen the slot matches.
-
hasItemAt
public boolean hasItemAt(int slot, org.bukkit.inventory.ItemStack itemStack) Checks whether a slot matches an expected item stack snapshot.- Parameters:
slot- Inventory slot index.itemStack- Expected item stack.- Returns:
truewhen the slot matches.
-