Class Gui
java.lang.Object
com.github.stefvanschie.inventoryframework.gui.type.util.Gui
The base class of all GUIs
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final @NotNull HumanEntityCacheA player cache for storing player's inventoriesprotected InventoryThe inventory of this guiprotected @Nullable Consumer<? super InventoryClickEvent> The consumer that will be called once a players clicks in the bottom-half of the guiprotected @Nullable Consumer<? super InventoryDragEvent> The consumer that will be called once a player drags in the bottom-half of the guiprotected @Nullable Consumer<? super InventoryCloseEvent> The consumer that will be called once a player closes the guiprotected @Nullable Consumer<? super InventoryClickEvent> The consumer that will be called once a players clicks in the gui or in their inventoryprotected @Nullable Consumer<? super InventoryDragEvent> The consumer that will be called once a player drags in the gui or their inventoryprotected @Nullable Consumer<? super InventoryClickEvent> The consumer that will be called once a player clicks outside of the gui screenprotected @Nullable Consumer<? super InventoryClickEvent> The consumer that will be called once a players clicks in the top-half of the guiprotected @Nullable Consumer<? super InventoryDragEvent> The consumer that will be called once a player drags in the top-half of the guiprotected final @NotNull PluginThe plugin that owns this guiprotected booleanWhether this gui is updating (as invoked byupdate()), true if this is the case, false otherwise. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddInventory(@NotNull Inventory inventory, @NotNull Gui gui) Adds the specified inventory and gui, so we can properly intercept clicks.protected <T extends InventoryEvent>
voidcallCallback(@Nullable Consumer<? super T> callback, T event, @NotNull String callbackName) Calls the specified consumer (if it's not null) with the specified parameter, catching and logging all exceptions it might throw.voidcallOnBottomClick(@NotNull 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 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 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 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 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 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 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 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 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 GuiGets a gui from the specified inventory.@NotNull HumanEntityCacheGets the human entity cache used for this guigetItems()Gets all theGuiIteminstances in this gui.abstract intGets the count ofHumanEntityinstances that are currently viewing this GUI.abstract @NotNull List<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 @Nullable Guiload(@NotNull Object instance, @NotNull InputStream inputStream, @NotNull Plugin plugin) Loads a Gui from a given input stream.static @NotNull PaneLoads a pane by the given instance and nodestatic @NotNull PaneLoads a pane by the given instance and nodevoidnavigateToParent(@NotNull HumanEntity humanEntity) The parent gui will be shown to the specifiedHumanEntity.static voidregisterGui(@NotNull String name, @NotNull TriFunction<? super Object, ? super Element, ? super Plugin, ? extends Gui> triFunction) Registers a type that can be used inside an XML file to specify the gui typestatic voidregisterPane(@NotNull String name, @NotNull TriFunction<? super Object, ? super Element, ? super Plugin, ? extends Pane> triFunction) Registers a name that can be used inside an XML file to add custom panesstatic voidregisterPane(@NotNull String name, @NotNull BiFunction<? super Object, ? super Element, ? extends Pane> biFunction) Registers a name that can be used inside an XML file to add custom panesstatic voidregisterProperty(@NotNull String attributeName, @NotNull Function<? super String, ?> function) Registers a property that can be used inside an XML file to add additional new properties.voidsetOnBottomClick(@Nullable Consumer<? super InventoryClickEvent> onBottomClick) Set the consumer that should be called whenever the inventory is clicked in.voidsetOnBottomDrag(@Nullable Consumer<? super InventoryDragEvent> onBottomDrag) Set the consumer that should be called whenever the inventory is dragged in.voidsetOnClose(@Nullable Consumer<? super InventoryCloseEvent> onClose) Set the consumer that should be called whenever this gui is closed.voidsetOnGlobalClick(@Nullable Consumer<? super InventoryClickEvent> onGlobalClick) Set the consumer that should be called whenever this gui or inventory is clicked in.voidsetOnGlobalDrag(@Nullable Consumer<? super InventoryDragEvent> onGlobalDrag) Set the consumer that should be called whenever this gui or inventory is dragged in.voidsetOnOutsideClick(@Nullable Consumer<? super InventoryClickEvent> onOutsideClick) Set the consumer that should be called whenever a player clicks outside the gui.voidsetOnTopClick(@Nullable Consumer<? super InventoryClickEvent> onTopClick) Set the consumer that should be called whenever this gui is clicked in.voidsetOnTopDrag(@Nullable Consumer<? super InventoryDragEvent> onTopDrag) Set the consumer that should be called whenever this gui's top half is dragged in.voidSets the parent gui to the provided gui.abstract voidshow(@NotNull HumanEntity humanEntity) Shows a gui to a playerabstract voidupdate()Update the gui for everyone
-
Field Details
-
plugin
The plugin that owns this gui -
inventory
The 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
The consumer that will be called once a players clicks in the bottom-half of the gui -
onGlobalClick
The consumer that will be called once a players clicks in the gui or in their inventory -
onOutsideClick
The 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 -
updating
protected boolean updatingWhether this gui is updating (as invoked byupdate()), true if this is the case, false otherwise. This is used to indicate that inventory close events due to updating should be ignored.
-
-
Constructor Details
-
Gui
Constructs a new gui with the provided plugin.- Parameters:
plugin- the plugin- Since:
- 0.10.8
-
-
Method Details
-
show
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 original owning plugin of the gui is preserved, but the plugin will not be deeply copied. The returned gui will never be reference equal to the current gui.- Returns:
- a copy of the gui
- Since:
- 0.6.2
-
click
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
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:
-
update
public abstract void update()Update the gui for everyone -
getItems
-
addInventory
-
getGui
@Nullable @Contract(pure=true) public static @Nullable Gui getGui(@NotNull @NotNull 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:
-
load
@Nullable public static @Nullable Gui load(@NotNull @NotNull Object instance, @NotNull @NotNull InputStream inputStream, @NotNull @NotNull Plugin plugin) Loads a Gui from a given input stream.- Parameters:
instance- the class instance for all reflection lookupsinputStream- the file- Returns:
- the gui or null if the loading failed
- Throws:
XMLLoadException- if loading could not finish successfully, due to e.g., a malformed file- Since:
- 0.10.8
- See Also:
-
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
- Throws:
XMLLoadException- if loading could not finish successfully, due to e.g., a malformed file
-
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:
-
setOnTopClick
Set the consumer that should be called whenever this gui is clicked in.- Parameters:
onTopClick- the consumer that gets called
-
callOnTopClick
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<? super InventoryClickEvent> onBottomClick) Set the consumer that should be called whenever the inventory is clicked in.- Parameters:
onBottomClick- the consumer that gets called
-
callOnBottomClick
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<? super 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
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<? super 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
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
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
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
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
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
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
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
Set the consumer that should be called whenever this gui is closed.- Parameters:
onClose- the consumer that gets called
-
callOnClose
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
-
callCallback
protected <T extends InventoryEvent> void callCallback(@Nullable @Nullable Consumer<? super T> callback, @NotNull T event, @NotNull @NotNull String callbackName) Calls the specified consumer (if it's not null) with the specified parameter, catching and logging all exceptions it might throw.- Type Parameters:
T- the type of the value the consumer is accepting- Parameters:
callback- the consumer to call if it isn't nullevent- the value the consumer should acceptcallbackName- the name of the action, used for logging
-
setParent
Sets the parent gui to the provided gui. This is the gui that a player will be navigated to once they close this gui. The navigation will occur after the close event handler, set bysetOnClose(Consumer), is called. If there was already a previous parent set, the provided gui will override the previous one.- Parameters:
gui- the new parent gui- Since:
- 0.10.14
-
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<? super String, ?> 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 TriFunction<? super Object, ? super Element, ? super Plugin, ? extends Pane> triFunction) 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 filetriFunction- how the pane loading should be processed- Throws:
IllegalArgumentException- when a pane with this name is already registered- Since:
- 0.10.8
- See Also:
-
registerPane
public static void registerPane(@NotNull @NotNull String name, @NotNull @NotNull BiFunction<? super Object, ? super Element, ? extends 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 TriFunction<? super Object, ? super Element, ? super Plugin, ? extends Gui> triFunction) 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 filetriFunction- how the gui creation should be processed- Throws:
IllegalArgumentException- when a gui type with this name is already registered- Since:
- 0.10.8
-
loadPane
@NotNull public static @NotNull Pane loadPane(@NotNull @NotNull Object instance, @NotNull @NotNull Node node, @NotNull @NotNull Plugin plugin) Loads a pane by the given instance and node- Parameters:
instance- the instancenode- the nodeplugin- the plugin to load the pane with- Returns:
- the pane
- Throws:
XMLLoadException- if the name of the node does not correspond to a valid pane.- Since:
- 0.10.8
-
loadPane
-