Class GuiItem
java.lang.Object
com.github.stefvanschie.inventoryframework.gui.GuiItem
An item for in an inventory
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new gui item based on the item stack and actionGuiItem(@NotNull ItemStack item, @Nullable Consumer<? super InventoryClickEvent> action) Creates a new gui item based on the item stack and actionGuiItem(@NotNull ItemStack item, @Nullable Consumer<? super InventoryClickEvent> action, @NotNull Plugin plugin) Creates a new gui item based on the item stack and actionCreates a new gui item based on the item stack and action -
Method Summary
Modifier and TypeMethodDescriptionvoidSets the internal UUID of this gui item onto the underlying item.voidcallAction(@NotNull InventoryClickEvent event) Calls the handler of theInventoryClickEventif such a handler was specified in the constructor.@NotNull GuiItemcopy()Makes a copy of this gui item and returns it.@NotNull ItemStackgetItem()Returns the item@NotNull NamespacedKeygetKey()Gets the namespaced key used for this item.Returns the list of properties@NotNull UUIDgetUUID()booleanReturns whether or not this item is visiblestatic @NotNull GuiItemLoads an item from an instance and an elementstatic @NotNull GuiItemLoads an item from an instance and an elementstatic 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.voidsetAction(@NotNull Consumer<InventoryClickEvent> action) Sets the action to be executed when a human entity clicks on this item.voidOverwrites the current item with the provided item.voidsetProperties(@NotNull List<Object> properties) Sets the list of properties for this gui itemvoidsetVisible(boolean visible) Sets the visibility of this item to the new visibility
-
Constructor Details
-
GuiItem
public GuiItem(@NotNull @NotNull ItemStack item, @Nullable @Nullable Consumer<? super InventoryClickEvent> action, @NotNull @NotNull Plugin plugin) Creates a new gui item based on the item stack and action- Parameters:
item- the item stackaction- the action called whenever an interaction with this item happensplugin- the owning plugin of this item- Since:
- 0.10.8
- See Also:
-
GuiItem
-
GuiItem
public GuiItem(@NotNull @NotNull ItemStack item, @Nullable @Nullable Consumer<? super InventoryClickEvent> action) Creates a new gui item based on the item stack and action- Parameters:
item- the item stackaction- the action called whenever an interaction with this item happens
-
GuiItem
Creates a new gui item based on the item stack and action- Parameters:
item- the item stack
-
-
Method Details
-
copy
Makes a copy of this gui item and returns it. This makes a deep copy of the gui item. This entails that the underlying item will be copied as per theirItemStack.clone()and miscellaneous data will be copied in such a way that they are identical. The returned gui item will never be reference equal to the current gui item.- Returns:
- a copy of the gui item
- Since:
- 0.6.2
-
callAction
Calls the handler of theInventoryClickEventif such a handler was specified in the constructor. Catches and logs all exceptions the handler might throw.- Parameters:
event- the event to handle- Since:
- 0.6.0
-
applyUUID
public void applyUUID()Sets the internal UUID of this gui item onto the underlying item. Previously set UUID will be overwritten by the current UUID. If the underlying item does not have an item meta, this method will silently do nothing.- Since:
- 0.9.3
-
setItem
Overwrites the current item with the provided item.- Parameters:
item- the item to set- Since:
- 0.10.8
-
setAction
Sets the action to be executed when a human entity clicks on this item.- Parameters:
action- the action of this item- Since:
- 0.7.1
-
getProperties
-
setProperties
-
getItem
Returns the item- Returns:
- the item that belongs to this gui item
-
getKey
Gets the namespaced key used for this item.- Returns:
- the namespaced key
- Since:
- 0.10.8
-
getUUID
-
isVisible
public boolean isVisible()Returns whether or not this item is visible- Returns:
- true if this item is visible, false otherwise
-
setVisible
public void setVisible(boolean visible) Sets the visibility of this item to the new visibility- Parameters:
visible- the new visibility
-
loadItem
@NotNull @Contract(pure=true) public static @NotNull GuiItem loadItem(@NotNull @NotNull Object instance, @NotNull @NotNull Element element, @NotNull @NotNull Plugin plugin) Loads an item from an instance and an element- Parameters:
instance- the instanceelement- the elementplugin- the plugin that will be the owner of the created item- Returns:
- the gui item
- Since:
- 0.12.0
- See Also:
-
loadItem
-
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. The use ofGui.registerProperty(String, Function)is preferred over this method.- 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.- Since:
- 0.12.0
-