Package dev.oumaimaa.kawaiiapi.menu
Class MenuManager
java.lang.Object
dev.oumaimaa.kawaiiapi.menu.MenuManager
Central management system for handling player menus.
Provides menu registration, opening, and player-specific menu data storage.
This manager must be initialized during plugin startup using setup(Server, Plugin).
It automatically registers the MenuListener and manages PlayerMenuUtility instances.
Features:
- Automatic listener registration
- Thread-safe player menu data storage
- Menu history tracking
- Reflection-based menu instantiation
- Version:
- 1.0
- Author:
- KawaiiDevelopment
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears all cached PlayerMenuUtility instances.static intGets the number of cached PlayerMenuUtility instances.static @NotNull PlayerMenuUtilitygetPlayerMenuUtility(@NotNull org.bukkit.entity.Player player) Retrieves or creates a PlayerMenuUtility for the specified player.static org.bukkit.plugin.PluginGets the plugin instance associated with this MenuManager.static booleanhasPlayerMenuUtility(@NotNull org.bukkit.entity.Player player) Checks if a player has an active PlayerMenuUtility.static booleanChecks if the MenuManager has been initialized.static <T extends Menu>
voidOpens a menu for a player by instantiating the specified menu class.static @NotNull PlayerMenuUtilityremovePlayerMenuUtility(@NotNull org.bukkit.entity.Player player) Removes a player's MenuUtility from the cache.static voidreset()Resets the MenuManager state.static voidsetup(@NotNull org.bukkit.Server server, @NotNull org.bukkit.plugin.Plugin plugin) Initializes the MenuManager system.
-
Method Details
-
setup
public static void setup(@NotNull @NotNull org.bukkit.Server server, @NotNull @NotNull org.bukkit.plugin.Plugin plugin) Initializes the MenuManager system. Must be called during plugin startup (onEnable). Automatically registers the MenuListener if not already registered.- Parameters:
server- The server instance (use getServer())plugin- The plugin instance (use 'this' from main class)- Throws:
IllegalStateException- if already initialized
-
openMenu
public static <T extends Menu> void openMenu(@NotNull @NotNull Class<T> menuClass, @NotNull @NotNull org.bukkit.entity.Player player) throws MenuManagerException, MenuManagerNotSetupException Opens a menu for a player by instantiating the specified menu class. The menu class must have a constructor that accepts PlayerMenuUtility.- Type Parameters:
T- The type of the menu class- Parameters:
menuClass- The class of the menu to openplayer- The player to open the menu for- Throws:
MenuManagerNotSetupException- If setup() has not been calledMenuManagerException- If the menu cannot be instantiated or opened
-
getPlayerMenuUtility
@NotNull public static @NotNull PlayerMenuUtility getPlayerMenuUtility(@NotNull @NotNull org.bukkit.entity.Player player) throws MenuManagerNotSetupException Retrieves or creates a PlayerMenuUtility for the specified player. PlayerMenuUtility instances are cached per player for performance.- Parameters:
player- The player to get the utility for- Returns:
- The PlayerMenuUtility instance for this player
- Throws:
MenuManagerNotSetupException- If setup() has not been called
-
removePlayerMenuUtility
@NotNull public static @NotNull PlayerMenuUtility removePlayerMenuUtility(@NotNull @NotNull org.bukkit.entity.Player player) Removes a player's MenuUtility from the cache. Useful for cleanup when a player leaves the server.- Parameters:
player- The player to remove- Returns:
- The removed PlayerMenuUtility, or null if not found
-
hasPlayerMenuUtility
public static boolean hasPlayerMenuUtility(@NotNull @NotNull org.bukkit.entity.Player player) Checks if a player has an active PlayerMenuUtility.- Parameters:
player- The player to check- Returns:
- true if the player has a cached utility
-
clearAllPlayerMenuUtilities
public static void clearAllPlayerMenuUtilities()Clears all cached PlayerMenuUtility instances. Useful for plugin reloads or cleanup. -
getCachedPlayerCount
public static int getCachedPlayerCount()Gets the number of cached PlayerMenuUtility instances.- Returns:
- The cache size
-
isInitialized
public static boolean isInitialized()Checks if the MenuManager has been initialized.- Returns:
- true if setup() has been called
-
getPlugin
public static org.bukkit.plugin.Plugin getPlugin()Gets the plugin instance associated with this MenuManager.- Returns:
- The plugin instance, or null if not initialized
-
reset
public static void reset()Resets the MenuManager state. WARNING: This will clear all cached data. Use with caution.
-