Class WbsMenu

java.lang.Object
wbs.utils.util.menus.WbsMenu
All Implemented Interfaces:
org.bukkit.event.Listener
Direct Known Subclasses:
PagedMenu

public class WbsMenu extends Object implements org.bukkit.event.Listener
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected @Nullable Consumer<org.bukkit.event.inventory.InventoryCloseEvent>
     
    protected @Nullable BiConsumer<WbsMenu,org.bukkit.event.inventory.InventoryCloseEvent>
     
    protected final WbsPlugin
     
    protected final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    WbsMenu(WbsPlugin plugin, String title, int rows, String id)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected int
    getColumn(int rawSlot)
     
    protected int
    Get the number of the last slot in this menu
    protected int
    getRow(int rawSlot)
     
    protected int
    getSlotNumber(int row, int column)
    Get the slot number for a given row and column.
    boolean
    hasMenuOpen(org.bukkit.entity.Player player)
     
    boolean
    isMenu(org.bukkit.inventory.InventoryView view)
     
    boolean
     
    void
    onClick(org.bukkit.event.inventory.InventoryClickEvent event)
     
    void
    onClose(org.bukkit.event.inventory.InventoryCloseEvent event)
     
    void
     
    void
    Fill the first and last rows with the given slot.
    void
    setCloseAction(@Nullable Consumer<org.bukkit.event.inventory.InventoryCloseEvent> closeAction)
     
    void
    setCloseActionMenu(@Nullable BiConsumer<WbsMenu,org.bukkit.event.inventory.InventoryCloseEvent> closeActionMenu)
     
    void
    setColumn(int column, MenuSlot slot)
    Fill a given column with the given slot.
    boolean
    setNextFreeSlot(int minRow, int maxRow, int minColumn, int maxColumn, MenuSlot slot)
    Set the next free slot in a rectangular region bound by a minimum and maximum row and column.
    boolean
    setNextFreeSlot(int minSlotCorner, int maxSlotCorner, MenuSlot slot)
    Set the next free slot in a rectangular region defined by two corners, where the first slot is the upper left corner, and the second slot is the lower right corner.
    boolean
    setNextFreeSlot(int startingAt, MenuSlot slot)
    Add a slot in the next available slot in the menu if any are available
    boolean
    Add a slot in the next available slot in the menu if any are available
    void
    Helper method to set the outline of the menu to a specific slot.
    void
    setOutline(MenuSlot slot, boolean override)
    Helper method to set the outline of the menu to a specific slot.
    void
    setRow(int row, MenuSlot slot)
    Fill a given row with the given slot.
    void
    setSlot(int row, int column, MenuSlot slot)
     
    void
    setSlot(int i, MenuSlot slot)
    Set a menu slot for this
    void
    setUnregisterOnClose(boolean unregisterOnClose)
     
    void
    showTo(org.bukkit.entity.Player player)
     
    boolean
    Unregisters this menu, and closes it for any players that have it open.
    void
    Update all slots for all players currently viewing this menu
    void
    update(int slot)
    Update the given slot for all players currently looking at this menu.
    void
    update(int row, int column)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • plugin

      protected final WbsPlugin plugin
    • rows

      protected final int rows
    • closeAction

      @Nullable protected @Nullable Consumer<org.bukkit.event.inventory.InventoryCloseEvent> closeAction
    • closeActionMenu

      @Nullable protected @Nullable BiConsumer<WbsMenu,org.bukkit.event.inventory.InventoryCloseEvent> closeActionMenu
  • Constructor Details

    • WbsMenu

      public WbsMenu(WbsPlugin plugin, String title, int rows, String id)
      Parameters:
      plugin - The plugin to register this menu to
      title - The title of the menu to show to players
      rows - How many rows to create, between 1 and 6 inclusive
      id - A unique identifier for identifying inventory clicks
  • Method Details

    • update

      public void update(int slot)
      Update the given slot for all players currently looking at this menu.
      Parameters:
      slot - The slot to update.
    • update

      public void update(int row, int column)
    • update

      public void update()
      Update all slots for all players currently viewing this menu
    • unregister

      public boolean unregister()
      Unregisters this menu, and closes it for any players that have it open. Once unregistered, the menu will cease to function.
      Returns:
      True any players had the menu open when it was unregistered.
    • isRegistered

      public boolean isRegistered()
    • register

      public void register()
    • setSlot

      public void setSlot(int i, MenuSlot slot)
      Set a menu slot for this
      Parameters:
      i - The number of the slot
      slot - The menu slot that defines the item, action, and various other properties
    • setSlot

      public void setSlot(int row, int column, MenuSlot slot)
    • setUnregisterOnClose

      public void setUnregisterOnClose(boolean unregisterOnClose)
    • showTo

      public void showTo(org.bukkit.entity.Player player)
    • hasMenuOpen

      public boolean hasMenuOpen(org.bukkit.entity.Player player)
    • isMenu

      public boolean isMenu(org.bukkit.inventory.InventoryView view)
    • onClose

      public void onClose(org.bukkit.event.inventory.InventoryCloseEvent event)
    • setCloseAction

      public void setCloseAction(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryCloseEvent> closeAction)
    • setCloseActionMenu

      public void setCloseActionMenu(@Nullable @Nullable BiConsumer<WbsMenu,org.bukkit.event.inventory.InventoryCloseEvent> closeActionMenu)
    • onClick

      public void onClick(org.bukkit.event.inventory.InventoryClickEvent event)
    • getMaxSlot

      protected int getMaxSlot()
      Get the number of the last slot in this menu
      Returns:
      The maximum slot this menu may contain
    • getSlotNumber

      protected int getSlotNumber(int row, int column)
      Get the slot number for a given row and column.
      Parameters:
      row - The row
      column - The column
      Returns:
      The slot number that represents the slot at the given row and column
    • getRow

      protected int getRow(int rawSlot)
    • getColumn

      protected int getColumn(int rawSlot)
    • setNextFreeSlot

      public boolean setNextFreeSlot(MenuSlot slot)
      Add a slot in the next available slot in the menu if any are available
      Parameters:
      slot - The slot to add at the first unassigned slot
      Returns:
      True if the slot was added, false if no free slots were found.
    • setNextFreeSlot

      public boolean setNextFreeSlot(int startingAt, MenuSlot slot)
      Add a slot in the next available slot in the menu if any are available
      Parameters:
      startingAt - The slot to start checking from.
      slot - The slot to add at the first unassigned slot
      Returns:
      True if the slot was added, false if no free slots were found.
    • setNextFreeSlot

      public boolean setNextFreeSlot(int minRow, int maxRow, int minColumn, int maxColumn, MenuSlot slot)
      Set the next free slot in a rectangular region bound by a minimum and maximum row and column.
      Parameters:
      minRow - The minimum row
      maxRow - The maximum row
      minColumn - The minimum column
      maxColumn - The maximum column
      slot - The slot to add
      Returns:
      True if the slot was added, false if no free slots were found.
    • setNextFreeSlot

      public boolean setNextFreeSlot(int minSlotCorner, int maxSlotCorner, MenuSlot slot)
      Set the next free slot in a rectangular region defined by two corners, where the first slot is the upper left corner, and the second slot is the lower right corner.
      Parameters:
      minSlotCorner - The minimum corner, in the upper left of the region
      maxSlotCorner - The maximum corner, in the lower right of the region
      slot - The slot to add
      Returns:
      True if the slot was added, false if no free slots were found.
    • setOutline

      public void setOutline(MenuSlot slot)
      Helper method to set the outline of the menu to a specific slot. On 1 or 2 row menus, this will fill the entire menu.
      Parameters:
      slot - The slot to use as an outline
    • setOutline

      public void setOutline(MenuSlot slot, boolean override)
      Helper method to set the outline of the menu to a specific slot. On 1 or 2 row menus, this will fill the entire menu.
      Parameters:
      slot - The slot to use as an outline
      override - True to override existing slots, false to only fill empty slots
    • setBanners

      public void setBanners(MenuSlot slot)
      Fill the first and last rows with the given slot. On 1 or 2 row menus, this will fill the entire menu.
      Parameters:
      slot - The slot to use as the "banners" of the menu
    • setRow

      public void setRow(int row, MenuSlot slot)
      Fill a given row with the given slot.
      Parameters:
      row - The row to fill
      slot - The slot to fill the given row with
    • setColumn

      public void setColumn(int column, MenuSlot slot)
      Fill a given column with the given slot.
      Parameters:
      column - The column to fill
      slot - The slot to fill the given column with