Class ItemCreator

java.lang.Object
me.croabeast.common.gui.ItemCreator

public final class ItemCreator extends Object
A fluent builder for creating and customizing ItemStack instances, and converting them into GuiItem objects for GUI implementations.

The ItemCreator provides methods to modify the underlying item, adjust its metadata (such as display name and lore), and attach click actions. This utility simplifies item customization and integrates with external APIs (e.g., PrismaticAPI for colorization) to produce visually appealing GUI items.

Example usage:


 // Create an item with a custom name and lore, and set a click action
 GuiItem guiItem = ItemCreator.of(Material.DIAMOND)
     .modifyName("invalid input: '&bShiny' Diamond")
     .modifyLore("invalid input: '&'7This is a very shiny diamond.", "invalid input: '&eRight'-click to use!")
     .setAction(event -> {
         event.setCancelled(true);
         // Additional click handling code...
     })
     .create();
 

  • Method Details

    • modifyItem

      public ItemCreator modifyItem(Consumer<org.bukkit.inventory.ItemStack> consumer)
      Applies a modification to the underlying ItemStack.

      This method accepts a Consumer that performs operations on the item.

      Parameters:
      consumer - the consumer that modifies the item stack
      Returns:
      this ItemCreator instance for fluent chaining
    • setAction

      public ItemCreator setAction(Consumer<org.bukkit.event.inventory.InventoryClickEvent> consumer)
      Sets the click action to be performed when the item is clicked in a GUI.
      Parameters:
      consumer - the click event consumer (must not be null)
      Returns:
      this ItemCreator instance for fluent chaining
    • setActionToEmpty

      public ItemCreator setActionToEmpty()
      Sets a default action for the item that cancels any click event.

      This is useful when you want the item to be non-interactive.

      Returns:
      this ItemCreator instance for fluent chaining
    • modifyMeta

      public ItemCreator modifyMeta(Consumer<org.bukkit.inventory.meta.ItemMeta> consumer)
      Applies modifications to the ItemMeta of the underlying item.

      The provided consumer will be executed on the current ItemMeta, and the updated meta will be set back to the item.

      Parameters:
      consumer - the consumer that modifies the item meta (must not be null)
      Returns:
      this ItemCreator instance for fluent chaining
    • modifyName

      public ItemCreator modifyName(String name)
      Sets the display name of the item.

      The provided name is colorized using PrismaticAPI.colorize(String).

      Parameters:
      name - the new display name for the item
      Returns:
      this ItemCreator instance for fluent chaining
    • modifyLore

      public ItemCreator modifyLore(List<String> lore)
      Sets the lore (description) of the item using a list of strings.

      Each line of the lore is processed and colorized via PrismaticAPI.colorize(String).

      Parameters:
      lore - a list of strings representing the item's lore
      Returns:
      this ItemCreator instance for fluent chaining
    • modifyLore

      public ItemCreator modifyLore(String... lore)
      Sets the lore (description) of the item using an array of strings.
      Parameters:
      lore - an array of strings representing the item's lore
      Returns:
      this ItemCreator instance for fluent chaining
    • create

      public com.github.stefvanschie.inventoryframework.gui.GuiItem create()
      Finalizes the creation of the GUI item.

      This method wraps the customized ItemStack in a GuiItem and assigns the configured click action (if any) to it.

      Returns:
      the constructed GuiItem
    • of

      public static ItemCreator of(org.bukkit.inventory.ItemStack stack)
      Creates a new ItemCreator for the given ItemStack.
      Parameters:
      stack - the item stack to customize
      Returns:
      a new ItemCreator instance
    • of

      public static ItemCreator of(org.bukkit.Material material)
      Creates a new ItemCreator for the specified Material.

      A new ItemStack is created from the material.

      Parameters:
      material - the material to create the item stack from (must not be null)
      Returns:
      a new ItemCreator instance