Class GuiItem

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

public class GuiItem extends Object
An item for in an inventory
  • 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 stack
      action - the action called whenever an interaction with this item happens
      plugin - the owning plugin of this item
      Since:
      0.10.8
      See Also:
    • GuiItem

      public GuiItem(@NotNull @NotNull ItemStack item, @NotNull @NotNull Plugin plugin)
      Creates a new gui item based on the item stack and action
      Parameters:
      item - the item stack
      plugin - the owning plugin of this item
      Since:
      0.10.8
      See Also:
    • 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 stack
      action - the action called whenever an interaction with this item happens
    • GuiItem

      public GuiItem(@NotNull @NotNull 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 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
    • setItem

      public void setItem(@NotNull @NotNull ItemStack item)
      Overwrites the current item with the provided item.
      Parameters:
      item - the item to set
      Since:
      0.10.8
    • setAction

      public void setAction(@NotNull @NotNull Consumer<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 ItemStack getItem()
      Returns the item
      Returns:
      the item that belongs to this gui item
    • getKey

      @NotNull @Contract(pure=true) public @NotNull NamespacedKey getKey()
      Gets the namespaced key used for this item.
      Returns:
      the namespaced key
      Since:
      0.10.8
    • 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
    • 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 instance
      element - the element
      plugin - the plugin that will be the owner of the created item
      Returns:
      the gui item
      Since:
      0.12.0
      See Also:
    • loadItem

      @NotNull @Contract(pure=true) public static @NotNull GuiItem loadItem(@NotNull @NotNull Object instance, @NotNull @NotNull Element element)
      Loads an item from an instance and an element
      Parameters:
      instance - the instance
      element - the element
      Returns:
      the gui item
      Since:
      0.12.0
    • 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 of Gui.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