Package me.despical.inventoryframework
Class Gui
java.lang.Object
me.despical.inventoryframework.Gui
- All Implemented Interfaces:
org.bukkit.inventory.InventoryHolder
The base class of all GUIs
- Since:
- 1.0.1
Created at 04.09.2020
- Author:
- Despical
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a pane to this guivoidclose()Closes the inventory in the next server tick for all viewers.voidCloses the inventory for all viewers.protected @NotNull HumanEntityCacheGets the human entity cache used for this gui@NotNull org.bukkit.inventory.Inventorystatic org.bukkit.inventory.InventorygetInventory(org.bukkit.inventory.InventoryView view, int rawSlot) @NotNull Collection<GuiItem> getItems()Gets all the items in all underlying panes@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> Gets the bottom click event assigned to this gui, or null if there is no bottom click assigned.@Nullable Consumer<org.bukkit.event.inventory.InventoryCloseEvent> Gets the on close event assigned to this gui, or null if no close event is assigned.@Nullable Consumer<org.bukkit.event.inventory.InventoryDragEvent> Gets the global click event assigned to this gui, or null if there is no global click assigned.@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> Gets the global click event assigned to this gui, or null if there is no global click assigned.@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> Gets the outside click event assigned to this gui, or null if there is no outside click assigned.@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> Gets the top click event assigned to this gui, or null if there is no top click assigned.getPanes()Gets all the panes in this gui, this includes child panes from other panesintgetRows()Returns the amount of rows this gui currently has@NotNull Gui.StategetState()Gets the state of this gui@NotNull StringgetTitle()Returns the title of this guiintGets the count ofHumanEntityinstances that are currently viewing this GUI.@NotNull List<org.bukkit.entity.HumanEntity> Gets a mutable snapshot of the currentHumanEntityviewers of this GUI.booleanGets whether this gui is being updated, as invoked byupdate().static @Nullable Guiload(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Object instance, @NotNull InputStream inputStream) Loads a Gui from a given input stream.static @NotNull GuiloadOrThrow(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Object instance, @NotNull InputStream inputStream) Loads a Gui from a given input stream.static @NotNull PaneLoads a pane by the given instance and nodestatic voidregisterPane(@NotNull String name, @NotNull BiFunction<Object, Element, Pane> biFunction) Registers a name that can be used inside an XML file to add custom panesstatic voidregisterProperty(@NotNull String attributeName, @NotNull Function<String, Object> function) Registers a property that can be used inside an XML file to add additional new properties.voidRemoves all the panes stored in this gui instance.voidsetOnBottomClick(@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onBottomClick) Set the consumer that should be called whenever the inventory is clicked in.voidsetOnClose(@Nullable Consumer<org.bukkit.event.inventory.InventoryCloseEvent> onClose) Set the consumer that should be called whenever this gui is closed.voidSet the consumer that should be called whenever player drags item in this gui.voidsetOnGlobalClick(@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onGlobalClick) Set the consumer that should be called whenever this gui or inventory is clicked in.voidsetOnLocalClick(@NotNull Consumer<org.bukkit.event.inventory.InventoryClickEvent> onLocalClick) Set the consumer that should be called whenever this gui is clicked in.voidsetOnOutsideClick(@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onOutsideClick) Set the consumer that should be called whenever a player clicks outside the gui.voidsetOnTopClick(@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onTopClick) Set the consumer that should be called whenever this gui is clicked in.voidsetRows(int rows) Sets the amount of rows for this inventory.voidCalling this method will set the state of this gui.voidSets the title for this inventory.voidshow(@NotNull org.bukkit.entity.HumanEntity humanEntity) Shows a gui to a playervoidupdate()Update the gui for everyone
-
Constructor Details
-
Gui
public Gui(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, int rows, @NotNull @NotNull String title) Constructs a new GUI- Parameters:
plugin- the main plugin.rows- the amount of rows this gui should contain, in range 1..6.title- the title/name of this gui.
-
-
Method Details
-
load
@Nullable public static @Nullable Gui load(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Object instance, @NotNull @NotNull InputStream inputStream) Loads a Gui from a given input stream. Returns null instead of throwing an exception in case of a failure.- Parameters:
plugin- the main plugininstance- the class instance for all reflection lookupsinputStream- the file- Returns:
- the gui or null if the loading failed
- See Also:
-
loadOrThrow
@NotNull public static @NotNull Gui loadOrThrow(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Object instance, @NotNull @NotNull InputStream inputStream) Loads a Gui from a given input stream. Throws aRuntimeExceptioninstead of returning null in case of a failure.- Parameters:
plugin- the main plugininstance- the class instance for all reflection lookupsinputStream- the file- Returns:
- the gui
- See Also:
-
getInventory
public static org.bukkit.inventory.Inventory getInventory(org.bukkit.inventory.InventoryView view, int rawSlot) -
registerProperty
public static void registerProperty(@NotNull @NotNull String attributeName, @NotNull @NotNull Function<String, Object> function) Registers a property that can be used inside an XML file to add additional new properties.- Parameters:
attributeName- the name of the property. This is the same name you'll be using to specify the property type in the XML file.function- how the property should be processed. This converts the raw text input from the XML node value into the correct object type.- Throws:
IllegalArgumentException- when a property with this name is already registered.
-
registerPane
public static void registerPane(@NotNull @NotNull String name, @NotNull @NotNull BiFunction<Object, Element, Pane> biFunction) Registers a name that can be used inside an XML file to add custom panes- Parameters:
name- the name of the pane to be used in the XML filebiFunction- how the pane loading should be processed- Throws:
IllegalArgumentException- when a pane with this name is already registered
-
loadPane
@NotNull public static @NotNull Pane loadPane(@NotNull @NotNull Object instance, @NotNull @NotNull Node node) Loads a pane by the given instance and node- Parameters:
instance- the instancenode- the node- Returns:
- the pane
-
addPane
Adds a pane to this gui- Parameters:
pane- the pane to add
-
show
public void show(@NotNull @NotNull org.bukkit.entity.HumanEntity humanEntity) Shows a gui to a player- Parameters:
humanEntity- the human entity to show the gui to
-
close
public void close()Closes the inventory in the next server tick for all viewers. -
closeInstantly
public void closeInstantly()Closes the inventory for all viewers. -
getViewerCount
@Contract(pure=true) public int getViewerCount()Gets the count ofHumanEntityinstances that are currently viewing this GUI.- Returns:
- the count of viewers
- Since:
- 1.0.1
-
getViewers
Gets a mutable snapshot of the currentHumanEntityviewers of this GUI. This is a snapshot (copy) and not a view, therefore modifications aren't visible.- Returns:
- a snapshot of the current viewers
- Since:
- 1.0.1
- See Also:
-
getPanes
Gets all the panes in this gui, this includes child panes from other panes- Returns:
- all panes
-
removePanes
public void removePanes()Removes all the panes stored in this gui instance. -
getItems
Gets all the items in all underlying panes- Returns:
- all items
-
update
public void update()Update the gui for everyone -
getState
Gets the state of this gui- Returns:
- the state
- Since:
- 1.0.1
-
setState
Calling this method will set the state of this gui. If this state is set to top state, it will restore all the stored inventories of the players and will assume no pane extends into the bottom inventory part. If the state is set to bottom state it will assume one or more panes overflow into the bottom half of the inventory and will store all players' inventories and clear those.Do not call this method if you just want the player's inventory to be cleared.
- Parameters:
state- the new gui state- Since:
- 1.0.1
-
getHumanEntityCache
Gets the human entity cache used for this gui- Returns:
- the human entity cache
- Since:
- 1.0.1
- See Also:
-
getOnTopClick
@Nullable @Contract(pure=true) public @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> getOnTopClick()Gets the top click event assigned to this gui, or null if there is no top click assigned.- Returns:
- the top click
- Since:
- 1.0.1
-
setOnTopClick
public void setOnTopClick(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onTopClick) Set the consumer that should be called whenever this gui is clicked in.- Parameters:
onTopClick- the consumer that gets called
-
getOnBottomClick
@Nullable @Contract(pure=true) public @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> getOnBottomClick()Gets the bottom click event assigned to this gui, or null if there is no bottom click assigned.- Returns:
- the bottom click
- Since:
- 1.0.1
-
setOnBottomClick
public void setOnBottomClick(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onBottomClick) Set the consumer that should be called whenever the inventory is clicked in.- Parameters:
onBottomClick- the consumer that gets called
-
getOnGlobalClick
@Nullable @Contract(pure=true) public @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> getOnGlobalClick()Gets the global click event assigned to this gui, or null if there is no global click assigned.- Returns:
- the global click
- Since:
- 1.0.1
-
setOnGlobalClick
public void setOnGlobalClick(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onGlobalClick) Set the consumer that should be called whenever this gui or inventory is clicked in.- Parameters:
onGlobalClick- the consumer that gets called
-
getOnOutsideClick
@Nullable @Contract(pure=true) public @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> getOnOutsideClick()Gets the outside click event assigned to this gui, or null if there is no outside click assigned.- Returns:
- the outside click
- Since:
- 1.0.1
-
setOnOutsideClick
public void setOnOutsideClick(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onOutsideClick) Set the consumer that should be called whenever a player clicks outside the gui.- Parameters:
onOutsideClick- the consumer that gets called- Since:
- 1.0.1
-
setOnLocalClick
public void setOnLocalClick(@NotNull @NotNull Consumer<org.bukkit.event.inventory.InventoryClickEvent> onLocalClick) Set the consumer that should be called whenever this gui is clicked in.- Parameters:
onLocalClick- the consumer that gets called
-
getOnDrag
@Nullable @Contract(pure=true) public @Nullable Consumer<org.bukkit.event.inventory.InventoryDragEvent> getOnDrag()Gets the global click event assigned to this gui, or null if there is no global click assigned.- Returns:
- the global click
- Since:
- 1.0.6
-
setOnDrag
public void setOnDrag(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryDragEvent> onDrag) Set the consumer that should be called whenever player drags item in this gui.- Parameters:
onDrag- the consumer that gets called
-
getOnClose
@Nullable @Contract(pure=true) public @Nullable Consumer<org.bukkit.event.inventory.InventoryCloseEvent> getOnClose()Gets the on close event assigned to this gui, or null if no close event is assigned.- Returns:
- the on close event
- Since:
- 1.0.1
-
setOnClose
public void setOnClose(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryCloseEvent> onClose) Set the consumer that should be called whenever this gui is closed.- Parameters:
onClose- the consumer that gets called
-
getRows
public int getRows()Returns the amount of rows this gui currently has- Returns:
- the amount of rows
-
setRows
public void setRows(int rows) Sets the amount of rows for this inventory. This will (unlike most other methods) directly update itself in order to ensure all viewers will still be viewing the new inventory as well.- Parameters:
rows- the amount of rows in range 1..6.
-
getTitle
Returns the title of this gui- Returns:
- the title
-
setTitle
Sets the title for this inventory. This will (unlike most other methods) directly update itself in order to ensure all viewers will still be viewing the new inventory as well.- Parameters:
title- the title
-
getInventory
@NotNull public @NotNull org.bukkit.inventory.Inventory getInventory()- Specified by:
getInventoryin interfaceorg.bukkit.inventory.InventoryHolder
-
isUpdating
@Contract(pure=true) public boolean isUpdating()Gets whether this gui is being updated, as invoked byupdate(). This returns true if this is the case and false otherwise.- Returns:
- whether this gui is being updated
- Since:
- 1.0.1
-