Class ItemCreator
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 Summary
Modifier and TypeMethodDescriptioncom.github.stefvanschie.inventoryframework.gui.GuiItemcreate()Finalizes the creation of the GUI item.modifyItem(Consumer<org.bukkit.inventory.ItemStack> consumer) Applies a modification to the underlyingItemStack.modifyLore(String... lore) Sets the lore (description) of the item using an array of strings.modifyLore(List<String> lore) Sets the lore (description) of the item using a list of strings.modifyMeta(Consumer<org.bukkit.inventory.meta.ItemMeta> consumer) Applies modifications to theItemMetaof the underlying item.modifyName(String name) Sets the display name of the item.static ItemCreatorof(org.bukkit.inventory.ItemStack stack) Creates a newItemCreatorfor the givenItemStack.static ItemCreatorof(org.bukkit.Material material) Creates a newItemCreatorfor the specifiedMaterial.Sets the click action to be performed when the item is clicked in a GUI.Sets a default action for the item that cancels any click event.
-
Method Details
-
modifyItem
Applies a modification to the underlyingItemStack.This method accepts a
Consumerthat performs operations on the item.- Parameters:
consumer- the consumer that modifies the item stack- Returns:
- this
ItemCreatorinstance for fluent chaining
-
setAction
Sets the click action to be performed when the item is clicked in a GUI.- Parameters:
consumer- the click event consumer (must not benull)- Returns:
- this
ItemCreatorinstance for fluent chaining
-
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
ItemCreatorinstance for fluent chaining
-
modifyMeta
Applies modifications to theItemMetaof 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 benull)- Returns:
- this
ItemCreatorinstance for fluent chaining
-
modifyName
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
ItemCreatorinstance for fluent chaining
-
modifyLore
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
ItemCreatorinstance for fluent chaining
-
modifyLore
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
ItemCreatorinstance for fluent chaining
-
create
public com.github.stefvanschie.inventoryframework.gui.GuiItem create()Finalizes the creation of the GUI item.This method wraps the customized
ItemStackin aGuiItemand assigns the configured click action (if any) to it.- Returns:
- the constructed
GuiItem
-
of
Creates a newItemCreatorfor the givenItemStack.- Parameters:
stack- the item stack to customize- Returns:
- a new
ItemCreatorinstance
-
of
Creates a newItemCreatorfor the specifiedMaterial.A new
ItemStackis created from the material.- Parameters:
material- the material to create the item stack from (must not benull)- Returns:
- a new
ItemCreatorinstance
-