Class InventoryGUI

java.lang.Object
redempt.redlib.inventorygui.InventoryGUI
All Implemented Interfaces:
org.bukkit.event.Listener

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

    Fields
    Modifier and Type
    Field
    Description
    static final org.bukkit.inventory.ItemStack
    A gray stained glass pane with no name.
  • Constructor Summary

    Constructors
    Constructor
    Description
    InventoryGUI(int size, String name)
    Creates a new GUI, instantiating a new inventory with the given size and name
    InventoryGUI(org.bukkit.inventory.Inventory inventory)
    Creates a new GUI from an inventory
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addButton(int slot, ItemButton button)
    Add a button to the GUI in the given slot
    void
    addButton(ItemButton button, int slot)
    Add a button to the GUI in the given slot
    void
    addButton(ItemButton button, int x, int y)
    Add a button at the given position in the inventory
    void
    Clears the inventory and its buttons
    void
    clearSlot(int slot)
    Clears a single slot, removing a button if it is present
    void
    closeSlot(int slot)
    Closes a slot so that items can't be placed in it
    void
    closeSlots(int start, int end)
    Closes slots so that items can't be placed in them
    void
    closeSlots(int x1, int y1, int x2, int y2)
    Closes slots so that items can't be placed in them
    void
    Remove this inventory as a listener and clean everything up to prevent memory leaks.
    void
    destroy(org.bukkit.entity.Player lastViewer)
    Remove this inventory as a listener and clean everything up to prevent memory leaks.
    boolean
    Returns whether this GUI is destroyed when it has been closed by all viewers
    void
    fill(int x1, int y1, int x2, int y2, org.bukkit.inventory.ItemStack item)
    Fill a section of the inventory with the given item
    void
    fill(int start, int end, org.bukkit.inventory.ItemStack item)
    Fill a section of the inventory with the given item
    getButton(int slot)
    Gets the ItemButton in a given slot
     
    org.bukkit.inventory.Inventory
    Gets the inventory this GUI is wrapping
    Gets the open slots
    int
    Gets the inventory size
    void
    onClick(org.bukkit.event.inventory.InventoryClickEvent e)
     
    void
    onClose(org.bukkit.event.inventory.InventoryCloseEvent e)
     
    void
    onDrag(org.bukkit.event.inventory.InventoryDragEvent e)
     
    void
    open(org.bukkit.entity.Player player)
    Opens this GUI for a player
    void
    openSlot(int slot)
    Opens a slot so that items can be placed in it
    void
    openSlots(int start, int end)
    Opens slots so that items can be placed in them
    void
    openSlots(int x1, int y1, int x2, int y2)
    Opens slots so that items can be placed in them
    void
    Remove a button from the inventory
    boolean
    Returns whether or not items in open slots are returned to the player when this inventory is destroyed
    void
    setDestroyOnClose(boolean destroyOnClose)
    Sets whether this GUI is destroyed when it has been closed by all viewers
    void
    setOnClickOpenSlot(BiConsumer<org.bukkit.event.inventory.InventoryClickEvent,List<Integer>> handler)
    Sets the handler for when an open slot is clicked
    void
    setOnClickOpenSlot(Consumer<org.bukkit.event.inventory.InventoryClickEvent> handler)
    Sets the handler for when an open slot is clicked
    void
    Sets a callback to be run when this GUI is destroyed
    void
    setOnDragOpenSlot(Consumer<org.bukkit.event.inventory.InventoryDragEvent> onDrag)
    Sets the handler for when items are drag-clicked into open slots
    void
    setReturnsItems(boolean returnItems)
    Sets whether items in open slots are returned to the player when this inventory is destroyed
    void
    Refresh the inventory.

    Methods inherited from class java.lang.Object

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

    • FILLER

      public static final org.bukkit.inventory.ItemStack FILLER
      A gray stained glass pane with no name. Good for filling empty slots in GUIs.
  • Constructor Details

    • InventoryGUI

      public InventoryGUI(org.bukkit.inventory.Inventory inventory)
      Creates a new GUI from an inventory
      Parameters:
      inventory - The inventory to create a GUI from
    • InventoryGUI

      public InventoryGUI(int size, String name)
      Creates a new GUI, instantiating a new inventory with the given size and name
      Parameters:
      size - The size of the inventory
      name - The name of the inventory
  • Method Details

    • getInventory

      public org.bukkit.inventory.Inventory getInventory()
      Gets the inventory this GUI is wrapping
      Returns:
      The wrapped inventory
    • getSize

      public int getSize()
      Gets the inventory size
      Returns:
      The inventory size
    • addButton

      public void addButton(ItemButton button, int slot)
      Add a button to the GUI in the given slot
      Parameters:
      button - The button to be added
      slot - The slot to add the button to
    • addButton

      public void addButton(int slot, ItemButton button)
      Add a button to the GUI in the given slot
      Parameters:
      button - The button to be added
      slot - The slot to add the button to
    • addButton

      public void addButton(ItemButton button, int x, int y)
      Add a button at the given position in the inventory
      Parameters:
      button - The button to be added
      x - The X position to add the button at
      y - The Y position to add the button at
    • fill

      public void fill(int start, int end, org.bukkit.inventory.ItemStack item)
      Fill a section of the inventory with the given item
      Parameters:
      start - The starting index to fill from, inclusive
      end - The ending index to fill to, exclusive
      item - The item to set in these slots
    • fill

      public void fill(int x1, int y1, int x2, int y2, org.bukkit.inventory.ItemStack item)
      Fill a section of the inventory with the given item
      Parameters:
      x1 - The X position to fill from, inclusive
      y1 - The Y position to fill from, inclusive
      x2 - The X position to fill to, exclusive
      y2 - The Y position to fill to, exclusive
      item - The item to set in these slots
    • removeButton

      public void removeButton(ItemButton button)
      Remove a button from the inventory
      Parameters:
      button - The button to be removed
    • getButtons

      public List<ItemButton> getButtons()
      Returns:
      All the ItemButtons in this GUI
    • getButton

      public ItemButton getButton(int slot)
      Gets the ItemButton in a given slot
      Parameters:
      slot - The slot the button is in
      Returns:
      The ItemButton, or null if there is no button in that slot
    • clearSlot

      public void clearSlot(int slot)
      Clears a single slot, removing a button if it is present
      Parameters:
      slot - The slot to clear
    • update

      public void update()
      Refresh the inventory.
    • openSlot

      public void openSlot(int slot)
      Opens a slot so that items can be placed in it
      Parameters:
      slot - The slot to open
    • openSlots

      public void openSlots(int start, int end)
      Opens slots so that items can be placed in them
      Parameters:
      start - The start of the open slot section, inclusive
      end - The end of the open slot section, exclusive
    • openSlots

      public void openSlots(int x1, int y1, int x2, int y2)
      Opens slots so that items can be placed in them
      Parameters:
      x1 - The x position to open from, inclusive
      y1 - The y position to open from, inclusive
      x2 - The x position to open to, exclusive
      y2 - The y position to open to, exclusive
    • closeSlot

      public void closeSlot(int slot)
      Closes a slot so that items can't be placed in it
      Parameters:
      slot - The slot to open
    • closeSlots

      public void closeSlots(int start, int end)
      Closes slots so that items can't be placed in them
      Parameters:
      start - The start of the closed slot section, inclusive
      end - The end of the open closed section, exclusive
    • closeSlots

      public void closeSlots(int x1, int y1, int x2, int y2)
      Closes slots so that items can't be placed in them
      Parameters:
      x1 - The x position to close from, inclusive
      y1 - The y position to close from, inclusive
      x2 - The x position to close to, exclusive
      y2 - The y position to close to, exclusive
    • getOpenSlots

      public Set<Integer> getOpenSlots()
      Gets the open slots
      Returns:
      The set of open slots
    • open

      public void open(org.bukkit.entity.Player player)
      Opens this GUI for a player
      Parameters:
      player - The player to open this GUI for
    • returnsItems

      public boolean returnsItems()
      Returns whether or not items in open slots are returned to the player when this inventory is destroyed
      Returns:
      Whether or not items in open slots are returned to the player when this inventory is destroyed
    • setReturnsItems

      public void setReturnsItems(boolean returnItems)
      Sets whether items in open slots are returned to the player when this inventory is destroyed
      Parameters:
      returnItems - Whether items in open slots should be returned to the player when this inventory is destroyed
    • destroysOnClose

      public boolean destroysOnClose()
      Returns whether this GUI is destroyed when it has been closed by all viewers
      Returns:
      Whether this GUI is destroyed when it has been closed by all viewers
    • setDestroyOnClose

      public void setDestroyOnClose(boolean destroyOnClose)
      Sets whether this GUI is destroyed when it has been closed by all viewers
      Parameters:
      destroyOnClose - Whether this GUI is destroyed when it has been closed by all viewers
    • setOnDestroy

      public void setOnDestroy(Runnable onDestroy)
      Sets a callback to be run when this GUI is destroyed
      Parameters:
      onDestroy - The callback
    • setOnClickOpenSlot

      public void setOnClickOpenSlot(Consumer<org.bukkit.event.inventory.InventoryClickEvent> handler)
      Sets the handler for when an open slot is clicked
      Parameters:
      handler - The handler for when an open slot is clicked
    • setOnClickOpenSlot

      public void setOnClickOpenSlot(BiConsumer<org.bukkit.event.inventory.InventoryClickEvent,List<Integer>> handler)
      Sets the handler for when an open slot is clicked
      Parameters:
      handler - The handler for when an open slot is clicked, taking the event and list of affected slots
    • destroy

      public void destroy(org.bukkit.entity.Player lastViewer)
      Remove this inventory as a listener and clean everything up to prevent memory leaks. Call this when the GUI is no longer being used.
      Parameters:
      lastViewer - The last Player who was viewing this GUI, to have the items returned to them.
    • destroy

      public void destroy()
      Remove this inventory as a listener and clean everything up to prevent memory leaks. Call this when the GUI is no longer being used.
    • clear

      public void clear()
      Clears the inventory and its buttons
    • setOnDragOpenSlot

      public void setOnDragOpenSlot(Consumer<org.bukkit.event.inventory.InventoryDragEvent> onDrag)
      Sets the handler for when items are drag-clicked into open slots
      Parameters:
      onDrag - The handler
    • onDrag

      public void onDrag(org.bukkit.event.inventory.InventoryDragEvent e)
    • onClick

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

      public void onClose(org.bukkit.event.inventory.InventoryCloseEvent e)