Package dev.oumaimaa.kawaiiapi.menu
Class PlayerMenuUtility
java.lang.Object
dev.oumaimaa.kawaiiapi.menu.PlayerMenuUtility
Companion class for storing player-specific menu data.
Each player has exactly one PlayerMenuUtility instance that persists across menu navigation's.
This class provides:
- Menu history tracking for back navigation
- Arbitrary data storage per player
- Type-safe data retrieval
Data stored in this utility persists until the player disconnects or the MenuManager is cleared.
- Version:
- 1.0
- Author:
- KawaiiDevelopment
-
Method Summary
Modifier and TypeMethodDescriptionvoidClears all stored data.voidClears the menu history stack.@Nullable ObjectRetrieves data stored under the specified enum key.<T> TRetrieves data with automatic type casting using an enum key.@Nullable ObjectRetrieves data stored under the specified key.<T> TRetrieves data with automatic type casting.Gets all stored data keys.intGets the number of data entries stored.intGets the current size of the menu history stack.@Nullable org.bukkit.entity.PlayergetOwner()Gets the player who owns this utility.@NotNull UUIDGets the UUID of the player who owns this utility.booleanChecks if data exists for the specified enum key.booleanChecks if data exists for the specified key.booleanChecks if there is a previous menu in the history.@Nullable MenuPeeks at the previous menu without removing it from history.@Nullable ObjectremoveData(@NotNull Enum<?> identifier) Removes data associated with the specified enum key.@Nullable ObjectremoveData(@NotNull String identifier) Removes data associated with the specified key.voidStores arbitrary data associated with an enum key.voidStores arbitrary data associated with a string key.toString()
-
Method Details
-
getOwner
@Nullable public @Nullable org.bukkit.entity.Player getOwner()Gets the player who owns this utility.- Returns:
- The player instance, or null if they are offline
-
getOwnerUUID
Gets the UUID of the player who owns this utility.- Returns:
- The player's UUID
-
setData
-
setData
-
getData
-
getData
-
getData
@Nullable public <T> T getData(@NotNull @NotNull String identifier, @NotNull @NotNull Class<T> classRef) Retrieves data with automatic type casting. Returns null if the data doesn't exist or cannot be cast to the specified type.- Type Parameters:
T- The type to cast to- Parameters:
identifier- The key to retrieve data forclassRef- The class to cast the data to- Returns:
- The cast data, or null if not found or cast failed
-
getData
@Nullable public <T> T getData(@NotNull @NotNull Enum<?> identifier, @NotNull @NotNull Class<T> classRef) Retrieves data with automatic type casting using an enum key.- Type Parameters:
T- The type to cast to- Parameters:
identifier- The enum key to retrieve data forclassRef- The class to cast the data to- Returns:
- The cast data, or null if not found or cast failed
-
hasData
Checks if data exists for the specified key.- Parameters:
identifier- The key to check- Returns:
- true if data exists for this key
-
hasData
Checks if data exists for the specified enum key.- Parameters:
identifier- The enum key to check- Returns:
- true if data exists for this key
-
removeData
-
removeData
-
clearData
public void clearData()Clears all stored data. Does not affect menu history. -
getDataSize
public int getDataSize()Gets the number of data entries stored.- Returns:
- The data map size
-
getMenuHistorySize
public int getMenuHistorySize()Gets the current size of the menu history stack.- Returns:
- The number of menus in history
-
clearMenuHistory
public void clearMenuHistory()Clears the menu history stack. Useful when you want to prevent back navigation. -
hasPreviousMenu
public boolean hasPreviousMenu()Checks if there is a previous menu in the history.- Returns:
- true if back navigation is possible
-
peekPreviousMenu
Peeks at the previous menu without removing it from history.- Returns:
- The previous menu, or null if none exists
-
getDataKeys
-
toString
-