Package xyz.xenondevs.invui.window
Class AbstractWindow
java.lang.Object
xyz.xenondevs.invui.window.AbstractWindow
- Direct Known Subclasses:
AbstractDoubleWindow
,AbstractSingleWindow
The abstract base class of all
Window
implementations.
Only in very rare circumstances should this class be used directly.
Instead, use the static builder functions in the
Window
interfaces to create a new Window
, such as
Window.single()
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
AbstractWindow.AbstractBuilder<W extends Window,
S extends Window.Builder<W, S>> Builder for aAbstractWindow
.Nested classes/interfaces inherited from interface xyz.xenondevs.invui.window.Window
Window.Builder<W extends Window,
S extends Window.Builder<W, S>> -
Constructor Summary
ConstructorDescriptionAbstractWindow
(org.bukkit.entity.Player viewer, xyz.xenondevs.inventoryaccess.component.ComponentWrapper title, int size, boolean closeable) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCloseHandler
(@NotNull Runnable closeHandler) Adds a close handler that will be called when this window gets closed.void
addOpenHandler
(@NotNull Runnable openHandler) Adds an open handler that will be called when this window gets opened.void
addOutsideClickHandler
(@NotNull Consumer<@NotNull org.bukkit.event.inventory.InventoryClickEvent> outsideClickHandler) Adds an outside click handler that will be called when a player clicks outside the inventory.void
changeTitle
(@NotNull String title) Changes the title of theInventory
.void
changeTitle
(@NotNull net.md_5.bungee.api.chat.BaseComponent[] title) Changes the title of theInventory
.void
changeTitle
(@NotNull xyz.xenondevs.inventoryaccess.component.ComponentWrapper title) Changes the title of theInventory
.void
close()
Closes the underlyingInventory
for its viewer.Gets the contentinventories
associated with thisWindow
.@Nullable org.bukkit.entity.Player
Gets the currentPlayer
that is viewing thisWindow
or null of there isn't one.protected abstract Pair
<AbstractGui, Integer> getGuiAt
(int index) Gets theAbstractGui
at the given index.protected abstract AbstractGui[]
getGuis()
protected abstract org.bukkit.inventory.Inventory[]
Gets theinventories
associated with thisWindow
.protected Map
<Integer, SlotElement> getInvSlotElements
(Inventory inventory) protected Map
<Integer, SlotElement> getItemSlotElements
(Item item) @NotNull String
getLang()
protected abstract SlotElement
getSlotElement
(int index) Gets theSlotElement
at the given index.@NotNull org.bukkit.entity.Player
Gets the viewer of thisWindow
@NotNull UUID
Gets the viewer'sUUID
protected abstract void
handleClick
(org.bukkit.event.inventory.InventoryClickEvent event) Handles a click in theWindow
.void
handleClickEvent
(org.bukkit.event.inventory.InventoryClickEvent event) protected abstract void
Handles the closing of theWindow
.void
handleCloseEvent
(boolean forceClose) void
handleCursorCollect
(org.bukkit.event.inventory.InventoryClickEvent event) void
handleDragEvent
(org.bukkit.event.inventory.InventoryDragEvent event) void
handleInventoryUpdate
(Inventory inventory) void
handleItemProviderUpdate
(Item item) protected abstract void
handleItemShift
(org.bukkit.event.inventory.InventoryClickEvent event) Handles an item-shift action in theWindow
.protected abstract void
Handles the opening of theWindow
.void
handleOpenEvent
(org.bukkit.event.inventory.InventoryOpenEvent event) abstract void
handleViewerDeath
(org.bukkit.event.entity.PlayerDeathEvent event) Handles the death of the viewer of theWindow
.protected abstract void
Initializes the items in theWindow
.boolean
Gets if the player is able to close theInventory
.boolean
isOpen()
Gets if the viewer is currently viewing thisWindow
.void
open()
Shows the window to the player.protected void
openInventory
(@NotNull org.bukkit.entity.Player viewer) protected void
redrawItem
(int index) Redraws the currentSlotElement
at the given slot index.protected void
redrawItem
(int index, SlotElement element, boolean setItem) Redraws theSlotElement
at the given index.void
removeCloseHandler
(@NotNull Runnable closeHandler) Removes a close handler that has been added previously.void
removeOutsideClickHandler
(@NotNull Consumer<@NotNull org.bukkit.event.inventory.InventoryClickEvent> outsideClickHandler) Removes an outside click handler that has been added previously.void
setCloseable
(boolean closeable) Sets if the player should be able to close theInventory
.void
setCloseHandlers
(@Nullable List<@NotNull Runnable> closeHandlers) Replaces the currently registered close handlers with the given list.protected abstract void
setInvItem
(int slot, org.bukkit.inventory.ItemStack itemStack) Puts the givenItemStack
into the inventory at the given slot.void
setOpenHandlers
(@Nullable List<@NotNull Runnable> openHandlers) Replaces the currently registered open handlers with the given list.void
setOutsideClickHandlers
(@Nullable List<@NotNull Consumer<@NotNull org.bukkit.event.inventory.InventoryClickEvent>> outsideClickHandlers) Replaces the currently registered outside click handlers with the given list.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface xyz.xenondevs.invui.gui.GuiParent
handleSlotElementUpdate
Methods inherited from interface xyz.xenondevs.invui.window.Window
getPlayerItems
-
Constructor Details
-
AbstractWindow
public AbstractWindow(org.bukkit.entity.Player viewer, xyz.xenondevs.inventoryaccess.component.ComponentWrapper title, int size, boolean closeable)
-
-
Method Details
-
redrawItem
protected void redrawItem(int index) Redraws the currentSlotElement
at the given slot index.- Parameters:
index
- The slot index.
-
redrawItem
Redraws theSlotElement
at the given index.- Parameters:
index
- The slot index.element
- TheSlotElement
at the index.setItem
- Whether theSlotElement
was newly set.
-
handleDragEvent
public void handleDragEvent(org.bukkit.event.inventory.InventoryDragEvent event) -
handleClickEvent
public void handleClickEvent(org.bukkit.event.inventory.InventoryClickEvent event) -
handleCursorCollect
public void handleCursorCollect(org.bukkit.event.inventory.InventoryClickEvent event) -
handleItemProviderUpdate
-
handleInventoryUpdate
-
getItemSlotElements
-
getInvSlotElements
-
open
public void open()Description copied from interface:Window
Shows the window to the player. -
openInventory
protected void openInventory(@NotNull @NotNull org.bukkit.entity.Player viewer) -
handleOpenEvent
public void handleOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent event) -
close
public void close()Description copied from interface:Window
Closes the underlyingInventory
for its viewer. -
handleCloseEvent
public void handleCloseEvent(boolean forceClose) -
changeTitle
public void changeTitle(@NotNull @NotNull xyz.xenondevs.inventoryaccess.component.ComponentWrapper title) Description copied from interface:Window
Changes the title of theInventory
.- Specified by:
changeTitle
in interfaceWindow
- Parameters:
title
- The new title
-
changeTitle
public void changeTitle(@NotNull @NotNull net.md_5.bungee.api.chat.BaseComponent[] title) Description copied from interface:Window
Changes the title of theInventory
.- Specified by:
changeTitle
in interfaceWindow
- Parameters:
title
- The new title
-
changeTitle
Description copied from interface:Window
Changes the title of theInventory
.- Specified by:
changeTitle
in interfaceWindow
- Parameters:
title
- The new title
-
setOpenHandlers
Description copied from interface:Window
Replaces the currently registered open handlers with the given list.- Specified by:
setOpenHandlers
in interfaceWindow
- Parameters:
openHandlers
- The new open handlers
-
addOpenHandler
Description copied from interface:Window
Adds an open handler that will be called when this window gets opened.- Specified by:
addOpenHandler
in interfaceWindow
- Parameters:
openHandler
- The close handler to add
-
setCloseHandlers
Description copied from interface:Window
Replaces the currently registered close handlers with the given list.- Specified by:
setCloseHandlers
in interfaceWindow
- Parameters:
closeHandlers
- The new close handlers
-
addCloseHandler
Description copied from interface:Window
Adds a close handler that will be called when this window gets closed.- Specified by:
addCloseHandler
in interfaceWindow
- Parameters:
closeHandler
- The close handler to add
-
removeCloseHandler
Description copied from interface:Window
Removes a close handler that has been added previously.- Specified by:
removeCloseHandler
in interfaceWindow
- Parameters:
closeHandler
- The close handler to remove
-
setOutsideClickHandlers
public void setOutsideClickHandlers(@Nullable @Nullable List<@NotNull Consumer<@NotNull org.bukkit.event.inventory.InventoryClickEvent>> outsideClickHandlers) Description copied from interface:Window
Replaces the currently registered outside click handlers with the given list.- Specified by:
setOutsideClickHandlers
in interfaceWindow
- Parameters:
outsideClickHandlers
- The new outside click handlers
-
addOutsideClickHandler
public void addOutsideClickHandler(@NotNull @NotNull Consumer<@NotNull org.bukkit.event.inventory.InventoryClickEvent> outsideClickHandler) Description copied from interface:Window
Adds an outside click handler that will be called when a player clicks outside the inventory.- Specified by:
addOutsideClickHandler
in interfaceWindow
- Parameters:
outsideClickHandler
- The outside click handler to add
-
removeOutsideClickHandler
public void removeOutsideClickHandler(@NotNull @NotNull Consumer<@NotNull org.bukkit.event.inventory.InventoryClickEvent> outsideClickHandler) Description copied from interface:Window
Removes an outside click handler that has been added previously.- Specified by:
removeOutsideClickHandler
in interfaceWindow
- Parameters:
outsideClickHandler
- The outside click handler to remove
-
getCurrentViewer
@Nullable public @Nullable org.bukkit.entity.Player getCurrentViewer()Description copied from interface:Window
Gets the currentPlayer
that is viewing thisWindow
or null of there isn't one.- Specified by:
getCurrentViewer
in interfaceWindow
- Returns:
- The current viewer of this
Window
(can be null)
-
getViewer
@NotNull public @NotNull org.bukkit.entity.Player getViewer()Description copied from interface:Window
Gets the viewer of thisWindow
-
getLang
-
getViewerUUID
Description copied from interface:Window
Gets the viewer'sUUID
- Specified by:
getViewerUUID
in interfaceWindow
- Returns:
- The viewer's
UUID
-
isCloseable
public boolean isCloseable()Description copied from interface:Window
Gets if the player is able to close theInventory
.- Specified by:
isCloseable
in interfaceWindow
- Returns:
- If the player is able to close the
Inventory
.
-
setCloseable
public void setCloseable(boolean closeable) Description copied from interface:Window
Sets if the player should be able to close theInventory
.- Specified by:
setCloseable
in interfaceWindow
- Parameters:
closeable
- If the player should be able to close theInventory
.
-
isOpen
public boolean isOpen()Description copied from interface:Window
Gets if the viewer is currently viewing thisWindow
. -
setInvItem
protected abstract void setInvItem(int slot, org.bukkit.inventory.ItemStack itemStack) Puts the givenItemStack
into the inventory at the given slot.- Parameters:
slot
- The slot to put the item into.itemStack
- The item to put into the inventory.
-
getSlotElement
Gets theSlotElement
at the given index.- Parameters:
index
- The index of the slot.- Returns:
- The
SlotElement
at the given index.
-
getGuiAt
Gets theAbstractGui
at the given index.- Parameters:
index
- The index of the slot.- Returns:
- The
AbstractGui
it's slot at that slot.
-
getGuis
- Returns:
- The guis displayed with this window.
-
getInventories
protected abstract org.bukkit.inventory.Inventory[] getInventories()Gets theinventories
associated with thisWindow
.- Returns:
- The inventories associated with this window.
-
getContentInventories
Gets the contentinventories
associated with thisWindow
. These are not UI inventories, but actual inventories contained inside theGui
, such asVirtualInventory
- Returns:
- The content inventories associated with this window.
-
initItems
protected abstract void initItems()Initializes the items in theWindow
. -
handleOpened
protected abstract void handleOpened()Handles the opening of theWindow
. -
handleClosed
protected abstract void handleClosed()Handles the closing of theWindow
. -
handleClick
protected abstract void handleClick(org.bukkit.event.inventory.InventoryClickEvent event) Handles a click in theWindow
.- Parameters:
event
- TheInventoryClickEvent
that occurred.
-
handleItemShift
protected abstract void handleItemShift(org.bukkit.event.inventory.InventoryClickEvent event) Handles an item-shift action in theWindow
.- Parameters:
event
- TheInventoryClickEvent
that occurred.
-
handleViewerDeath
public abstract void handleViewerDeath(org.bukkit.event.entity.PlayerDeathEvent event) Handles the death of the viewer of theWindow
.- Parameters:
event
- ThePlayerDeathEvent
that occurred.
-