Package redempt.redlib.inventorygui
Class InventoryGUI
java.lang.Object
redempt.redlib.inventorygui.InventoryGUI
- All Implemented Interfaces:
org.bukkit.event.Listener
-
Field Summary
Modifier and TypeFieldDescriptionstatic final org.bukkit.inventory.ItemStack
A gray stained glass pane with no name. -
Constructor Summary
ConstructorDescriptionInventoryGUI
(int size, String name) Creates a new GUI, instantiating a new inventory with the given size and nameInventoryGUI
(org.bukkit.inventory.Inventory inventory) Creates a new GUI from an inventory -
Method Summary
Modifier and TypeMethodDescriptionvoid
addButton
(int slot, ItemButton button) Add a button to the GUI in the given slotvoid
addButton
(ItemButton button, int slot) Add a button to the GUI in the given slotvoid
addButton
(ItemButton button, int x, int y) Add a button at the given position in the inventoryvoid
clear()
Clears the inventory and its buttonsvoid
clearSlot
(int slot) Clears a single slot, removing a button if it is presentvoid
closeSlot
(int slot) Closes a slot so that items can't be placed in itvoid
closeSlots
(int start, int end) Closes slots so that items can't be placed in themvoid
closeSlots
(int x1, int y1, int x2, int y2) Closes slots so that items can't be placed in themvoid
destroy()
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 viewersvoid
fill
(int x1, int y1, int x2, int y2, org.bukkit.inventory.ItemStack item) Fill a section of the inventory with the given itemvoid
fill
(int start, int end, org.bukkit.inventory.ItemStack item) Fill a section of the inventory with the given itemgetButton
(int slot) Gets the ItemButton in a given slotorg.bukkit.inventory.Inventory
Gets the inventory this GUI is wrappingGets the open slotsint
getSize()
Gets the inventory sizevoid
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 playervoid
openSlot
(int slot) Opens a slot so that items can be placed in itvoid
openSlots
(int start, int end) Opens slots so that items can be placed in themvoid
openSlots
(int x1, int y1, int x2, int y2) Opens slots so that items can be placed in themvoid
removeButton
(ItemButton button) Remove a button from the inventoryboolean
Returns whether or not items in open slots are returned to the player when this inventory is destroyedvoid
setDestroyOnClose
(boolean destroyOnClose) Sets whether this GUI is destroyed when it has been closed by all viewersvoid
setOnClickOpenSlot
(BiConsumer<org.bukkit.event.inventory.InventoryClickEvent, List<Integer>> handler) Sets the handler for when an open slot is clickedvoid
setOnClickOpenSlot
(Consumer<org.bukkit.event.inventory.InventoryClickEvent> handler) Sets the handler for when an open slot is clickedvoid
setOnDestroy
(Runnable onDestroy) Sets a callback to be run when this GUI is destroyedvoid
setOnDragOpenSlot
(Consumer<org.bukkit.event.inventory.InventoryDragEvent> onDrag) Sets the handler for when items are drag-clicked into open slotsvoid
setReturnsItems
(boolean returnItems) Sets whether items in open slots are returned to the player when this inventory is destroyedvoid
update()
Refresh the inventory.
-
Field Details
-
FILLER
public static final org.bukkit.inventory.ItemStack FILLERA 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
Creates a new GUI, instantiating a new inventory with the given size and name- Parameters:
size
- The size of the inventoryname
- 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
Add a button to the GUI in the given slot- Parameters:
button
- The button to be addedslot
- The slot to add the button to
-
addButton
Add a button to the GUI in the given slot- Parameters:
button
- The button to be addedslot
- The slot to add the button to
-
addButton
Add a button at the given position in the inventory- Parameters:
button
- The button to be addedx
- The X position to add the button aty
- 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, inclusiveend
- The ending index to fill to, exclusiveitem
- 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, inclusivey1
- The Y position to fill from, inclusivex2
- The X position to fill to, exclusivey2
- The Y position to fill to, exclusiveitem
- The item to set in these slots
-
removeButton
Remove a button from the inventory- Parameters:
button
- The button to be removed
-
getButtons
- Returns:
- All the ItemButtons in this GUI
-
getButton
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, inclusiveend
- 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, inclusivey1
- The y position to open from, inclusivex2
- The x position to open to, exclusivey2
- 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, inclusiveend
- 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, inclusivey1
- The y position to close from, inclusivex2
- The x position to close to, exclusivey2
- The y position to close to, exclusive
-
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
Sets a callback to be run when this GUI is destroyed- Parameters:
onDestroy
- The callback
-
setOnClickOpenSlot
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
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)
-