Package dev.itsharshxd.zentrix.api.item
Class ItemBuilder
java.lang.Object
dev.itsharshxd.zentrix.api.item.ItemBuilder
Fluent builder for creating custom items.
Use it to define vanilla items or items supplied by ItemsAdder and Nexo.
Vanilla item example
ItemBuilder compass = new ItemBuilder()
.id("tracking-compass")
.material(Material.COMPASS)
.displayName("&#FFD700&l Tracking Compass")
.lore(
"",
"&#AAAAAA Right-click to track",
"&#AAAAAA the nearest player!",
"",
"򇨣Cooldown: 10s"
)
.enchant(Enchantment.UNBREAKING, 1)
.flag(ItemFlag.HIDE_ENCHANTS)
.glow(true)
.slot(4)
.addonId(getAddonId());
itemService.registerItem(compass);
External item example
ItemBuilder customSword = new ItemBuilder()
.id("custom-diamond-sword")
.external("itemsadder:mynamespace:my_sword")
.slot(0)
.addonId(getAddonId());
itemService.registerItem(customSword);
- Since:
- 1.1.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull ItemBuilderAdds a lore line to this item.@NotNull ItemBuilderSets the addon ID that owns this item.@NotNull ItemBuilderamount(int amount) Sets the item amount.@NotNull ItemBuildercopy()Copies this builder.@NotNull ItemBuildercustomField(@NotNull String key, @Nullable Object value) Adds a custom metadata field to this item.@NotNull ItemBuildercustomModelData(int data) Sets the custom model data for this item.@NotNull ItemBuilderdisplayName(@NotNull String name) Sets the display name for this item.@NotNull ItemBuilderenabled(boolean enabled) Sets whether this item is enabled.@NotNull ItemBuilderenchant(@NotNull org.bukkit.enchantments.Enchantment enchantment, int level) Adds an enchantment to this item.@NotNull ItemBuilderSets this item to use an external source (ItemsAdder, Nexo, etc.).@NotNull ItemBuilderflag(@NotNull org.bukkit.inventory.ItemFlag... flags) Adds item flags to this item.@Nullable Stringintint@Nullable String@Nullable String@NotNull Set<org.bukkit.inventory.ItemFlag> getFlags()@Nullable StringgetId()getLore()@NotNull org.bukkit.MaterialintgetSlot()@NotNull ItemBuilderglow(boolean glow) Sets whether this item has a glow effect.@NotNull ItemBuilderSets the unique identifier for this item.booleanbooleanisGlow()booleanbooleanisValid()Checks if this builder is valid without throwing an exception.@NotNull ItemBuilderSets the lore for this item.@NotNull ItemBuildermaterial(@NotNull org.bukkit.Material material) Sets the material for this item.@NotNull ItemBuilderslot(int slot) Sets the preferred inventory slot for this item.toString()@NotNull ItemBuilderunbreakable(boolean unbreakable) Sets whether this item is unbreakable.voidvalidate()Validates that this builder has all required fields set correctly.
-
Constructor Details
-
ItemBuilder
public ItemBuilder()Creates a new ItemBuilder instance.
-
-
Method Details
-
id
Sets the unique identifier for this item.Item IDs must only contain lowercase letters, numbers, hyphens, and underscores.
- Parameters:
id- The item ID (e.g., "tracking-compass", "custom_sword")- Returns:
- This builder for chaining
- Throws:
IllegalArgumentException- if the ID is null, empty, or contains invalid characters
-
material
Sets the material for this item.- Parameters:
material- The Bukkit material- Returns:
- This builder for chaining
-
external
Sets this item to use an external source (ItemsAdder, Nexo, etc.).Format examples:
- "itemsadder:namespace:item_id"
- "nexo:item_id"
- Parameters:
source- The external source identifier- Returns:
- This builder for chaining
-
displayName
Sets the display name for this item.- Parameters:
name- The display name (supports color codes)- Returns:
- This builder for chaining
-
lore
Sets the lore for this item.- Parameters:
lines- The lore lines (varargs, supports color codes)- Returns:
- This builder for chaining
-
addLore
Adds a lore line to this item.- Parameters:
line- The lore line to add- Returns:
- This builder for chaining
-
amount
Sets the item amount.- Parameters:
amount- The amount (1-64)- Returns:
- This builder for chaining
- Throws:
IllegalArgumentException- if amount is not between 1 and 64
-
enchant
@NotNull public @NotNull ItemBuilder enchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchantment, int level) Adds an enchantment to this item.- Parameters:
enchantment- The enchantmentlevel- The enchantment level- Returns:
- This builder for chaining
-
flag
Adds item flags to this item.- Parameters:
flags- The item flags (varargs)- Returns:
- This builder for chaining
-
customModelData
Sets the custom model data for this item.- Parameters:
data- The custom model data value- Returns:
- This builder for chaining
-
unbreakable
Sets whether this item is unbreakable.- Parameters:
unbreakable-trueto make unbreakable- Returns:
- This builder for chaining
-
glow
Sets whether this item has a glow effect.If true and no enchantments are present, a dummy enchantment will be added with HIDE_ENCHANTS flag.
- Parameters:
glow-trueto enable glow- Returns:
- This builder for chaining
-
slot
Sets the preferred inventory slot for this item.- Parameters:
slot- The slot index (0-8 for hotbar, -1 for no preference)- Returns:
- This builder for chaining
-
enabled
Sets whether this item is enabled.- Parameters:
enabled-trueto enable- Returns:
- This builder for chaining
-
addonId
Sets the addon ID that owns this item.- Parameters:
addonId- The addon identifier- Returns:
- This builder for chaining
-
customField
@NotNull public @NotNull ItemBuilder customField(@NotNull @NotNull String key, @Nullable @Nullable Object value) Adds a custom metadata field to this item.- Parameters:
key- The field keyvalue- The field value (should be serializable)- Returns:
- This builder for chaining
-
copy
Copies this builder.- Returns:
- A new ItemBuilder with the same configuration
-
getId
-
getMaterial
@NotNull public @NotNull org.bukkit.Material getMaterial() -
getExternal
-
getDisplayName
-
getLore
-
getAmount
public int getAmount() -
getEnchantments
-
getFlags
-
getCustomModelData
public int getCustomModelData() -
isUnbreakable
public boolean isUnbreakable() -
isGlow
public boolean isGlow() -
getSlot
public int getSlot() -
isEnabled
public boolean isEnabled() -
getAddonId
-
getCustomFields
-
validate
Validates that this builder has all required fields set correctly.- Throws:
IllegalStateException- if the builder is not valid
-
isValid
public boolean isValid()Checks if this builder is valid without throwing an exception.- Returns:
trueif the builder has all required fields
-
toString
-