Package de.Keyle.MyPet.api.gui
Interface GuiService
- All Superinterfaces:
Listener,ServiceContainer
Service facade. Obtained via
MyPetApi.getGuiService(). Plugins register
their menus with registerMenu(de.Keyle.MyPet.api.gui.MenuId<C>, de.Keyle.MyPet.api.gui.MenuHandler<C>, java.util.function.Supplier<java.io.InputStream>); the registered handler receives every
lifecycle callback for that menu.-
Method Summary
Modifier and TypeMethodDescriptionaddToOpenStorage(Player viewer, Pet pet, ItemStack item) Insertsiteminto the live storage of the menuviewercurrently has open forpet(e.g.voidClose the viewer's current menu withCloseReason.PLUGIN_CLOSED.voidcloseStorageViewers(Object sharedStorageKey) Persists and closes every open menu whose handler reportssharedStorageKeyfromMenuHandler.sharedStorageKey(C), whoever is viewing it.Returns the registry of section types, for registering a type of your own.<C> voidOpen or push a menu for the viewer.voidrefreshMenu(Player viewer) Re-render the menu the viewer is currently in.<C> voidregisterMenu(MenuId<C> id, MenuHandler<C> handler, Supplier<InputStream> bundledJson) Register a menu.Methods inherited from interface de.Keyle.MyPet.api.util.service.ServiceContainer
getActivationMessage, getServiceName, loadConfig, onDisable, onEnable
-
Method Details
-
registerMenu
Register a menu.bundledJsonis a freshInputStreamover the JSON file shipped inside the registering plugin's JAR. The supplier is invoked once at registration and again on/mypet reload.- Type Parameters:
C- the context type this menu is opened with- Parameters:
id- the menu being registeredhandler- the logic that drives itbundledJson- supplies a fresh stream over the menu's bundled JSON, called again on reload
-
openMenu
Open or push a menu for the viewer.- Type Parameters:
C- the context type this menu is opened with- Parameters:
viewer- who to open it forid- the menu to opencontext- the context object the handler receives
-
refreshMenu
Re-render the menu the viewer is currently in. No-op if none.- Parameters:
viewer- whose menu to re-render
-
closeMenu
Close the viewer's current menu withCloseReason.PLUGIN_CLOSED.- Parameters:
viewer- whose menu to close
-
addToOpenStorage
Insertsiteminto the live storage of the menuviewercurrently has open forpet(e.g. that pet's open Backpack), so the addition is visible immediately and is persisted when the menu closes. Returns the amount that did not fit, or empty when the viewer has no open menu with a storage section — callers should then persist through their own backing store instead.- Parameters:
viewer- the player whose open menu to insert intopet- the pet whose storage the item belongs to; a menu open for another pet is ignoreditem- the item to insert- Returns:
- how much did not fit, or empty when the viewer has no open menu with a storage
section for
pet
-
closeStorageViewers
Persists and closes every open menu whose handler reportssharedStorageKeyfromMenuHandler.sharedStorageKey(C), whoever is viewing it.A storage section is copied into the viewer's inventory on open and written back to its store only on close. Until then the store is stale, and any code that reads or replaces it directly — dropping a backpack on death, shrinking it after a skilltree change — acts on items the viewer may already have moved out and can still take out afterwards. Call this first: it writes each open window back, closes it and returns with the store current and no window left over it.
No-op for a
nullkey or when nobody has such a menu open.- Parameters:
sharedStorageKey- the store identity, compared by reference like the handler's ownsharedStorageKey
-
getSectionTypeRegistry
SectionTypeRegistry getSectionTypeRegistry()Returns the registry of section types, for registering a type of your own.- Returns:
- the process-wide section type registry
-