Interface GuiService

All Superinterfaces:
Listener, ServiceContainer

public interface GuiService extends 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 Details

    • registerMenu

      <C> void registerMenu(MenuId<C> id, MenuHandler<C> handler, Supplier<InputStream> bundledJson)
      Register a menu. bundledJson is a fresh InputStream over 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 registered
      handler - the logic that drives it
      bundledJson - supplies a fresh stream over the menu's bundled JSON, called again on reload
    • openMenu

      <C> void openMenu(Player viewer, MenuId<C> id, C context)
      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 for
      id - the menu to open
      context - the context object the handler receives
    • refreshMenu

      void refreshMenu(Player viewer)
      Re-render the menu the viewer is currently in. No-op if none.
      Parameters:
      viewer - whose menu to re-render
    • closeMenu

      void closeMenu(Player viewer)
      Close the viewer's current menu with CloseReason.PLUGIN_CLOSED.
      Parameters:
      viewer - whose menu to close
    • addToOpenStorage

      OptionalInt addToOpenStorage(Player viewer, Pet pet, ItemStack item)
      Inserts item into the live storage of the menu viewer currently has open for pet (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 into
      pet - the pet whose storage the item belongs to; a menu open for another pet is ignored
      item - 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

      void closeStorageViewers(Object sharedStorageKey)
      Persists and closes every open menu whose handler reports sharedStorageKey from MenuHandler.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 null key or when nobody has such a menu open.

      Parameters:
      sharedStorageKey - the store identity, compared by reference like the handler's own sharedStorageKey
    • getSectionTypeRegistry

      SectionTypeRegistry getSectionTypeRegistry()
      Returns the registry of section types, for registering a type of your own.
      Returns:
      the process-wide section type registry