Class Gui
java.lang.Object
com.github.stefvanschie.inventoryframework.gui.type.util.Gui
The base class of all GUIs
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @NotNull HumanEntityCacheA player cache for storing player's inventoriesprotected org.bukkit.inventory.InventoryThe inventory of this guiprotected @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent>The consumer that will be called once a players clicks in the bottom-half of the guiprotected @Nullable Consumer<org.bukkit.event.inventory.InventoryDragEvent>The consumer that will be called once a player drags in the bottom-half of the guiprotected @Nullable Consumer<org.bukkit.event.inventory.InventoryCloseEvent>The consumer that will be called once a player closes the guiprotected @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent>The consumer that will be called once a players clicks in the gui or in their inventoryprotected @Nullable Consumer<org.bukkit.event.inventory.InventoryDragEvent>The consumer that will be called once a player drags in the gui or their inventoryprotected @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent>The consumer that will be called once a player clicks outside of the gui screenprotected @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent>The consumer that will be called once a players clicks in the top-half of the guiprotected @Nullable Consumer<org.bukkit.event.inventory.InventoryDragEvent>The consumer that will be called once a player drags in the top-half of the gui -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddInventory(@NotNull org.bukkit.inventory.Inventory inventory, @NotNull Gui gui)Adds the specified inventory and gui, so we can properly intercept clicks.voidcallOnBottomClick(@NotNull org.bukkit.event.inventory.InventoryClickEvent event)Calls the consumer (if it's not null) that was specified usingsetOnBottomClick(Consumer), so the consumer that should be called whenever the inventory is clicked in.voidcallOnBottomDrag(@NotNull org.bukkit.event.inventory.InventoryDragEvent event)Calls the consumer (if it's not null) that was specified usingsetOnBottomDrag(Consumer), so the consumer that should be called whenever the inventory is dragged in.voidcallOnClose(@NotNull org.bukkit.event.inventory.InventoryCloseEvent event)Calls the consumer (if it's not null) that was specified usingsetOnClose(Consumer), so the consumer that should be called whenever this gui is closed.voidcallOnGlobalClick(@NotNull org.bukkit.event.inventory.InventoryClickEvent event)Calls the consumer (if it's not null) that was specified usingsetOnGlobalClick(Consumer), so the consumer that should be called whenever this gui or inventory is clicked in.voidcallOnGlobalDrag(@NotNull org.bukkit.event.inventory.InventoryDragEvent event)Calls the consumer (if it's not null) that was specified usingsetOnGlobalDrag(Consumer), so the consumer that should be called whenever this gui or inventory is dragged in.voidcallOnOutsideClick(@NotNull org.bukkit.event.inventory.InventoryClickEvent event)Calls the consumer (if it's not null) that was specified usingsetOnOutsideClick(Consumer), so the consumer that should be called whenever a player clicks outside the gui.voidcallOnTopClick(@NotNull org.bukkit.event.inventory.InventoryClickEvent event)Calls the consumer (if it's not null) that was specified usingsetOnTopClick(Consumer), so the consumer that should be called whenever this gui is clicked in.voidcallOnTopDrag(@NotNull org.bukkit.event.inventory.InventoryDragEvent event)Calls the consumer (if it's not null) that was specified usingsetOnTopDrag(Consumer), so the consumer that should be called whenever this gui's top half is dragged in.abstract voidclick(@NotNull org.bukkit.event.inventory.InventoryClickEvent event)This should delegate the provided inventory click event to the right pane, which can then handle this click event further.abstract @NotNull Guicopy()Makes a copy of this gui and returns it.static @Nullable GuigetGui(@NotNull org.bukkit.inventory.Inventory inventory)Gets a gui from the specified inventory.@NotNull HumanEntityCacheGets the human entity cache used for this guiabstract intGets the count ofHumanEntityinstances that are currently viewing this GUI.abstract @NotNull List<org.bukkit.entity.HumanEntity>Gets a mutable snapshot of the currentHumanEntityviewers of this GUI.protected voidinitializeOrThrow(@NotNull Object instance, @NotNull Element element)Initializes standard fields from a Gui from a given input stream.abstract booleanGets whether the player inventory is currently in use.booleanGets whether this gui is being updated, as invoked byupdate().static @Nullable Guiload(@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 voidregisterGui(@NotNull String name, @NotNull BiFunction<? super Object,? super Element,? extends Gui> biFunction)Registers a type that can be used inside an XML file to specify the gui typestatic 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.voidsetOnBottomClick(@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onBottomClick)Set the consumer that should be called whenever the inventory is clicked in.voidsetOnBottomDrag(@Nullable Consumer<org.bukkit.event.inventory.InventoryDragEvent> onBottomDrag)Set the consumer that should be called whenever the inventory is dragged in.voidsetOnClose(@Nullable Consumer<org.bukkit.event.inventory.InventoryCloseEvent> onClose)Set the consumer that should be called whenever this gui is closed.voidsetOnGlobalClick(@Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onGlobalClick)Set the consumer that should be called whenever this gui or inventory is clicked in.voidsetOnGlobalDrag(@Nullable Consumer<org.bukkit.event.inventory.InventoryDragEvent> onGlobalDrag)Set the consumer that should be called whenever this gui or inventory is dragged 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.voidsetOnTopDrag(@Nullable Consumer<org.bukkit.event.inventory.InventoryDragEvent> onTopDrag)Set the consumer that should be called whenever this gui's top half is dragged in.abstract voidshow(@NotNull org.bukkit.entity.HumanEntity humanEntity)Shows a gui to a playervoidupdate()Update the gui for everyone
-
Field Details
-
inventory
protected org.bukkit.inventory.Inventory inventoryThe inventory of this gui -
humanEntityCache
A player cache for storing player's inventories -
onTopClick
The consumer that will be called once a players clicks in the top-half of the gui -
onBottomClick
@Nullable protected @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onBottomClickThe consumer that will be called once a players clicks in the bottom-half of the gui -
onGlobalClick
@Nullable protected @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onGlobalClickThe consumer that will be called once a players clicks in the gui or in their inventory -
onOutsideClick
@Nullable protected @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> onOutsideClickThe consumer that will be called once a player clicks outside of the gui screen -
onTopDrag
The consumer that will be called once a player drags in the top-half of the gui -
onBottomDrag
The consumer that will be called once a player drags in the bottom-half of the gui -
onGlobalDrag
The consumer that will be called once a player drags in the gui or their inventory -
onClose
The consumer that will be called once a player closes the gui
-
-
Constructor Details
-
Gui
public Gui()Constructs a new GUI- Since:
- 0.8.0
-
Gui
public Gui(@NotNull @NotNull org.bukkit.plugin.java.JavaPlugin plugin)Constructs a new gui with the provided plugin.- Parameters:
plugin- the plugin- Since:
- 0.10.0
- See Also:
for a constructor that automatically detects the wanted plugin
-
-
Method Details
-
show
public abstract 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
-
copy
Makes a copy of this gui and returns it. This makes a deep copy of the gui. This entails that the underlying panes will be copied as per theirPane.copy()and miscellaneous data will be copied. The copy of this gui, will however have no viewers even if this gui currently has viewers. With this, cache data for viewers will also be non-existent for the copied gui. The returned gui will never be reference equal to the current gui.- Returns:
- a copy of the gui
- Since:
- 0.6.2
-
click
public abstract void click(@NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent event)This should delegate the provided inventory click event to the right pane, which can then handle this click event further. This should not call any internal click handlers, since those will already have been activated.- Parameters:
event- the event to delegate- Since:
- 0.8.0
-
isPlayerInventoryUsed
public abstract boolean isPlayerInventoryUsed()Gets whether the player inventory is currently in use. This means whether the player inventory currently has an item in it.- Returns:
- true if the player inventory is occupied, false otherwise
- Since:
- 0.8.0
-
getViewerCount
@Contract(pure=true) public abstract int getViewerCount()Gets the count ofHumanEntityinstances that are currently viewing this GUI.- Returns:
- the count of viewers
- Since:
- 0.5.19
-
getViewers
@NotNull @Contract(pure=true) public abstract @NotNull List<org.bukkit.entity.HumanEntity> 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:
- 0.5.19
- See Also:
getViewerCount()
-
update
public void update()Update the gui for everyone -
addInventory
protected void addInventory(@NotNull @NotNull org.bukkit.inventory.Inventory inventory, @NotNull @NotNull Gui gui)Adds the specified inventory and gui, so we can properly intercept clicks.- Parameters:
inventory- the inventory for the specified guigui- the gui belonging to the specified inventory- Since:
- 0.8.1
-
getGui
@Nullable @Contract(pure=true) public static @Nullable Gui getGui(@NotNull @NotNull org.bukkit.inventory.Inventory inventory)Gets a gui from the specified inventory. Only guis of type beacon, brewing stand, dispenser, dropper, furnace and hopper can be retrieved.- Parameters:
inventory- the inventory to get the gui from- Returns:
- the gui or null if the inventory doesn't have an accompanying gui
- Since:
- 0.8.1
-
getHumanEntityCache
Gets the human entity cache used for this gui- Returns:
- the human entity cache
- Since:
- 0.5.4
- See Also:
HumanEntityCache
-
load
@Nullable public static @Nullable Gui load(@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:
instance- the class instance for all reflection lookupsinputStream- the file- Returns:
- the gui or null if the loading failed
-
initializeOrThrow
protected void initializeOrThrow(@NotNull @NotNull Object instance, @NotNull @NotNull Element element)Initializes standard fields from a Gui from a given input stream. Throws aRuntimeExceptioninstead of returning null in case of a failure.- Parameters:
instance- the class instance for all reflection lookupselement- the gui element- See Also:
load(Object, InputStream)
-
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
-
callOnTopClick
public void callOnTopClick(@NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent event)Calls the consumer (if it's not null) that was specified usingsetOnTopClick(Consumer), so the consumer that should be called whenever this gui is clicked in. Catches and logs all exceptions the consumer might throw.- Parameters:
event- the event to handle- Since:
- 0.6.0
-
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
-
callOnBottomClick
public void callOnBottomClick(@NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent event)Calls the consumer (if it's not null) that was specified usingsetOnBottomClick(Consumer), so the consumer that should be called whenever the inventory is clicked in. Catches and logs all exceptions the consumer might throw.- Parameters:
event- the event to handle- Since:
- 0.6.0
-
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
-
callOnGlobalClick
public void callOnGlobalClick(@NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent event)Calls the consumer (if it's not null) that was specified usingsetOnGlobalClick(Consumer), so the consumer that should be called whenever this gui or inventory is clicked in. Catches and logs all exceptions the consumer might throw.- Parameters:
event- the event to handle- Since:
- 0.6.0
-
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:
- 0.5.7
-
callOnOutsideClick
public void callOnOutsideClick(@NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent event)Calls the consumer (if it's not null) that was specified usingsetOnOutsideClick(Consumer), so the consumer that should be called whenever a player clicks outside the gui. Catches and logs all exceptions the consumer might throw.- Parameters:
event- the event to handle- Since:
- 0.6.0
-
setOnTopDrag
public void setOnTopDrag(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryDragEvent> onTopDrag)Set the consumer that should be called whenever this gui's top half is dragged in.- Parameters:
onTopDrag- the consumer that gets called- Since:
- 0.9.0
-
callOnTopDrag
public void callOnTopDrag(@NotNull @NotNull org.bukkit.event.inventory.InventoryDragEvent event)Calls the consumer (if it's not null) that was specified usingsetOnTopDrag(Consumer), so the consumer that should be called whenever this gui's top half is dragged in. Catches and logs all exceptions the consumer might throw.- Parameters:
event- the event to handle- Since:
- 0.9.0
-
setOnBottomDrag
public void setOnBottomDrag(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryDragEvent> onBottomDrag)Set the consumer that should be called whenever the inventory is dragged in.- Parameters:
onBottomDrag- the consumer that gets called- Since:
- 0.9.0
-
callOnBottomDrag
public void callOnBottomDrag(@NotNull @NotNull org.bukkit.event.inventory.InventoryDragEvent event)Calls the consumer (if it's not null) that was specified usingsetOnBottomDrag(Consumer), so the consumer that should be called whenever the inventory is dragged in. Catches and logs all exceptions the consumer might throw.- Parameters:
event- the event to handle- Since:
- 0.9.0
-
setOnGlobalDrag
public void setOnGlobalDrag(@Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryDragEvent> onGlobalDrag)Set the consumer that should be called whenever this gui or inventory is dragged in.- Parameters:
onGlobalDrag- the consumer that gets called- Since:
- 0.9.0
-
callOnGlobalDrag
public void callOnGlobalDrag(@NotNull @NotNull org.bukkit.event.inventory.InventoryDragEvent event)Calls the consumer (if it's not null) that was specified usingsetOnGlobalDrag(Consumer), so the consumer that should be called whenever this gui or inventory is dragged in. Catches and logs all exceptions the consumer might throw.- Parameters:
event- the event to handle- Since:
- 0.6.0
-
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
-
callOnClose
public void callOnClose(@NotNull @NotNull org.bukkit.event.inventory.InventoryCloseEvent event)Calls the consumer (if it's not null) that was specified usingsetOnClose(Consumer), so the consumer that should be called whenever this gui is closed. Catches and logs all exceptions the consumer might throw.- Parameters:
event- the event to handle- Since:
- 0.6.0
-
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:
- 0.5.15
-
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
-
registerGui
public static void registerGui(@NotNull @NotNull String name, @NotNull @NotNull BiFunction<? super Object,? super Element,? extends Gui> biFunction)Registers a type that can be used inside an XML file to specify the gui type- Parameters:
name- the name of the type of gui to be used in an XML filebiFunction- how the gui creation should be processed- Throws:
IllegalArgumentException- when a gui type 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
-