Class AbstractWindow

java.lang.Object
xyz.xenondevs.invui.window.AbstractWindow
All Implemented Interfaces:
GuiParent, Window
Direct Known Subclasses:
AbstractDoubleWindow, AbstractSingleWindow

public abstract class AbstractWindow extends Object implements Window, GuiParent
The abstract base class of all Window implementations.

Only in very rare circumstances should this class be used directly. Instead, use the static builder functions in the Window interfaces to create a new Window, such as Window.single().

  • Constructor Details

    • AbstractWindow

      public AbstractWindow(org.bukkit.entity.Player viewer, xyz.xenondevs.inventoryaccess.component.ComponentWrapper title, int size, boolean closeable)
  • Method Details

    • redrawItem

      protected void redrawItem(int index)
      Redraws the current SlotElement at the given slot index.
      Parameters:
      index - The slot index.
    • redrawItem

      protected void redrawItem(int index, SlotElement element, boolean setItem)
      Redraws the SlotElement at the given index.
      Parameters:
      index - The slot index.
      element - The SlotElement at the index.
      setItem - Whether the SlotElement was newly set.
    • handleDragEvent

      public void handleDragEvent(org.bukkit.event.inventory.InventoryDragEvent event)
    • handleClickEvent

      public void handleClickEvent(org.bukkit.event.inventory.InventoryClickEvent event)
    • handleCursorCollect

      public void handleCursorCollect(org.bukkit.event.inventory.InventoryClickEvent event)
    • handleItemProviderUpdate

      public void handleItemProviderUpdate(Item item)
    • handleInventoryUpdate

      public void handleInventoryUpdate(Inventory inventory)
    • getItemSlotElements

      protected Map<Integer,SlotElement> getItemSlotElements(Item item)
    • getInvSlotElements

      protected Map<Integer,SlotElement> getInvSlotElements(Inventory inventory)
    • open

      public void open()
      Description copied from interface: Window
      Shows the window to the player.
      Specified by:
      open in interface Window
    • openInventory

      protected void openInventory(@NotNull @NotNull org.bukkit.entity.Player viewer)
    • handleOpenEvent

      public void handleOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent event)
    • close

      public void close()
      Description copied from interface: Window
      Closes the underlying Inventory for its viewer.
      Specified by:
      close in interface Window
    • handleCloseEvent

      public void handleCloseEvent(boolean forceClose)
    • changeTitle

      public void changeTitle(@NotNull @NotNull xyz.xenondevs.inventoryaccess.component.ComponentWrapper title)
      Description copied from interface: Window
      Changes the title of the Inventory.
      Specified by:
      changeTitle in interface Window
      Parameters:
      title - The new title
    • changeTitle

      public void changeTitle(@NotNull @NotNull net.md_5.bungee.api.chat.BaseComponent[] title)
      Description copied from interface: Window
      Changes the title of the Inventory.
      Specified by:
      changeTitle in interface Window
      Parameters:
      title - The new title
    • changeTitle

      public void changeTitle(@NotNull @NotNull String title)
      Description copied from interface: Window
      Changes the title of the Inventory.
      Specified by:
      changeTitle in interface Window
      Parameters:
      title - The new title
    • setOpenHandlers

      public void setOpenHandlers(@Nullable @Nullable List<@NotNull Runnable> openHandlers)
      Description copied from interface: Window
      Replaces the currently registered open handlers with the given list.
      Specified by:
      setOpenHandlers in interface Window
      Parameters:
      openHandlers - The new open handlers
    • addOpenHandler

      public void addOpenHandler(@NotNull @NotNull Runnable openHandler)
      Description copied from interface: Window
      Adds an open handler that will be called when this window gets opened.
      Specified by:
      addOpenHandler in interface Window
      Parameters:
      openHandler - The close handler to add
    • setCloseHandlers

      public void setCloseHandlers(@Nullable @Nullable List<@NotNull Runnable> closeHandlers)
      Description copied from interface: Window
      Replaces the currently registered close handlers with the given list.
      Specified by:
      setCloseHandlers in interface Window
      Parameters:
      closeHandlers - The new close handlers
    • addCloseHandler

      public void addCloseHandler(@NotNull @NotNull Runnable closeHandler)
      Description copied from interface: Window
      Adds a close handler that will be called when this window gets closed.
      Specified by:
      addCloseHandler in interface Window
      Parameters:
      closeHandler - The close handler to add
    • removeCloseHandler

      public void removeCloseHandler(@NotNull @NotNull Runnable closeHandler)
      Description copied from interface: Window
      Removes a close handler that has been added previously.
      Specified by:
      removeCloseHandler in interface Window
      Parameters:
      closeHandler - The close handler to remove
    • setOutsideClickHandlers

      public void setOutsideClickHandlers(@Nullable @Nullable List<@NotNull Consumer<@NotNull org.bukkit.event.inventory.InventoryClickEvent>> outsideClickHandlers)
      Description copied from interface: Window
      Replaces the currently registered outside click handlers with the given list.
      Specified by:
      setOutsideClickHandlers in interface Window
      Parameters:
      outsideClickHandlers - The new outside click handlers
    • addOutsideClickHandler

      public void addOutsideClickHandler(@NotNull @NotNull Consumer<@NotNull org.bukkit.event.inventory.InventoryClickEvent> outsideClickHandler)
      Description copied from interface: Window
      Adds an outside click handler that will be called when a player clicks outside the inventory.
      Specified by:
      addOutsideClickHandler in interface Window
      Parameters:
      outsideClickHandler - The outside click handler to add
    • removeOutsideClickHandler

      public void removeOutsideClickHandler(@NotNull @NotNull Consumer<@NotNull org.bukkit.event.inventory.InventoryClickEvent> outsideClickHandler)
      Description copied from interface: Window
      Removes an outside click handler that has been added previously.
      Specified by:
      removeOutsideClickHandler in interface Window
      Parameters:
      outsideClickHandler - The outside click handler to remove
    • getCurrentViewer

      @Nullable public @Nullable org.bukkit.entity.Player getCurrentViewer()
      Description copied from interface: Window
      Gets the current Player that is viewing this Window or null of there isn't one.
      Specified by:
      getCurrentViewer in interface Window
      Returns:
      The current viewer of this Window (can be null)
    • getViewer

      @NotNull public @NotNull org.bukkit.entity.Player getViewer()
      Description copied from interface: Window
      Gets the viewer of this Window
      Specified by:
      getViewer in interface Window
      Returns:
      The viewer of this window.
    • getLang

      @NotNull public @NotNull String getLang()
    • getViewerUUID

      @NotNull public @NotNull UUID getViewerUUID()
      Description copied from interface: Window
      Gets the viewer's UUID
      Specified by:
      getViewerUUID in interface Window
      Returns:
      The viewer's UUID
    • isCloseable

      public boolean isCloseable()
      Description copied from interface: Window
      Gets if the player is able to close the Inventory.
      Specified by:
      isCloseable in interface Window
      Returns:
      If the player is able to close the Inventory.
    • setCloseable

      public void setCloseable(boolean closeable)
      Description copied from interface: Window
      Sets if the player should be able to close the Inventory.
      Specified by:
      setCloseable in interface Window
      Parameters:
      closeable - If the player should be able to close the Inventory.
    • isOpen

      public boolean isOpen()
      Description copied from interface: Window
      Gets if the viewer is currently viewing this Window.
      Specified by:
      isOpen in interface Window
      Returns:
      If the Window is currently open.
    • setInvItem

      protected abstract void setInvItem(int slot, org.bukkit.inventory.ItemStack itemStack)
      Puts the given ItemStack into the inventory at the given slot.
      Parameters:
      slot - The slot to put the item into.
      itemStack - The item to put into the inventory.
    • getSlotElement

      protected abstract SlotElement getSlotElement(int index)
      Gets the SlotElement at the given index.
      Parameters:
      index - The index of the slot.
      Returns:
      The SlotElement at the given index.
    • getGuiAt

      protected abstract Pair<AbstractGui,Integer> getGuiAt(int index)
      Gets the AbstractGui at the given index.
      Parameters:
      index - The index of the slot.
      Returns:
      The AbstractGui it's slot at that slot.
    • getGuis

      protected abstract AbstractGui[] getGuis()
      Gets the guis displayed with this Window, does not contain the guis embedded in other guis.
      Returns:
      The guis displayed with this window.
    • getInventories

      protected abstract org.bukkit.inventory.Inventory[] getInventories()
      Gets the inventories associated with this Window.
      Returns:
      The inventories associated with this window.
    • getContentInventories

      protected abstract List<Inventory> getContentInventories()
      Gets the content inventories associated with this Window. These are not UI inventories, but actual inventories contained inside the Gui, such as VirtualInventory
      Returns:
      The content inventories associated with this window.
    • initItems

      protected abstract void initItems()
      Initializes the items in the Window.
    • handleOpened

      protected abstract void handleOpened()
      Handles the opening of the Window.
    • handleClosed

      protected abstract void handleClosed()
      Handles the closing of the Window.
    • handleClick

      protected abstract void handleClick(org.bukkit.event.inventory.InventoryClickEvent event)
      Handles a click in the Window.
      Parameters:
      event - The InventoryClickEvent that occurred.
    • handleItemShift

      protected abstract void handleItemShift(org.bukkit.event.inventory.InventoryClickEvent event)
      Handles an item-shift action in the Window.
      Parameters:
      event - The InventoryClickEvent that occurred.
    • handleViewerDeath

      public abstract void handleViewerDeath(org.bukkit.event.entity.PlayerDeathEvent event)
      Handles the death of the viewer of the Window.
      Parameters:
      event - The PlayerDeathEvent that occurred.