Package redempt.redlib.inventorygui
Class InventoryGUI
java.lang.Object
redempt.redlib.inventorygui.InventoryGUI
- All Implemented Interfaces:
org.bukkit.event.Listener
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.bukkit.inventory.ItemStackA gray stained glass pane with no name. -
Constructor Summary
ConstructorsConstructorDescriptionInventoryGUI(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 TypeMethodDescriptionvoidaddButton(int slot, ItemButton button) Add a button to the GUI in the given slotvoidaddButton(ItemButton button, int slot) Add a button to the GUI in the given slotvoidaddButton(ItemButton button, int x, int y) Add a button at the given position in the inventoryvoidclear()Clears the inventory and its buttonsvoidclearSlot(int slot) Clears a single slot, removing a button if it is presentvoidcloseSlot(int slot) Closes a slot so that items can't be placed in itvoidcloseSlots(int start, int end) Closes slots so that items can't be placed in themvoidcloseSlots(int x1, int y1, int x2, int y2) Closes slots so that items can't be placed in themvoiddestroy()Remove this inventory as a listener and clean everything up to prevent memory leaks.voiddestroy(org.bukkit.entity.Player lastViewer) Remove this inventory as a listener and clean everything up to prevent memory leaks.booleanReturns whether this GUI is destroyed when it has been closed by all viewersvoidfill(int x1, int y1, int x2, int y2, org.bukkit.inventory.ItemStack item) Fill a section of the inventory with the given itemvoidfill(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.InventoryGets the inventory this GUI is wrappingGets the open slotsintgetSize()Gets the inventory sizevoidonClick(org.bukkit.event.inventory.InventoryClickEvent e) voidonClose(org.bukkit.event.inventory.InventoryCloseEvent e) voidonDrag(org.bukkit.event.inventory.InventoryDragEvent e) voidopen(org.bukkit.entity.Player player) Opens this GUI for a playervoidopenSlot(int slot) Opens a slot so that items can be placed in itvoidopenSlots(int start, int end) Opens slots so that items can be placed in themvoidopenSlots(int x1, int y1, int x2, int y2) Opens slots so that items can be placed in themvoidremoveButton(ItemButton button) Remove a button from the inventorybooleanReturns whether or not items in open slots are returned to the player when this inventory is destroyedvoidsetDestroyOnClose(boolean destroyOnClose) Sets whether this GUI is destroyed when it has been closed by all viewersvoidsetOnClickOpenSlot(BiConsumer<org.bukkit.event.inventory.InventoryClickEvent, List<Integer>> handler) Sets the handler for when an open slot is clickedvoidsetOnClickOpenSlot(Consumer<org.bukkit.event.inventory.InventoryClickEvent> handler) Sets the handler for when an open slot is clickedvoidsetOnDestroy(Runnable onDestroy) Sets a callback to be run when this GUI is destroyedvoidsetOnDragOpenSlot(Consumer<org.bukkit.event.inventory.InventoryDragEvent> onDrag) Sets the handler for when items are drag-clicked into open slotsvoidsetReturnsItems(boolean returnItems) Sets whether items in open slots are returned to the player when this inventory is destroyedvoidupdate()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)
-