Package eu.xap3y.xagui
Class VirtualMenu<T>
Object
VirtualMenu<T>
- Type Parameters:
T- The contextual data type used to (re)build or adapt the GUI before opening.
- All Implemented Interfaces:
VirtualMenuInterface<T>
Abstract helper base for creating type-aware (data-driven) virtual menus.
A VirtualMenu<T> wraps a concrete GuiMenuInterface instance and optionally
provides a data-bound build method (build(Object)) that can transform / adapt
the menu before it is opened for a player using some contextual object of type T.
Typical usage pattern:
public class ProfileMenu extends VirtualMenu<String> {
public ProfileMenu(XaGui xaGui) {
super("Profile", 3, xaGui); // 3 rows, 1 page by default
}
@Override
public GuiMenuInterface build(@NotNull String name) {
// configure gui buttons based on profile fields
return build(); // returns the already constructed (base) menu
}
}
// Opening without data (static build):
new ProfileMenu(xaGui).open(player);
// Opening with contextual data (dynamic build):
new ProfileMenu(xaGui).open(player, profileObject);
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final GuiMenuInterfaceThe underlying GUI instance this virtual menu manipulates. -
Constructor Summary
ConstructorsConstructorDescriptionWrap an existingGuiMenuInterfaceinstance.VirtualMenu(String name, int rows, int pages, XaGui instance) Construct a virtual menu with a multi-page GUI.VirtualMenu(String name, int rows, XaGui instance) Construct a virtual menu with a single-page GUI. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Access the underlying (already constructed) GUI instance without contextual rebuild.abstract @NotNull GuiMenuInterfaceBuild (or adapt) the GUI instance using a contextual object.getGui()voidopen(int page, Player player) Open a specific page of the (static) menu for a player (does not invokebuild(Object)).voidopen(Player player) Open the (static) menu for a player (does not invokebuild(Object)).voidBuild the GUI with a context object and open it for a player.
-
Field Details
-
gui
The underlying GUI instance this virtual menu manipulates.
-
-
Constructor Details
-
VirtualMenu
Construct a virtual menu with a single-page GUI.- Parameters:
name- GUI title (supports color codes if downstream implementation does)rows- number of rows (1-6 typical in Bukkit inventories)instance- activeXaGuimanager used to create the backing menu
-
VirtualMenu
-
VirtualMenu
Wrap an existingGuiMenuInterfaceinstance.- Parameters:
gui- existing GUI to virtualize
-
-
Method Details
-
open
public void open(Player player) Open the (static) menu for a player (does not invokebuild(Object)).- Parameters:
player- target player
-
open
public void open(int page, Player player) Open a specific page of the (static) menu for a player (does not invokebuild(Object)).- Parameters:
page- zero-based page indexplayer- target player
-
build
Access the underlying (already constructed) GUI instance without contextual rebuild.- Returns:
- backing
GuiMenuInterface
-
build
Build (or adapt) the GUI instance using a contextual object.Implementations should mutate
guias needed and return it.- Specified by:
buildin interfaceVirtualMenuInterface<T>- Parameters:
ctx- context object (non-null)- Returns:
- the (possibly modified) GUI instance to open
-
open
Build the GUI with a context object and open it for a player.- Parameters:
player- target playerctx- contextual data
-
getGui
-