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
Modifier and TypeClassDescriptionstatic class
AbstractGui.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
ConstructorDescriptionAbstractGui
(int width, int height) Creates a newAbstractGui
with the specified width and height. -
Method Summary
Modifier and TypeMethodDescriptionvoid
AddsItems
to the gui.void
Adds aGuiParent
to thisAbstractGui
.void
addSlotElements
(@NotNull SlotElement... slotElements) AddsSlotElements
to theGui
.void
applyStructure
(@NotNull Structure structure) void
Cancels the runningAnimation
if there is one.void
void
void
void
fillBorders
(@Nullable Item item, boolean replaceExisting) void
fillColumn
(int column, @Nullable Item item, boolean replaceExisting) Fills one column with a specificItem
void
fillRectangle
(int x, int y, int width, int height, @Nullable Item item, boolean replaceExisting) void
fillRectangle
(int x, int y, int width, @NotNull Inventory inventory, boolean replaceExisting) void
fillRectangle
(int x, int y, int width, @NotNull Inventory inventory, @Nullable ItemProvider background, boolean replaceExisting) void
fillRectangle
(int x, int y, @NotNull Gui gui, boolean replaceExisting) void
Fills one row with a specificItem
@NotNull Set
<@NotNull org.bukkit.entity.Player> Finds allPlayers
that are currently seeing thisWindow
.getAllInventories
(Inventory... ignored) Gets allInventories
that are used in thisAbstractGui
.getAllInventorySlots
(Inventory... ignored) Gets allInventories
and their slots that are used in thisAbstractGui
.@Nullable ItemProvider
Gets theItemProvider
that will be used if nothing else is placed on a slot.int
Gets the height of theGui
@Nullable Item
getItem
(int index) Gets theItem
placed on that slot.@Nullable Item
getItem
(int x, int y) Gets theItem
on these coordinates.Gets allGuiParents
of thisAbstractGui
.int
getSize()
Gets the size of theGui
.@Nullable SlotElement
getSlotElement
(int index) Gets theSlotElement
placed on that slot.@Nullable SlotElement
getSlotElement
(int x, int y) Gets theSlotElement
on these coordinates.@Nullable SlotElement @NotNull []
Gets allSlotElements
of thisGui
in an Array.int
getWidth()
Gets the width of theGui
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
.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
.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
.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
.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
.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
.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
.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
.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
.protected void
handleInvSlotElementClick
(SlotElement.InventorySlotElement element, org.bukkit.event.inventory.InventoryClickEvent event) Handles a click on anSlotElement.InventorySlotElement
.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
.void
handleItemShift
(org.bukkit.event.inventory.InventoryClickEvent event) Handles an item shift click from outside thisAbstractGui
into it.void
handleSlotElementUpdate
(Gui child, int slotIndex) Called by the childGui
to report an update of aSlotElement
.boolean
hasSlotElement
(int index) Gets if there is aSlotElement
placed on that slot.boolean
hasSlotElement
(int x, int y) Gets if there is aSlotElement
on these coordinates.boolean
isFrozen()
Gets if theGui
is frozen.boolean
Gets whether it is possible to shift-click items into and cursor collect items from allInventory
slots of partially obscured embeddedInventories
.void
playAnimation
(@NotNull Animation animation, @Nullable Predicate<@NotNull SlotElement> filter) Plays anAnimation
.protected int
putIntoFirstInventory
(UpdateReason updateReason, org.bukkit.inventory.ItemStack itemStack, Inventory... ignored) Puts anItemStack
into the firstInventory
that accepts it.void
remove
(int index) Remove theItem
which are placed on these slots.void
remove
(int x, int y) Removes anItem
by its coordinates.void
removeParent
(@NotNull GuiParent parent) Removes aGuiParent
from thisAbstractGui
.void
setBackground
(ItemProvider itemProvider) Sets theItemProvider
that will be used if nothing else is placed on a slot.void
setFrozen
(boolean frozen) Freezes or unfreezes theGui
.void
setIgnoreObscuredInventorySlots
(boolean ignoreObscuredInventorySlots) Configures whether it is possible to shift-click items into and cursor collect items from allInventory
slots of partially obscured embeddedInventories
.void
Sets theItem
on these coordinates.void
Sets theItem
on that slotvoid
setSlotElement
(int x, int y, SlotElement slotElement) Sets theSlotElement
on these coordinates.void
setSlotElement
(int index, SlotElement slotElement) Sets theSlotElement
on these coordinates.void
Finds an updates allControlItems
in thisAbstractGui
.
-
Constructor Details
-
AbstractGui
public AbstractGui(int width, int height) Creates a newAbstractGui
with 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
- TheInventoryClickEvent
that was triggered
-
handleInvSlotElementClick
protected void handleInvSlotElementClick(SlotElement.InventorySlotElement element, org.bukkit.event.inventory.InventoryClickEvent event) Handles a click on anSlotElement.InventorySlotElement
.- Parameters:
element
- TheSlotElement.InventorySlotElement
that was clickedevent
- TheInventoryClickEvent
that 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
- TheInventoryClickEvent
that was triggeredinventory
- TheInventory
that was clickedslot
- The slot that was clickedplayer
- ThePlayer
that clickedclicked
- TheItemStack
that was clickedcursor
- TheItemStack
that 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
- TheInventoryClickEvent
that was triggeredinventory
- TheInventory
that was clickedslot
- The slot that was clickedplayer
- ThePlayer
that clickedclicked
- TheItemStack
that was clickedcursor
- TheItemStack
that 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
- TheInventoryClickEvent
that was triggeredinventory
- TheInventory
that was clickedslot
- The slot that was clickedplayer
- ThePlayer
that clickedclicked
- TheItemStack
that 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
- TheInventoryClickEvent
that was triggeredinventory
- TheInventory
that was clickedslot
- The slot that was clickedplayer
- ThePlayer
that clickedclicked
- TheItemStack
that 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
- TheInventoryClickEvent
that was triggeredinventory
- TheInventory
that was clickedslot
- The slot that was clickedplayer
- ThePlayer
that clickedclicked
- TheItemStack
that 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
- TheInventoryClickEvent
that was triggeredinventory
- TheInventory
that was clickedslot
- The slot that was clickedplayer
- ThePlayer
that clickedclicked
- TheItemStack
that 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
- TheInventoryClickEvent
that was triggeredplayer
- ThePlayer
that clickedcursor
- TheItemStack
that 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
- TheInventoryClickEvent
that was triggeredinventory
- TheInventory
that 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
- TheUpdateReason
to be used in case the affected slot is anInventory
slot
- The slot that was draggedoldStack
- The oldItemStack
in the slotnewStack
- The newItemStack
in 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 thisAbstractGui
into it.- Parameters:
event
- TheInventoryClickEvent
that was triggered
-
putIntoFirstInventory
protected int putIntoFirstInventory(UpdateReason updateReason, org.bukkit.inventory.ItemStack itemStack, Inventory... ignored) Puts anItemStack
into the firstInventory
that accepts it.- Parameters:
updateReason
- TheUpdateReason
to be used forInventory.addItem(UpdateReason, ItemStack)
itemStack
- TheItemStack
to put into the firstInventory
ignored
- TheInventories
to ignore- Returns:
- The amount of items that could not be put into any
Inventory
-
getAllInventorySlots
Gets allInventories
and their slots that are used in thisAbstractGui
.- Parameters:
ignored
- TheInventories
to ignore- Returns:
- A map of all
Inventories
and their slots that are visible.
-
getAllInventories
Gets allInventories
that are used in thisAbstractGui
. IfGui.isIgnoreObscuredInventorySlots()
, is true,ObscuredInventories
will 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
- TheInventories
to ignore- Returns:
- A collection of all
Inventories
used in thisAbstractGui
.
-
handleSlotElementUpdate
Description copied from interface:GuiParent
Called by the childGui
to report an update of aSlotElement
.- Specified by:
handleSlotElementUpdate
in interfaceGuiParent
- Parameters:
child
- The childGui
whoseSlotElement
has changedslotIndex
- The slot index of the changedSlotElement
in the childGui
-
addParent
Adds aGuiParent
to thisAbstractGui
.- Parameters:
parent
- TheGuiParent
to add
-
removeParent
Removes aGuiParent
from thisAbstractGui
.- Parameters:
parent
- TheGuiParent
to remove
-
getParents
Gets allGuiParents
of thisAbstractGui
.- Returns:
- A set of all
GuiParents
-
findAllWindows
Description copied from interface:Gui
- Specified by:
findAllWindows
in interfaceGui
- Returns:
- The list of
Window
that show thisGui
-
findAllCurrentViewers
Description copied from interface:Gui
Finds allPlayers
that are currently seeing thisWindow
.- Specified by:
findAllCurrentViewers
in interfaceGui
- Returns:
- The list of
Players
that are currently seeing thisWindow
-
closeForAllViewers
public void closeForAllViewers()Description copied from interface:Gui
Closes the openInventory
for all viewers ofWindows
where thisGui
is displayed.If the
Windows
are not marked as "retain", they will be removed from theWindowManager
automatically.- Specified by:
closeForAllViewers
in interfaceGui
-
playAnimation
public void playAnimation(@NotNull @NotNull Animation animation, @Nullable @Nullable Predicate<@NotNull SlotElement> filter) Description copied from interface:Gui
Plays anAnimation
.- Specified by:
playAnimation
in interfaceGui
- Parameters:
animation
- TheAnimation
to play.filter
- The filter that selects whichSlotElements
should be animated.
-
cancelAnimation
public void cancelAnimation()Description copied from interface:Gui
Cancels the runningAnimation
if there is one.- Specified by:
cancelAnimation
in interfaceGui
-
updateControlItems
public void updateControlItems()Finds an updates allControlItems
in thisAbstractGui
. -
setSlotElement
Description copied from interface:Gui
Sets theSlotElement
on these coordinates. If you need to set anItem
, please useGui.setItem(int, Item)
instead.- Specified by:
setSlotElement
in interfaceGui
- Parameters:
index
- The slot indexslotElement
- TheSlotElement
to be placed there.
-
addSlotElements
Description copied from interface:Gui
AddsSlotElements
to theGui
.- Specified by:
addSlotElements
in interfaceGui
- Parameters:
slotElements
- TheSlotElements
to add.
-
getSlotElement
Description copied from interface:Gui
Gets theSlotElement
placed on that slot.- Specified by:
getSlotElement
in interfaceGui
- Parameters:
index
- The slot index- Returns:
- The
SlotElement
placed on that slot
-
hasSlotElement
public boolean hasSlotElement(int index) Description copied from interface:Gui
Gets if there is aSlotElement
placed on that slot.- Specified by:
hasSlotElement
in interfaceGui
- Parameters:
index
- The slot index- Returns:
- If there is a
SlotElement
placed there
-
getSlotElements
Description copied from interface:Gui
Gets allSlotElements
of thisGui
in an Array.- Specified by:
getSlotElements
in interfaceGui
- Returns:
- All
SlotElements
of thisGui
-
setItem
Description copied from interface:Gui
Sets theItem
on that slot -
addItems
Description copied from interface:Gui
AddsItems
to the gui. -
getItem
Description copied from interface:Gui
Gets theItem
placed on that slot. -
getBackground
Description copied from interface:Gui
Gets theItemProvider
that will be used if nothing else is placed on a slot.- Specified by:
getBackground
in interfaceGui
- Returns:
- The
ItemProvider
-
setBackground
Description copied from interface:Gui
Sets theItemProvider
that will be used if nothing else is placed on a slot.- Specified by:
setBackground
in interfaceGui
- Parameters:
itemProvider
- TheItemProvider
-
remove
public void remove(int index) Description copied from interface:Gui
Remove theItem
which are placed on these slots. -
applyStructure
Description copied from interface:Gui
- Specified by:
applyStructure
in interfaceGui
- Parameters:
structure
- The structure
-
getSize
public int getSize()Description copied from interface:Gui
Gets the size of theGui
. -
setFrozen
public void setFrozen(boolean frozen) Description copied from interface:Gui
-
isFrozen
public boolean isFrozen()Description copied from interface:Gui
Gets if theGui
is frozen. -
setIgnoreObscuredInventorySlots
public void setIgnoreObscuredInventorySlots(boolean ignoreObscuredInventorySlots) Description copied from interface:Gui
Configures whether it is possible to shift-click items into and cursor collect items from allInventory
slots of partially obscured embeddedInventories
.Defaults to true.
- Specified by:
setIgnoreObscuredInventorySlots
in interfaceGui
- Parameters:
ignoreObscuredInventorySlots
- Whether obscuredInventory
slots should be ignored when shift-clicking and collecting to the cursor.
-
isIgnoreObscuredInventorySlots
public boolean isIgnoreObscuredInventorySlots()Description copied from interface:Gui
Gets whether it is possible to shift-click items into and cursor collect items from allInventory
slots of partially obscured embeddedInventories
.- Specified by:
isIgnoreObscuredInventorySlots
in interfaceGui
- Returns:
- Whether obscured
Inventory
slots are ignored when shift-clicking and collecting to the cursor.
-
setSlotElement
Description copied from interface:Gui
Sets theSlotElement
on these coordinates. If you need to set anItem
, please useGui.setItem(int, int, Item)
instead.- Specified by:
setSlotElement
in interfaceGui
- Parameters:
x
- The x coordinatey
- The y coordinateslotElement
- TheSlotElement
to be placed there.
-
getSlotElement
Description copied from interface:Gui
Gets theSlotElement
on these coordinates.- Specified by:
getSlotElement
in interfaceGui
- Parameters:
x
- The x coordinatey
- The y coordinate- Returns:
- The
SlotElement
placed there
-
hasSlotElement
public boolean hasSlotElement(int x, int y) Description copied from interface:Gui
Gets if there is aSlotElement
on these coordinates.- Specified by:
hasSlotElement
in interfaceGui
- Parameters:
x
- The x coordinatey
- The y coordinate- Returns:
- If there is a
SlotElement
placed there
-
setItem
Description copied from interface:Gui
Sets theItem
on these coordinates. -
getItem
Description copied from interface:Gui
Gets theItem
on these coordinates. -
remove
public void remove(int x, int y) Description copied from interface:Gui
Removes anItem
by its coordinates. -
getWidth
public int getWidth()Description copied from interface:Gui
Gets the width of theGui
-
getHeight
public int getHeight()Description copied from interface:Gui
Gets the height of theGui
-
fill
Description copied from interface:Gui
-
fill
Description copied from interface:Gui
-
fillRow
Description copied from interface:Gui
Fills one row with a specificItem
-
fillColumn
Description copied from interface:Gui
Fills one column with a specificItem
- Specified by:
fillColumn
in interfaceGui
- Parameters:
column
- The columnitem
- TheItem
that should be used or null to remove an existing item.replaceExisting
- If existingItems
should be replaced.
-
fillBorders
Description copied from interface:Gui
- Specified by:
fillBorders
in interfaceGui
- Parameters:
item
- TheItem
that should be used or null to remove an existing item.replaceExisting
- If existingItems
should 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:
fillRectangle
in 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
- TheItem
that should be used or null to remove an existing item.replaceExisting
- If existingItems
should be replaced.
-
fillRectangle
Description copied from interface:Gui
- Specified by:
fillRectangle
in interfaceGui
- Parameters:
x
- The x coordinate where the rectangle should starty
- The y coordinate where the rectangle should startgui
- TheGui
to be put into thisGui
replaceExisting
- If existingSlotElements
should 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:
fillRectangle
in 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
- TheInventory
to be put into thisGui
.replaceExisting
- If existingSlotElements
should 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:
fillRectangle
in 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
- TheInventory
to be put into thisGui
.background
- TheItemProvider
for empty slots of theInventory
replaceExisting
- If existingSlotElements
should be replaced.
-