Package de.Keyle.MyPet.api.gui
Interface MenuHandler<C>
- Type Parameters:
C- the context type this menu is opened with
public interface MenuHandler<C>
Per-menu Java logic. One implementation per
MenuId, registered with
GuiService.registerMenu(de.Keyle.MyPet.api.gui.MenuId<C>, de.Keyle.MyPet.api.gui.MenuHandler<C>, java.util.function.Supplier<java.io.InputStream>).-
Method Summary
Modifier and TypeMethodDescriptiondefault ItemAppearancecustomizeSlotItem(C context, String sectionId, ItemAppearance appearance) Customize aslotsection's item at render time (e.g.default ItemAppearancecustomizeTemplateItem(C context, String sectionId, int itemIndex, ItemAppearance template) Customize a paginated-list template's item for one specific entry (e.g.id()Identifies which menu this handler drives.default booleanisSlotVisible(C context, String sectionId) Per-render visibility check for a section.voidonClick(MenuInstance instance, String sectionId, ClickPayload payload) Called for a click the section's renderer delegated to this handler.default voidonClose(MenuInstance instance, CloseReason reason) Called once as the menu closes.voidonOpen(MenuInstance instance, C context) Called once as the menu opens, before the first render.default voidonRefresh(MenuInstance instance, C context) Called when something outside the menu asks for it to be redrawn (GuiService.refreshMenu(org.bukkit.entity.Player)), before the renderer reads the handler's state.default voidpersistStorage(C context, String sectionId, ItemStack[] contents) Persist storage contents when the menu closes.default TagResolverplaceholders(C context, String sectionId, int itemIndex) Placeholders for one rendered item.default ObjectsharedStorageKey(C context) Identity of the mutable store this menu's storage sections read and write, ornull(the default) for menus with no storage or none that another viewer can reach.default ItemStack[]storageContents(C context, String sectionId) Initial contents for a storage section.default List<?> templateItems(C context, String sectionId) Items for a paginated-list section.default TagResolvertitlePlaceholders(C context) Placeholders resolved into the JSONtitlewhen the menu is built.default MenuDefinitiontransformDefinition(C context, MenuDefinition base) Reshape the loadedMenuDefinitionbased on the open-time context.default intvalueBarPosition(C context, String sectionId) Current 0-indexed fill position for a value-bar section (0..width-1).
-
Method Details
-
id
Identifies which menu this handler drives.- Returns:
- the id this handler was registered under
-
onOpen
Called once as the menu opens, before the first render.- Parameters:
instance- handle to the menu now openingcontext- the context object the caller opened the menu with
-
onClick
Called for a click the section's renderer delegated to this handler.- Parameters:
instance- handle to the open menusectionId- id of the section that owns the clicked slotpayload- what was clicked and how
-
onClose
Called once as the menu closes. Default does nothing.- Parameters:
instance- handle to the closing menureason- why it is closing
-
onRefresh
Called when something outside the menu asks for it to be redrawn (GuiService.refreshMenu(org.bukkit.entity.Player)), before the renderer reads the handler's state. A handler that caches derived state -- a sorted row list, a per-row status -- rebuilds it here; one that renders straight from its context needs nothing.- Parameters:
instance- the open menucontext- the context the menu was opened with
-
templateItems
Items for a paginated-list section. Called every render.- Parameters:
context- the menu's context objectsectionId- the paginated-list section being rendered- Returns:
- the items to lay out; empty by default
-
storageContents
Initial contents for a storage section. Called on open.- Parameters:
context- the menu's context objectsectionId- the storage section being filled- Returns:
- the contents to show on open; empty by default
-
persistStorage
Persist storage contents when the menu closes.- Parameters:
context- the menu's context objectsectionId- the storage section being savedcontents- what the viewer left in the section
-
placeholders
Placeholders for one rendered item. For paginated-list templates,itemIndexis the page-relative index; for other sections it is -1.- Parameters:
context- the menu's context objectsectionId- the section being rendereditemIndex- page-relative index for a paginated-list template, or-1elsewhere- Returns:
- resolvers for this item; empty by default
-
titlePlaceholders
Placeholders resolved into the JSONtitlewhen the menu is built. Supply the dynamic part as an uncolored component (e.g.Placeholder.component("pet_title", Component.translatable("X.Title", Component.text(petName)))); the JSON wraps it with color. Lets dynamic titles keep their styling in JSON rather than in code.- Parameters:
context- the menu's context object- Returns:
- resolvers for the menu title; empty by default
-
customizeTemplateItem
default ItemAppearance customizeTemplateItem(C context, String sectionId, int itemIndex, ItemAppearance template) Customize a paginated-list template's item for one specific entry (e.g. swap the material / glow per-item based on the underlying data). Default returns the template unchanged. Only called forpaginated-listsections; for other section types, the template is used as-is.- Parameters:
context- the menu's context objectsectionId- the paginated-list section being rendereditemIndex- page-relative index of the entrytemplate- the appearance as loaded from JSON- Returns:
- the appearance to draw; the template unchanged by default
-
customizeSlotItem
Customize aslotsection's item at render time (e.g. swap material per pet type, recolor potion bottle). Default returns the appearance unchanged. Called every render after state resolution for slot sections only.- Parameters:
context- the menu's context objectsectionId- the slot section being renderedappearance- the appearance after state resolution- Returns:
- the appearance to draw; unchanged by default
-
isSlotVisible
Per-render visibility check for a section. Returning false skips both rendering and click routing for that slot. The slot's underlying area is left to whatever lower-priority section painted there (border, fill, or empty). Default true.- Parameters:
context- the menu's context objectsectionId- the section being considered- Returns:
trueto render and route clicks for it;trueby default
-
valueBarPosition
Current 0-indexed fill position for a value-bar section (0..width-1). Default 0 (renders as all-low). Clamped to range at render time.- Parameters:
context- the menu's context objectsectionId- the value-bar section being rendered- Returns:
- the 0-indexed fill position, clamped to the bar's width at render time
-
transformDefinition
Reshape the loadedMenuDefinitionbased on the open-time context. Use when row count or section regions depend on per-pet state (e.g. the backpack's upgrade-driven row count). Default returnsbaseunchanged.- Parameters:
context- the menu's context objectbase- the definition as loaded- Returns:
- the definition to open;
baseunchanged by default
-