Package xyz.xenondevs.invui.gui
Class AbstractGui
java.lang.Object
xyz.xenondevs.invui.gui.AbstractGui
- Direct Known Subclasses:
AbstractPagedGui,AbstractScrollGui,AbstractTabGui
The abstract base class of all
Gui implementations.
Only in very rare circumstances should this class be used directly.
Instead, use the static factory and builder functions in the Gui interfaces,
such as Gui.normal().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstractGui.AbstractBuilder<G extends Gui,S extends Gui.Builder<G, S>> A builder forAbstractGuis.Nested classes/interfaces inherited from interface xyz.xenondevs.invui.gui.Gui
Gui.Builder<G extends Gui,S extends Gui.Builder<G, S>> -
Constructor Summary
ConstructorsConstructorDescriptionAbstractGui(int width, int height) Creates a newAbstractGuiwith the specified width and height. -
Method Summary
Modifier and TypeMethodDescriptionvoidAddsItemsto the gui.voidAdds aGuiParentto thisAbstractGui.voidaddSlotElements(@NotNull SlotElement... slotElements) AddsSlotElementsto theGui.voidapplyStructure(@NotNull Structure structure) voidCancels the runningAnimationif there is one.voidvoidvoidvoidfillBorders(@Nullable Item item, boolean replaceExisting) voidfillColumn(int column, @Nullable Item item, boolean replaceExisting) Fills one column with a specificItemvoidfillRectangle(int x, int y, int width, int height, @Nullable Item item, boolean replaceExisting) voidfillRectangle(int x, int y, int width, @NotNull Inventory inventory, boolean replaceExisting) voidfillRectangle(int x, int y, int width, @NotNull Inventory inventory, @Nullable ItemProvider background, boolean replaceExisting) voidfillRectangle(int x, int y, @NotNull Gui gui, boolean replaceExisting) voidFills one row with a specificItem@NotNull Set<@NotNull org.bukkit.entity.Player> Finds allPlayersthat are currently seeing thisWindow.getAllInventories(Inventory... ignored) Gets allInventoriesthat are used in thisAbstractGui.getAllInventorySlots(Inventory... ignored) Gets allInventoriesand their slots that are used in thisAbstractGui.@Nullable ItemProviderGets theItemProviderthat will be used if nothing else is placed on a slot.intGets the height of theGui@Nullable ItemgetItem(int index) Gets theItemplaced on that slot.@Nullable ItemgetItem(int x, int y) Gets theItemon these coordinates.Gets allGuiParentsof thisAbstractGui.intgetSize()Gets the size of theGui.@Nullable SlotElementgetSlotElement(int index) Gets theSlotElementplaced on that slot.@Nullable SlotElementgetSlotElement(int x, int y) Gets theSlotElementon these coordinates.@Nullable SlotElement @NotNull []Gets allSlotElementsof thisGuiin an Array.intgetWidth()Gets the width of theGuivoidhandleClick(int slotNumber, org.bukkit.entity.Player player, org.bukkit.event.inventory.ClickType clickType, org.bukkit.event.inventory.InventoryClickEvent event) Handles a click on a slot in theAbstractGui.protected voidhandleInvDoubleClick(org.bukkit.event.inventory.InventoryClickEvent event, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack cursor) Handles a double click on anSlotElement.InventorySlotElement.protected voidhandleInvDrop(boolean ctrl, org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked) Handles dropping items from a slot in anSlotElement.InventorySlotElement.protected voidhandleInvItemShift(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked) Handles a shift click on anSlotElement.InventorySlotElement.protected voidhandleInvLeftClick(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked, org.bukkit.inventory.ItemStack cursor) Handles a left click on anSlotElement.InventorySlotElement.protected voidhandleInvMiddleClick(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player) Handles a middle click on anSlotElement.InventorySlotElement.protected voidhandleInvNumberKey(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked) Handles a number key press on anSlotElement.InventorySlotElement.protected voidhandleInvOffHandKey(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked) Handles an off-hand key press on anSlotElement.InventorySlotElement.protected voidhandleInvRightClick(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked, org.bukkit.inventory.ItemStack cursor) Handles a right click on anSlotElement.InventorySlotElement.protected voidhandleInvSlotElementClick(SlotElement.InventorySlotElement element, org.bukkit.event.inventory.InventoryClickEvent event) Handles a click on anSlotElement.InventorySlotElement.booleanhandleItemDrag(UpdateReason updateReason, int slot, org.bukkit.inventory.ItemStack oldStack, org.bukkit.inventory.ItemStack newStack) Handles an item drag on a single slot of thisAbstractGui.voidhandleItemShift(org.bukkit.event.inventory.InventoryClickEvent event) Handles an item shift click from outside thisAbstractGuiinto it.voidhandleSlotElementUpdate(Gui child, int slotIndex) Called by the childGuito report an update of aSlotElement.booleanhasSlotElement(int index) Gets if there is aSlotElementplaced on that slot.booleanhasSlotElement(int x, int y) Gets if there is aSlotElementon these coordinates.booleanisFrozen()Gets if theGuiis frozen.booleanGets whether it is possible to shift-click items into and cursor collect items from allInventoryslots of partially obscured embeddedInventories.voidplayAnimation(@NotNull Animation animation, @Nullable Predicate<@NotNull SlotElement> filter) Plays anAnimation.protected intputIntoFirstInventory(UpdateReason updateReason, org.bukkit.inventory.ItemStack itemStack, Inventory... ignored) Puts anItemStackinto the firstInventorythat accepts it.voidremove(int index) Remove theItemwhich are placed on these slots.voidremove(int x, int y) Removes anItemby its coordinates.voidremoveParent(@NotNull GuiParent parent) Removes aGuiParentfrom thisAbstractGui.voidsetBackground(ItemProvider itemProvider) Sets theItemProviderthat will be used if nothing else is placed on a slot.voidsetFrozen(boolean frozen) Freezes or unfreezes theGui.voidsetIgnoreObscuredInventorySlots(boolean ignoreObscuredInventorySlots) Configures whether it is possible to shift-click items into and cursor collect items from allInventoryslots of partially obscured embeddedInventories.voidSets theItemon these coordinates.voidSets theItemon that slotvoidsetSlotElement(int x, int y, SlotElement slotElement) Sets theSlotElementon these coordinates.voidsetSlotElement(int index, SlotElement slotElement) Sets theSlotElementon these coordinates.voidFinds an updates allControlItemsin thisAbstractGui.
-
Constructor Details
-
AbstractGui
public AbstractGui(int width, int height) Creates a newAbstractGuiwith the specified width and height.- Parameters:
width- The width of the Guiheight- The height of the Gui
-
-
Method Details
-
handleClick
public void handleClick(int slotNumber, org.bukkit.entity.Player player, org.bukkit.event.inventory.ClickType clickType, org.bukkit.event.inventory.InventoryClickEvent event) Handles a click on a slot in theAbstractGui.- Parameters:
slotNumber- The slot number that was clickedplayer- The player that clickedclickType- The type of the clickevent- TheInventoryClickEventthat was triggered
-
handleInvSlotElementClick
protected void handleInvSlotElementClick(SlotElement.InventorySlotElement element, org.bukkit.event.inventory.InventoryClickEvent event) Handles a click on anSlotElement.InventorySlotElement.- Parameters:
element- TheSlotElement.InventorySlotElementthat was clickedevent- TheInventoryClickEventthat was triggered
-
handleInvLeftClick
protected void handleInvLeftClick(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked, org.bukkit.inventory.ItemStack cursor) Handles a left click on anSlotElement.InventorySlotElement.- Parameters:
event- TheInventoryClickEventthat was triggeredinventory- TheInventorythat was clickedslot- The slot that was clickedplayer- ThePlayerthat clickedclicked- TheItemStackthat was clickedcursor- TheItemStackthat is on the cursor
-
handleInvRightClick
protected void handleInvRightClick(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked, org.bukkit.inventory.ItemStack cursor) Handles a right click on anSlotElement.InventorySlotElement.- Parameters:
event- TheInventoryClickEventthat was triggeredinventory- TheInventorythat was clickedslot- The slot that was clickedplayer- ThePlayerthat clickedclicked- TheItemStackthat was clickedcursor- TheItemStackthat is on the cursor
-
handleInvItemShift
protected void handleInvItemShift(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked) Handles a shift click on anSlotElement.InventorySlotElement.- Parameters:
event- TheInventoryClickEventthat was triggeredinventory- TheInventorythat was clickedslot- The slot that was clickedplayer- ThePlayerthat clickedclicked- TheItemStackthat was clicked
-
handleInvNumberKey
protected void handleInvNumberKey(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked) Handles a number key press on anSlotElement.InventorySlotElement.- Parameters:
event- TheInventoryClickEventthat was triggeredinventory- TheInventorythat was clickedslot- The slot that was clickedplayer- ThePlayerthat clickedclicked- TheItemStackthat was clicked
-
handleInvOffHandKey
protected void handleInvOffHandKey(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked) Handles an off-hand key press on anSlotElement.InventorySlotElement.- Parameters:
event- TheInventoryClickEventthat was triggeredinventory- TheInventorythat was clickedslot- The slot that was clickedplayer- ThePlayerthat clickedclicked- TheItemStackthat was clicked
-
handleInvDrop
protected void handleInvDrop(boolean ctrl, org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack clicked) Handles dropping items from a slot in anSlotElement.InventorySlotElement.- Parameters:
ctrl- Whether the player pressed the control keyevent- TheInventoryClickEventthat was triggeredinventory- TheInventorythat was clickedslot- The slot that was clickedplayer- ThePlayerthat clickedclicked- TheItemStackthat was clicked
-
handleInvDoubleClick
protected void handleInvDoubleClick(org.bukkit.event.inventory.InventoryClickEvent event, org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack cursor) Handles a double click on anSlotElement.InventorySlotElement.- Parameters:
event- TheInventoryClickEventthat was triggeredplayer- ThePlayerthat clickedcursor- TheItemStackthat is on the cursor
-
handleInvMiddleClick
protected void handleInvMiddleClick(org.bukkit.event.inventory.InventoryClickEvent event, Inventory inventory, int slot, org.bukkit.entity.Player player) Handles a middle click on anSlotElement.InventorySlotElement.- Parameters:
event- TheInventoryClickEventthat was triggeredinventory- TheInventorythat was clickedslot- The slot that was clicked
-
handleItemDrag
public boolean handleItemDrag(UpdateReason updateReason, int slot, org.bukkit.inventory.ItemStack oldStack, org.bukkit.inventory.ItemStack newStack) Handles an item drag on a single slot of thisAbstractGui.- Parameters:
updateReason- TheUpdateReasonto be used in case the affected slot is anInventoryslot- The slot that was draggedoldStack- The oldItemStackin the slotnewStack- The newItemStackin the slot- Returns:
- Whether the drag was successful.
-
handleItemShift
public void handleItemShift(org.bukkit.event.inventory.InventoryClickEvent event) Handles an item shift click from outside thisAbstractGuiinto it.- Parameters:
event- TheInventoryClickEventthat was triggered
-
putIntoFirstInventory
protected int putIntoFirstInventory(UpdateReason updateReason, org.bukkit.inventory.ItemStack itemStack, Inventory... ignored) Puts anItemStackinto the firstInventorythat accepts it.- Parameters:
updateReason- TheUpdateReasonto be used forInventory.addItem(UpdateReason, ItemStack)itemStack- TheItemStackto put into the firstInventoryignored- TheInventoriesto ignore- Returns:
- The amount of items that could not be put into any
Inventory
-
getAllInventorySlots
Gets allInventoriesand their slots that are used in thisAbstractGui.- Parameters:
ignored- TheInventoriesto ignore- Returns:
- A map of all
Inventoriesand their slots that are visible.
-
getAllInventories
Gets allInventoriesthat are used in thisAbstractGui. IfGui.isIgnoreObscuredInventorySlots(), is true,ObscuredInventorieswill be used to only show the visible slots. Otherwise, this method will just return allInventories, regardless of which of their slots are actually used.- Parameters:
ignored- TheInventoriesto ignore- Returns:
- A collection of all
Inventoriesused in thisAbstractGui.
-
handleSlotElementUpdate
Description copied from interface:GuiParentCalled by the childGuito report an update of aSlotElement.- Specified by:
handleSlotElementUpdatein interfaceGuiParent- Parameters:
child- The childGuiwhoseSlotElementhas changedslotIndex- The slot index of the changedSlotElementin the childGui
-
addParent
Adds aGuiParentto thisAbstractGui.- Parameters:
parent- TheGuiParentto add
-
removeParent
Removes aGuiParentfrom thisAbstractGui.- Parameters:
parent- TheGuiParentto remove
-
getParents
Gets allGuiParentsof thisAbstractGui.- Returns:
- A set of all
GuiParents
-
findAllWindows
Description copied from interface:Gui- Specified by:
findAllWindowsin interfaceGui- Returns:
- The list of
Windowthat show thisGui
-
findAllCurrentViewers
Description copied from interface:GuiFinds allPlayersthat are currently seeing thisWindow.- Specified by:
findAllCurrentViewersin interfaceGui- Returns:
- The list of
Playersthat are currently seeing thisWindow
-
closeForAllViewers
public void closeForAllViewers()Description copied from interface:GuiCloses the openInventoryfor all viewers ofWindowswhere thisGuiis displayed.If the
Windowsare not marked as "retain", they will be removed from theWindowManagerautomatically.- Specified by:
closeForAllViewersin interfaceGui
-
playAnimation
public void playAnimation(@NotNull @NotNull Animation animation, @Nullable @Nullable Predicate<@NotNull SlotElement> filter) Description copied from interface:GuiPlays anAnimation.- Specified by:
playAnimationin interfaceGui- Parameters:
animation- TheAnimationto play.filter- The filter that selects whichSlotElementsshould be animated.
-
cancelAnimation
public void cancelAnimation()Description copied from interface:GuiCancels the runningAnimationif there is one.- Specified by:
cancelAnimationin interfaceGui
-
updateControlItems
public void updateControlItems()Finds an updates allControlItemsin thisAbstractGui. -
setSlotElement
Description copied from interface:GuiSets theSlotElementon these coordinates. If you need to set anItem, please useGui.setItem(int, Item)instead.- Specified by:
setSlotElementin interfaceGui- Parameters:
index- The slot indexslotElement- TheSlotElementto be placed there.
-
addSlotElements
Description copied from interface:GuiAddsSlotElementsto theGui.- Specified by:
addSlotElementsin interfaceGui- Parameters:
slotElements- TheSlotElementsto add.
-
getSlotElement
Description copied from interface:GuiGets theSlotElementplaced on that slot.- Specified by:
getSlotElementin interfaceGui- Parameters:
index- The slot index- Returns:
- The
SlotElementplaced on that slot
-
hasSlotElement
public boolean hasSlotElement(int index) Description copied from interface:GuiGets if there is aSlotElementplaced on that slot.- Specified by:
hasSlotElementin interfaceGui- Parameters:
index- The slot index- Returns:
- If there is a
SlotElementplaced there
-
getSlotElements
Description copied from interface:GuiGets allSlotElementsof thisGuiin an Array.- Specified by:
getSlotElementsin interfaceGui- Returns:
- All
SlotElementsof thisGui
-
setItem
Description copied from interface:GuiSets theItemon that slot -
addItems
Description copied from interface:GuiAddsItemsto the gui. -
getItem
Description copied from interface:GuiGets theItemplaced on that slot. -
getBackground
Description copied from interface:GuiGets theItemProviderthat will be used if nothing else is placed on a slot.- Specified by:
getBackgroundin interfaceGui- Returns:
- The
ItemProvider
-
setBackground
Description copied from interface:GuiSets theItemProviderthat will be used if nothing else is placed on a slot.- Specified by:
setBackgroundin interfaceGui- Parameters:
itemProvider- TheItemProvider
-
remove
public void remove(int index) Description copied from interface:GuiRemove theItemwhich are placed on these slots. -
applyStructure
Description copied from interface:Gui- Specified by:
applyStructurein interfaceGui- Parameters:
structure- The structure
-
getSize
public int getSize()Description copied from interface:GuiGets the size of theGui. -
setFrozen
public void setFrozen(boolean frozen) Description copied from interface:Gui -
isFrozen
public boolean isFrozen()Description copied from interface:GuiGets if theGuiis frozen. -
setIgnoreObscuredInventorySlots
public void setIgnoreObscuredInventorySlots(boolean ignoreObscuredInventorySlots) Description copied from interface:GuiConfigures whether it is possible to shift-click items into and cursor collect items from allInventoryslots of partially obscured embeddedInventories.Defaults to true.
- Specified by:
setIgnoreObscuredInventorySlotsin interfaceGui- Parameters:
ignoreObscuredInventorySlots- Whether obscuredInventoryslots should be ignored when shift-clicking and collecting to the cursor.
-
isIgnoreObscuredInventorySlots
public boolean isIgnoreObscuredInventorySlots()Description copied from interface:GuiGets whether it is possible to shift-click items into and cursor collect items from allInventoryslots of partially obscured embeddedInventories.- Specified by:
isIgnoreObscuredInventorySlotsin interfaceGui- Returns:
- Whether obscured
Inventoryslots are ignored when shift-clicking and collecting to the cursor.
-
setSlotElement
Description copied from interface:GuiSets theSlotElementon these coordinates. If you need to set anItem, please useGui.setItem(int, int, Item)instead.- Specified by:
setSlotElementin interfaceGui- Parameters:
x- The x coordinatey- The y coordinateslotElement- TheSlotElementto be placed there.
-
getSlotElement
Description copied from interface:GuiGets theSlotElementon these coordinates.- Specified by:
getSlotElementin interfaceGui- Parameters:
x- The x coordinatey- The y coordinate- Returns:
- The
SlotElementplaced there
-
hasSlotElement
public boolean hasSlotElement(int x, int y) Description copied from interface:GuiGets if there is aSlotElementon these coordinates.- Specified by:
hasSlotElementin interfaceGui- Parameters:
x- The x coordinatey- The y coordinate- Returns:
- If there is a
SlotElementplaced there
-
setItem
Description copied from interface:GuiSets theItemon these coordinates. -
getItem
Description copied from interface:GuiGets theItemon these coordinates. -
remove
public void remove(int x, int y) Description copied from interface:GuiRemoves anItemby its coordinates. -
getWidth
public int getWidth()Description copied from interface:GuiGets the width of theGui -
getHeight
public int getHeight()Description copied from interface:GuiGets the height of theGui -
fill
Description copied from interface:Gui -
fill
Description copied from interface:Gui -
fillRow
Description copied from interface:GuiFills one row with a specificItem -
fillColumn
Description copied from interface:GuiFills one column with a specificItem- Specified by:
fillColumnin interfaceGui- Parameters:
column- The columnitem- TheItemthat should be used or null to remove an existing item.replaceExisting- If existingItemsshould be replaced.
-
fillBorders
Description copied from interface:Gui- Specified by:
fillBordersin interfaceGui- Parameters:
item- TheItemthat should be used or null to remove an existing item.replaceExisting- If existingItemsshould be replaced.
-
fillRectangle
public void fillRectangle(int x, int y, int width, int height, @Nullable @Nullable Item item, boolean replaceExisting) Description copied from interface:Gui- Specified by:
fillRectanglein interfaceGui- Parameters:
x- The x coordinate where the rectangle should start.y- The y coordinate where the rectangle should start.width- The width of the rectangle.height- The height of the rectangleitem- TheItemthat should be used or null to remove an existing item.replaceExisting- If existingItemsshould be replaced.
-
fillRectangle
Description copied from interface:Gui- Specified by:
fillRectanglein interfaceGui- Parameters:
x- The x coordinate where the rectangle should starty- The y coordinate where the rectangle should startgui- TheGuito be put into thisGuireplaceExisting- If existingSlotElementsshould be replaced.
-
fillRectangle
public void fillRectangle(int x, int y, int width, @NotNull @NotNull Inventory inventory, boolean replaceExisting) Description copied from interface:Gui- Specified by:
fillRectanglein interfaceGui- Parameters:
x- The x coordinate where the rectangle should starty- The y coordinate where the rectangle should startwidth- The line length of the rectangle.inventory- TheInventoryto be put into thisGui.replaceExisting- If existingSlotElementsshould be replaced.
-
fillRectangle
public void fillRectangle(int x, int y, int width, @NotNull @NotNull Inventory inventory, @Nullable @Nullable ItemProvider background, boolean replaceExisting) Description copied from interface:Gui- Specified by:
fillRectanglein interfaceGui- Parameters:
x- The x coordinate where the rectangle should starty- The y coordinate where the rectangle should startwidth- The line length of the rectangle.inventory- TheInventoryto be put into thisGui.background- TheItemProviderfor empty slots of theInventoryreplaceExisting- If existingSlotElementsshould be replaced.
-