java.lang.Object
com.github.stefvanschie.inventoryframework.gui.GuiItem

public class GuiItem extends Object
An item for in an inventory
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static org.bukkit.NamespacedKey
    The NamespacedKey that specifies the location of the (internal) UUID in PersistentDataContainers.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GuiItem​(@NotNull org.bukkit.inventory.ItemStack item)
    Creates a new gui item based on the item stack and action
    GuiItem​(@NotNull org.bukkit.inventory.ItemStack item, @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> action)
    Creates a new gui item based on the item stack and action
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Sets the internal UUID of this gui item onto the underlying item.
    void
    callAction​(@NotNull org.bukkit.event.inventory.InventoryClickEvent event)
    Calls the handler of the InventoryClickEvent if such a handler was specified in the constructor.
    @NotNull GuiItem
    Makes a copy of this gui item and returns it.
    @NotNull org.bukkit.inventory.ItemStack
    Returns the item
    @NotNull List<Object>
    Returns the list of properties
    @NotNull UUID
    Gets the UUID associated with this GuiItem.
    boolean
    Returns whether or not this item is visible
    void
    setAction​(@NotNull Consumer<org.bukkit.event.inventory.InventoryClickEvent> action)
    Sets the action to be executed when a human entity clicks on this item.
    void
    setProperties​(@NotNull List<Object> properties)
    Sets the list of properties for this gui item
    void
    setVisible​(boolean visible)
    Sets the visibility of this item to the new visibility

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • KEY_UUID

      public static final org.bukkit.NamespacedKey KEY_UUID
      The NamespacedKey that specifies the location of the (internal) UUID in PersistentDataContainers. The PersistentDataType that should be used is UUIDTagType.
  • Constructor Details

    • GuiItem

      public GuiItem(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @Nullable @Nullable Consumer<org.bukkit.event.inventory.InventoryClickEvent> action)
      Creates a new gui item based on the item stack and action
      Parameters:
      item - the item stack
      action - the action called whenever an interaction with this item happens
    • GuiItem

      public GuiItem(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Creates a new gui item based on the item stack and action
      Parameters:
      item - the item stack
  • Method Details

    • copy

      @NotNull @Contract(pure=true) public @NotNull GuiItem 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 their ItemStack.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

      public void callAction(@NotNull @NotNull org.bukkit.event.inventory.InventoryClickEvent event)
      Calls the handler of the InventoryClickEvent if 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
    • setAction

      public void setAction(@NotNull @NotNull Consumer<org.bukkit.event.inventory.InventoryClickEvent> action)
      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

      @NotNull @Contract(pure=true) public @NotNull List<Object> getProperties()
      Returns the list of properties
      Returns:
      the list of properties that belong to this gui item
      Since:
      0.7.2
    • setProperties

      public void setProperties(@NotNull @NotNull List<Object> properties)
      Sets the list of properties for this gui item
      Parameters:
      properties - list of new properties
      Since:
      0.7.2
    • getItem

      @NotNull @Contract(pure=true) public @NotNull org.bukkit.inventory.ItemStack getItem()
      Returns the item
      Returns:
      the item that belongs to this gui item
    • getUUID

      @NotNull @Contract(pure=true) public @NotNull UUID getUUID()
      Gets the UUID associated with this GuiItem. This is for internal use only, and should not be used.
      Returns:
      the UUID of this item
      Since:
      0.5.9
    • 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