Interface GuiLayoutService


public interface GuiLayoutService
GUI ID registration plus configured size, slot, filler, and pagination resolution. Runtime registration is reserved for addon IDs and never replaces a shipped built-in definition.

Since 1.15.0 this service also reaches the resource-pack textures that the background blocks of guis.yml give menus. Zentrix decides a menu's texture after the menu has placed its buttons and before it opens, and again whenever the menu redraws, from what it shows. Add-ons can read what an open menu shows (getOpenMenu(org.bukkit.entity.Player)), give server owners conditions and values to write in those rules (registerBackgroundCondition(org.bukkit.plugin.Plugin, java.lang.String, dev.itsharshxd.zentrix.api.gui.background.MenuBackgroundCondition), registerBackgroundValue(org.bukkit.plugin.Plugin, java.lang.String, dev.itsharshxd.zentrix.api.gui.background.MenuBackgroundValue)), choose a texture themselves (registerBackgroundResolver(org.bukkit.plugin.Plugin, java.lang.String, dev.itsharshxd.zentrix.api.gui.background.MenuBackgroundResolver)), and have an open menu decided again when something their conditions depend on changes (refreshBackground(org.bukkit.entity.Player)).

Background methods must be called on the main thread. Registrations end on their own when the registering plugin is disabled.

Since:
1.6.0
  • Method Details

    • getRegisteredIds

      @NotNull @NotNull Set<String> getRegisteredIds()
    • isRegistered

      boolean isRegistered(@NotNull @NotNull String guiId)
    • isBuiltIn

      boolean isBuiltIn(@NotNull @NotNull String guiId)
    • register

      boolean register(@NotNull @NotNull GuiLayoutDefinition definition)
    • unregister

      boolean unregister(@NotNull @NotNull String guiId)
    • resolve

      @NotNull @NotNull GuiLayout resolve(@NotNull @NotNull String guiId)
    • resolve

      @NotNull @NotNull GuiLayout resolve(@NotNull @NotNull String guiId, int automaticSize)
    • reload

      void reload()
    • getOpenMenu

      @NotNull default @NotNull Optional<MenuView> getOpenMenu(@NotNull @NotNull org.bukkit.entity.Player player)
      What the Zentrix menu a player has open shows, and the texture it was given.
      Parameters:
      player - the viewer
      Returns:
      the menu, or empty when the player has no Zentrix menu open, or one that placed nothing through a guis.yml layout
      Throws:
      IllegalStateException - when called off the main thread
      Since:
      1.15.0
    • refreshBackground

      default boolean refreshBackground(@NotNull @NotNull org.bukkit.entity.Player player)
      Decides the texture of the menu a player has open again, now, and updates its title when it changed. Menus are decided when they open and redraw; call this when something an add-on condition, value or resolver depends on changes while the menu stays open.
      Parameters:
      player - the viewer
      Returns:
      whether the player had a menu with a background to decide
      Throws:
      IllegalStateException - when called off the main thread
      Since:
      1.15.0
    • registerBackgroundCondition

      @NotNull default @NotNull Registration registerBackgroundCondition(@NotNull @NotNull org.bukkit.plugin.Plugin owner, @NotNull @NotNull String name, @NotNull @NotNull MenuBackgroundCondition condition)
      Adds a condition server owners can write in the when of background rules, as namespace:name.

      guis.yml is read again when the registration starts or ends, so rules that use the condition work as soon as it is registered and are reported as unknown once it is gone. Conditions registered while the server starts are in place before any rule is checked.

      Parameters:
      owner - the registering plugin, whose namespace the name is written under
      name - the name within the plugin, using a-z, 0-9, _ and -
      condition - the condition
      Returns:
      the registration, to remove the condition early
      Throws:
      IllegalArgumentException - when the name is invalid, or the plugin already registered a condition or value under it
      Since:
      1.15.0
    • registerBackgroundValue

      @NotNull default @NotNull Registration registerBackgroundValue(@NotNull @NotNull org.bukkit.plugin.Plugin owner, @NotNull @NotNull String name, @NotNull @NotNull MenuBackgroundValue value)
      Adds a value server owners can compare in the when of background rules, as namespace:name. Conditions and values share one set of names per plugin.
      Parameters:
      owner - the registering plugin, whose namespace the name is written under
      name - the name within the plugin, using a-z, 0-9, _ and -
      value - the value
      Returns:
      the registration, to remove the value early
      Throws:
      IllegalArgumentException - when the name is invalid, or the plugin already registered a condition or value under it
      Since:
      1.15.0
      See Also:
    • registerBackgroundResolver

      @NotNull default @NotNull Registration registerBackgroundResolver(@NotNull @NotNull org.bukkit.plugin.Plugin owner, @NotNull @NotNull String menuId, @NotNull @NotNull MenuBackgroundResolver resolver)
      Lets an add-on choose the texture of one menu, or of every menu, itself. See MenuBackgroundResolver for the order resolvers are asked in.

      Menus that are open keep their title until they redraw or are refreshed. In the Free edition, which keeps guis.yml at its defaults, the registration is refused and returned inactive.

      Parameters:
      owner - the registering plugin
      menuId - the menu's ID in guis.yml, or MenuBackgroundResolver.ALL_MENUS
      resolver - the resolver
      Returns:
      the registration, to remove the resolver early
      Since:
      1.15.0