Package com.kamikazejam.kamicommon.item
Class ItemBuilder
java.lang.Object
com.kamikazejam.kamicommon.item.ItemBuilder
- All Implemented Interfaces:
IBuilder<ItemBuilder>,Cloneable
A builder class for wrapping
Patches modify the base metadata and nbt of the item via easier to use methods exposed by this class.
NOTE: Using third party plugins like ItemsAdder which provide custom items IS SUPPORTED!
Just adjust your workflow to parse the
There is also support in the loaders for using external
ItemStacks and applying patches to them.Patches modify the base metadata and nbt of the item via easier to use methods exposed by this class.
NOTE: Using third party plugins like ItemsAdder which provide custom items IS SUPPORTED!
Just adjust your workflow to parse the
ItemStack from their API, and then use that object as the prototype for this wrapper:
ItemStack customItem = CustomStack.getInstance("my_namespaced_id");
ItemBuilder builder = new ItemBuilder(customItem);
// apply patches to the builder...
ItemStack finalItem = builder.build();
There is also support in the loaders for using external
ItemStack prototypes using ItemBuilderLoader.loadPatches(ItemStack, ConfigurationSection):
ItemStack customItem = CustomStack.getInstance("my_namespaced_id");
ItemBuilder builder = ItemBuilderLoader.loadPatches(customItem, configSection);
// apply patches to the builder...
ItemStack finalItem = builder.build();
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionItemBuilder(@NotNull com.cryptomorin.xseries.XMaterial material) Construct a new ItemBuilder from anXMaterial.
This is equivalent to callingItemBuilder(ItemStack)with the result ofXMaterial.parseItem()ItemBuilder(@NotNull Material material) Construct a new ItemBuilder from anMaterial.
This is equivalent to callingItemBuilder(XMaterial)with the result ofXMaterial.matchXMaterial(Material)ItemBuilder(@NotNull ItemStack prototype) Construct a new ItemBuilder from a prototypeItemStack.
(The prototype is never modified, it is immutable, and accessed viagetPrototype())
Call ItemBuilder methods to set and update item 'patches', and then useIBuilder.build()to construct the final item.
-
Method Summary
Modifier and TypeMethodDescription@NotNull ItemBuilderaddGlow()PATCH FUNCTION - Sets whether the item should have an added glow effect.
Clear this patch by callingIBuilder.removeGlow().@NotNull ItemBuilderaddItemFlag(@NotNull com.cryptomorin.xseries.XItemFlag flag) PATCH FUNCTION - Adds an item flag to the item.
Remove an item flag viaIBuilder.removeItemFlag(XItemFlag).@NotNull ItemBuilderaddItemFlags(@NotNull Collection<com.cryptomorin.xseries.XItemFlag> flags) PATCH FUNCTION - Adds several item flags to the item.
Remove an item flag viaIBuilder.removeItemFlag(XItemFlag).@NotNull ItemBuilderaddLoreComponents(@NotNull List<@NotNull VersionedComponent> lines) PATCH FUNCTION - Appends additional lines to the current lore.
If no lore patch is currently set, this will create a new lore patch with the provided lines.
If a lore patch is already set, the new lines will be added to the end of the existing lore.
Colors are assumed to be already handled in the components.
Placeholders are set automatically viaSoftPlaceholderAPI.setPlaceholders(OfflinePlayer, String).@NotNull ItemStackCompiles the patches, applying them on top of the prototype.@NotNull ItemBuilderclone()@NotNull ItemBuildercloneWithNewPrototype(@NotNull ItemStack newPrototype) Create a clone of this builder with all the same patches, but a different prototypeItemStack.@Nullable VersionedComponentGet the custom display name for the item.
Placeholders are set automatically viaSoftPlaceholderAPI.setPlaceholders(OfflinePlayer, String).
If the patch name is null (not set), the prototype's name will be returned (if available).@NotNull ItemBuilderdisplayName(@NotNull VersionedComponent name) PATCH FUNCTION - Applies a custom display name for the item.
Colors are assumed to be already handled in the component.
Placeholders are set automatically viaSoftPlaceholderAPI.setPlaceholders(OfflinePlayer, String).
Clear this patch by callingIBuilder.resetName().intGet the amount of items in the stack.
Range: 1 toItemStack.getMaxStackSize()(inclusive) of the prototype.
If the patch amount is null (not set), the prototype's amount is returned.intGet the damage of a damageable item, or 0 if not damageable / undamaged.
NOTE: This will always return 0 ifIBuilder.willUseDamage()returns false.intgetEnchantmentLevel(@NotNull com.cryptomorin.xseries.XEnchantment enchant) Get the level of an enchantment on the item, or 0 if the item does not have this enchantment.
If the patch does not specify a level for this enchantment, the prototype's value will be returned.Get a map of ALL enchantments on the item.
This is the combination of the prototype's enchantments and the patch enchantment overrides.
This map is never null, but can be empty if no enchantments are present on the prototype or patch.@NotNull Set<com.cryptomorin.xseries.XItemFlag> Get a set of ALL item flags on the item.
This is the combination of the prototype's item flags and the patch item flag overrides.
This set is never null, but can be empty if no item flags are present on the prototype or patch.@NotNull ItemStackGet the prototypeItemStackthis builder is based on.
The prototype is never modified, it is immutable, and accessed via this method.
UseIBuilder.build()to get the final version of the item with all patches applied.@Nullable StringGet the owner of a player head item, or null if not set / not a player head.
NOTE: This will always return null ifIBuilder.willUseSkullOwner()returns false.booleanhasGlow()Get if the item has an added glow effect.
If the patch glow is null (not set), the prototype's glow value will be returned.booleanhasItemFlag(@NotNull com.cryptomorin.xseries.XItemFlag flag) Get if the item has the specified item flag.
If the patch does not specify the presence of this flag, the prototype's value will be returned.booleanGet if the item is unbreakable or not.
If the patch unbreakable is null (not set), the prototype's unbreakable value will be returned.static @NotNull ItemBuilderload(@NotNull com.cryptomorin.xseries.XMaterial material, @NotNull ConfigurationSection section) Load anItemBuilderfrom a prototypeItemStackand a configuration section which defines additional patches to apply to the item.
The section can define the amount, name, lore, and many additional attributes of the item.static @NotNull ItemBuilderload(@NotNull ConfigurationSection section) Load a fullItemBuilderfrom a configuration section.
The section can define the material, amount, name, lore, and many additional attributes of the item.static @NotNull ItemBuilderload(@NotNull ItemStack prototype, @NotNull ConfigurationSection section) Load anItemBuilderfrom a prototypeItemStackand a configuration section which defines additional patches to apply to the item.
The section can define the amount, name, lore, and many additional attributes of the item.@Nullable List<@NotNull VersionedComponent> lore()Get the custom lore for the item.
If the patch lore is null (not set), the prototype's lore will be returned (if available).@NotNull ItemBuilderlore(@NotNull List<@NotNull VersionedComponent> lines) PATCH FUNCTION - Sets the custom lore for the item.
Colors are assumed to be already handled in the components.
Placeholders are set automatically viaSoftPlaceholderAPI.setPlaceholders(OfflinePlayer, String).
Clear this patch by callingIBuilder.resetLore().@NotNull ItemBuilderremoveEnchantment(@NotNull com.cryptomorin.xseries.XEnchantment enchant) PATCH FUNCTION - Remove an enchantment from the item.
Other Methods:
- ADD or UPDATE an enchantment viaIBuilder.setEnchantment(XEnchantment, int)
- RESET an enchantment (remove patch) viaIBuilder.resetEnchantment(XEnchantment)@NotNull ItemBuilderPATCH FUNCTION - Removes the glow effect patch, the Builder will then use the prototype's value.
NOTE: The prototype's glow value is now used by the builder, this only removes any existing glow patch.
NOTE: Even when the glow patch is removed, the item may still glow if the prototype has enchantments or a glow effect.@NotNull ItemBuilderremoveItemFlag(@NotNull com.cryptomorin.xseries.XItemFlag flag) PATCH FUNCTION - Removes an item flag from the item.
Add an item flag viaIBuilder.addItemFlag(XItemFlag).@NotNull ItemBuilderremoveItemFlags(@NotNull Collection<com.cryptomorin.xseries.XItemFlag> flags) PATCH FUNCTION - Removes several item flags from the item.
Add an item flag viaIBuilder.addItemFlag(XItemFlag).@NotNull ItemBuilderreplaceLore(@NotNull String find, @NotNull VersionedComponent replacement) PATCH PROPERTY HELPER - Replaces all occurrences of a substring in each lore line with another component.
This transformation only applies to the lore patch, if no lore patch is set this does nothing.
It does NOT modify the prototype's lore.
It will serialize each lore line into mini message format, perform the replacement, then deserialize it back to a component.@NotNull ItemBuilderreplaceLoreLineComponent(@NotNull Predicate<@NotNull VersionedComponent> filter, @NotNull List<@NotNull VersionedComponent> replacements) PATCH PROPERTY HELPER - Replaces all occurrences of lines matching the given predicate in the lore with replacement lines.
This transformation only applies to the lore patch, if no lore patch is set this does nothing.
It does NOT modify the prototype's lore.
For each line, it checks if the predicate returns true, and if so that line is replaced with the replacement lines.@NotNull ItemBuilderreplaceLorePAPI(@Nullable OfflinePlayer player) PATCH PROPERTY HELPER - Replaces all PlaceholderAPI placeholders in the lore with their respective values.
This transformation only applies to the lore patch, if no lore patch is set this does nothing.
It does NOT modify the prototype's lore.@NotNull ItemBuilderreplaceName(@NotNull String find, @NotNull VersionedComponent replacement) PATCH PROPERTY HELPER - Replaces all occurrences of a substring in the name with another component.
This transformation only applies to the name patch, if no name patch is set this does nothing.
It does NOT modify the prototype's name.@NotNull ItemBuilderreplaceNamePAPI(@Nullable OfflinePlayer player) PATCH PROPERTY HELPER - Replaces all PlaceholderAPI placeholders in the name with their respective values.
This transformation only applies to the name patch, if no name patch is set this does nothing.
It does NOT modify the prototype's name.@NotNull ItemBuilderPATCH FUNCTION - Clears all enchantment patches, the Builder will then use the prototype's values.
NOTE: The prototype's enchantments will still be applied, this only clears the patches.@NotNull ItemBuilderPATCH FUNCTION - Clears all item flag patches, the Builder will then use the prototype's values.
NOTE: The prototype's item flags will still be applied, this only clears the patches.@NotNull ItemBuilderPATCH FUNCTION - Clears the amount patch, the Builder will then use the prototype's value.
NOTE: The prototype's amount is now used by the builder, this only removes any existing amount patch.@NotNull ItemBuilderPATCH FUNCTION - Clears the damage patch, the Builder will then use the prototype's value.
NOTE: This function has no effect on the item unlessIBuilder.willUseDamage()returns true, otherwise the item will be unaffected andIBuilder.getDamage()will always return 0.
NOTE: The prototype's damage is now used by the builder (if applicable), this only removes any existing damage patch.@NotNull ItemBuilderresetEnchantment(@NotNull com.cryptomorin.xseries.XEnchantment enchant) PATCH FUNCTION - Reset an enchantment patch, the Builder will then use the prototype's value for this enchantment.
Other Methods:
- ADD or UPDATE an enchantment viaIBuilder.setEnchantment(XEnchantment, int)
- REMOVE an enchantment viaIBuilder.removeEnchantment(XEnchantment)@NotNull ItemBuilderresetItemFlag(@NotNull com.cryptomorin.xseries.XItemFlag flag) PATCH FUNCTION - Resets an item flag patch, the Builder will then use the prototype's value for this flag.
Other Methods:
- ADD an item flag viaIBuilder.addItemFlag(XItemFlag)
- REMOVE an item flag viaIBuilder.removeItemFlag(XItemFlag)@NotNull ItemBuilderPATCH FUNCTION - Clears the lore patch, the Builder will then use the prototype's value.
NOTE: The prototype's lore is now used by the builder, this only removes any existing lore patch.@NotNull ItemBuilderPATCH FUNCTION - Clears the name patch, the Builder will then use the prototype's value.
NOTE: The prototype's name is now used by the builder, this only removes any existing name patch.@NotNull ItemBuilderPATCH FUNCTION - Clears the skull owner patch, the Builder will then use the prototype's value.
NOTE: This function has no effect on the item unlessIBuilder.willUseSkullOwner()returns true, otherwise the item will be unaffected andIBuilder.getSkullOwner()will always return null.
NOTE: The prototype's skull owner is now used by the builder (if applicable), this only removes any existing skull owner patch.@NotNull ItemBuilderPATCH FUNCTION - Clears the unbreakable patch, the Builder will then use the prototype's value.
NOTE: The prototype's unbreakable value is now used by the builder, this only removes any existing unbreakable patch.@NotNull ItemBuildersetAmount(int amount) PATCH FUNCTION - Sets the amount of items in the stack.
Range: 1 toItemStack.getMaxStackSize()(inclusive) of the prototype.
Clear this patch by callingIBuilder.resetAmount().@NotNull ItemBuildersetDamage(int damage) PATCH FUNCTION - Sets the damage of a damageable item.
NOTE: This function has no effect on the item unlessIBuilder.willUseDamage()returns true, otherwise the item will be unaffected andIBuilder.getDamage()will always return 0.
Clear this patch by callingIBuilder.resetDamage().@NotNull ItemBuildersetEnchantment(@NotNull com.cryptomorin.xseries.XEnchantment enchant, int level) PATCH FUNCTION - Sets the level of an enchantment on the item.
Other Methods:
- REMOVE an enchantment viaIBuilder.removeEnchantment(XEnchantment)
- RESET an enchantment (remove patch) viaIBuilder.resetEnchantment(XEnchantment)@NotNull ItemBuildersetEnchantments(@NotNull Map<com.cryptomorin.xseries.XEnchantment, Integer> enchantments) PATCH FUNCTION - Sets the level of several enchantments on the item.
Other Methods:
- REMOVE an enchantment viaIBuilder.removeEnchantment(XEnchantment)
- RESET an enchantment (remove patch) viaIBuilder.resetEnchantment(XEnchantment)@NotNull ItemBuildersetSkullOwner(@NotNull String skullOwner) PATCH FUNCTION - Sets the owner of a player head item.
NOTE: This function has no effect on the item unlessIBuilder.willUseSkullOwner()returns true, otherwise the item will be unaffected andIBuilder.getSkullOwner()will always return null.
Clear this patch by callingIBuilder.resetSkullOwner().@NotNull ItemBuildersetUnbreakable(boolean unbreakable) PATCH FUNCTION - Sets if the item is unbreakable or not.
Clear this patch by callingIBuilder.resetUnbreakable().booleanCheck if the prototype item supports setting damage (is damageable).
If this returns true, then the following methods will modify the item:
-IBuilder.setDamage(int)
-IBuilder.resetDamage()
-IBuilder.getDamage()
If this returns false, calling those methods have no effect andIBuilder.getDamage()will always return 0.booleanCheck if the prototype item supports setting a skull owner (is a player head).
If this returns true, then the following methods will modify the item:
-IBuilder.setSkullOwner(String)
-IBuilder.resetSkullOwner()
-IBuilder.getSkullOwner()
If this returns false, calling those methods have no effect andIBuilder.getSkullOwner()will always return null.Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.kamikazejam.kamicommon.item.IBuilder
addLoreComponents, addLoreLines, addLoreLines, build, cloneWithNewPrototype, cloneWithNewPrototype, disableGlow, displayName, getLore, getMaterial, getName, hideAttributes, isAddGlow, lore, removeLore, replaceBoth, replaceBoth, replaceBothPAPI, replaceBothPAPI, replaceLore, replaceLoreLine, replaceLoreLineComponent, replaceLorePAPI, replaceName, replaceNamePAPI, setDisplayName, setDurability, setDurability, setGlow, setItemFlag, setLore, setLore, setName, toItemStack, toItemStack
-
Constructor Details
-
ItemBuilder
Construct a new ItemBuilder from a prototypeItemStack.
(The prototype is never modified, it is immutable, and accessed viagetPrototype())
Call ItemBuilder methods to set and update item 'patches', and then useIBuilder.build()to construct the final item.
- Parameters:
prototype- The initial item this class applies patches on top of.
-
ItemBuilder
public ItemBuilder(@NotNull @NotNull com.cryptomorin.xseries.XMaterial material) Construct a new ItemBuilder from anXMaterial.
This is equivalent to callingItemBuilder(ItemStack)with the result ofXMaterial.parseItem() -
ItemBuilder
Construct a new ItemBuilder from anMaterial.
This is equivalent to callingItemBuilder(XMaterial)with the result ofXMaterial.matchXMaterial(Material)
-
-
Method Details
-
getPrototype
Description copied from interface:IBuilderGet the prototypeItemStackthis builder is based on.
The prototype is never modified, it is immutable, and accessed via this method.
UseIBuilder.build()to get the final version of the item with all patches applied.- Specified by:
getPrototypein interfaceIBuilder<ItemBuilder>- Returns:
- The prototype
ItemStackthis builder is based on.
-
build
Description copied from interface:IBuilderCompiles the patches, applying them on top of the prototype.- Specified by:
buildin interfaceIBuilder<ItemBuilder>- Parameters:
viewer- ThePlayerviewing this item, for PlaceholderAPI support. (Can be null)- Returns:
- The final
ItemStackwith all patches applied.
-
setAmount
Description copied from interface:IBuilderPATCH FUNCTION - Sets the amount of items in the stack.
Range: 1 toItemStack.getMaxStackSize()(inclusive) of the prototype.
Clear this patch by callingIBuilder.resetAmount().
(If the amount is out of range, it will be clamped within the valid range.)- Specified by:
setAmountin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
resetAmount
Description copied from interface:IBuilderPATCH FUNCTION - Clears the amount patch, the Builder will then use the prototype's value.
NOTE: The prototype's amount is now used by the builder, this only removes any existing amount patch.- Specified by:
resetAmountin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
setDamage
Description copied from interface:IBuilderPATCH FUNCTION - Sets the damage of a damageable item.
NOTE: This function has no effect on the item unlessIBuilder.willUseDamage()returns true, otherwise the item will be unaffected andIBuilder.getDamage()will always return 0.
Clear this patch by callingIBuilder.resetDamage().- Specified by:
setDamagein interfaceIBuilder<ItemBuilder>- Parameters:
damage- The damage value to set (0 = undamaged)- Returns:
- This builder, for chaining
-
resetDamage
Description copied from interface:IBuilderPATCH FUNCTION - Clears the damage patch, the Builder will then use the prototype's value.
NOTE: This function has no effect on the item unlessIBuilder.willUseDamage()returns true, otherwise the item will be unaffected andIBuilder.getDamage()will always return 0.
NOTE: The prototype's damage is now used by the builder (if applicable), this only removes any existing damage patch.- Specified by:
resetDamagein interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
displayName
Description copied from interface:IBuilderPATCH FUNCTION - Applies a custom display name for the item.
Colors are assumed to be already handled in the component.
Placeholders are set automatically viaSoftPlaceholderAPI.setPlaceholders(OfflinePlayer, String).
Clear this patch by callingIBuilder.resetName().- Specified by:
displayNamein interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
resetName
Description copied from interface:IBuilderPATCH FUNCTION - Clears the name patch, the Builder will then use the prototype's value.
NOTE: The prototype's name is now used by the builder, this only removes any existing name patch.- Specified by:
resetNamein interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
lore
@NotNull public @NotNull ItemBuilder lore(@NotNull @NotNull List<@NotNull VersionedComponent> lines) Description copied from interface:IBuilderPATCH FUNCTION - Sets the custom lore for the item.
Colors are assumed to be already handled in the components.
Placeholders are set automatically viaSoftPlaceholderAPI.setPlaceholders(OfflinePlayer, String).
Clear this patch by callingIBuilder.resetLore().- Specified by:
lorein interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
resetLore
Description copied from interface:IBuilderPATCH FUNCTION - Clears the lore patch, the Builder will then use the prototype's value.
NOTE: The prototype's lore is now used by the builder, this only removes any existing lore patch.- Specified by:
resetLorein interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
setUnbreakable
Description copied from interface:IBuilderPATCH FUNCTION - Sets if the item is unbreakable or not.
Clear this patch by callingIBuilder.resetUnbreakable().- Specified by:
setUnbreakablein interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
resetUnbreakable
Description copied from interface:IBuilderPATCH FUNCTION - Clears the unbreakable patch, the Builder will then use the prototype's value.
NOTE: The prototype's unbreakable value is now used by the builder, this only removes any existing unbreakable patch.- Specified by:
resetUnbreakablein interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
addItemFlag
@NotNull public @NotNull ItemBuilder addItemFlag(@NotNull @NotNull com.cryptomorin.xseries.XItemFlag flag) Description copied from interface:IBuilderPATCH FUNCTION - Adds an item flag to the item.
Remove an item flag viaIBuilder.removeItemFlag(XItemFlag).- Specified by:
addItemFlagin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
addItemFlags
@NotNull public @NotNull ItemBuilder addItemFlags(@NotNull @NotNull Collection<com.cryptomorin.xseries.XItemFlag> flags) Description copied from interface:IBuilderPATCH FUNCTION - Adds several item flags to the item.
Remove an item flag viaIBuilder.removeItemFlag(XItemFlag).- Specified by:
addItemFlagsin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
removeItemFlag
@NotNull public @NotNull ItemBuilder removeItemFlag(@NotNull @NotNull com.cryptomorin.xseries.XItemFlag flag) Description copied from interface:IBuilderPATCH FUNCTION - Removes an item flag from the item.
Add an item flag viaIBuilder.addItemFlag(XItemFlag).- Specified by:
removeItemFlagin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
removeItemFlags
@NotNull public @NotNull ItemBuilder removeItemFlags(@NotNull @NotNull Collection<com.cryptomorin.xseries.XItemFlag> flags) Description copied from interface:IBuilderPATCH FUNCTION - Removes several item flags from the item.
Add an item flag viaIBuilder.addItemFlag(XItemFlag).- Specified by:
removeItemFlagsin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
resetItemFlag
@NotNull public @NotNull ItemBuilder resetItemFlag(@NotNull @NotNull com.cryptomorin.xseries.XItemFlag flag) Description copied from interface:IBuilderPATCH FUNCTION - Resets an item flag patch, the Builder will then use the prototype's value for this flag.
Other Methods:
- ADD an item flag viaIBuilder.addItemFlag(XItemFlag)
- REMOVE an item flag viaIBuilder.removeItemFlag(XItemFlag)- Specified by:
resetItemFlagin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
resetAllItemFlags
Description copied from interface:IBuilderPATCH FUNCTION - Clears all item flag patches, the Builder will then use the prototype's values.
NOTE: The prototype's item flags will still be applied, this only clears the patches.- Specified by:
resetAllItemFlagsin interfaceIBuilder<ItemBuilder>
-
setEnchantment
@NotNull public @NotNull ItemBuilder setEnchantment(@NotNull @NotNull com.cryptomorin.xseries.XEnchantment enchant, int level) Description copied from interface:IBuilderPATCH FUNCTION - Sets the level of an enchantment on the item.
Other Methods:
- REMOVE an enchantment viaIBuilder.removeEnchantment(XEnchantment)
- RESET an enchantment (remove patch) viaIBuilder.resetEnchantment(XEnchantment)- Specified by:
setEnchantmentin interfaceIBuilder<ItemBuilder>- Parameters:
level- The level of the enchantment to set (MUST be greater than 0)- Returns:
- This builder, for chaining
-
setEnchantments
@NotNull public @NotNull ItemBuilder setEnchantments(@NotNull @NotNull Map<com.cryptomorin.xseries.XEnchantment, Integer> enchantments) Description copied from interface:IBuilderPATCH FUNCTION - Sets the level of several enchantments on the item.
Other Methods:
- REMOVE an enchantment viaIBuilder.removeEnchantment(XEnchantment)
- RESET an enchantment (remove patch) viaIBuilder.resetEnchantment(XEnchantment)- Specified by:
setEnchantmentsin interfaceIBuilder<ItemBuilder>- Parameters:
enchantments- The map of enchantments to their levels to set (all levels MUST be greater than 0)- Returns:
- This builder, for chaining
-
removeEnchantment
@NotNull public @NotNull ItemBuilder removeEnchantment(@NotNull @NotNull com.cryptomorin.xseries.XEnchantment enchant) Description copied from interface:IBuilderPATCH FUNCTION - Remove an enchantment from the item.
Other Methods:
- ADD or UPDATE an enchantment viaIBuilder.setEnchantment(XEnchantment, int)
- RESET an enchantment (remove patch) viaIBuilder.resetEnchantment(XEnchantment)- Specified by:
removeEnchantmentin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
resetEnchantment
@NotNull public @NotNull ItemBuilder resetEnchantment(@NotNull @NotNull com.cryptomorin.xseries.XEnchantment enchant) Description copied from interface:IBuilderPATCH FUNCTION - Reset an enchantment patch, the Builder will then use the prototype's value for this enchantment.
Other Methods:
- ADD or UPDATE an enchantment viaIBuilder.setEnchantment(XEnchantment, int)
- REMOVE an enchantment viaIBuilder.removeEnchantment(XEnchantment)- Specified by:
resetEnchantmentin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
resetAllEnchantments
Description copied from interface:IBuilderPATCH FUNCTION - Clears all enchantment patches, the Builder will then use the prototype's values.
NOTE: The prototype's enchantments will still be applied, this only clears the patches.- Specified by:
resetAllEnchantmentsin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
addGlow
Description copied from interface:IBuilderPATCH FUNCTION - Sets whether the item should have an added glow effect.
Clear this patch by callingIBuilder.removeGlow().- Specified by:
addGlowin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
removeGlow
Description copied from interface:IBuilderPATCH FUNCTION - Removes the glow effect patch, the Builder will then use the prototype's value.
NOTE: The prototype's glow value is now used by the builder, this only removes any existing glow patch.
NOTE: Even when the glow patch is removed, the item may still glow if the prototype has enchantments or a glow effect.- Specified by:
removeGlowin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
setSkullOwner
Description copied from interface:IBuilderPATCH FUNCTION - Sets the owner of a player head item.
NOTE: This function has no effect on the item unlessIBuilder.willUseSkullOwner()returns true, otherwise the item will be unaffected andIBuilder.getSkullOwner()will always return null.
Clear this patch by callingIBuilder.resetSkullOwner().- Specified by:
setSkullOwnerin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
resetSkullOwner
Description copied from interface:IBuilderPATCH FUNCTION - Clears the skull owner patch, the Builder will then use the prototype's value.
NOTE: This function has no effect on the item unlessIBuilder.willUseSkullOwner()returns true, otherwise the item will be unaffected andIBuilder.getSkullOwner()will always return null.
NOTE: The prototype's skull owner is now used by the builder (if applicable), this only removes any existing skull owner patch.- Specified by:
resetSkullOwnerin interfaceIBuilder<ItemBuilder>- Returns:
- This builder, for chaining
-
getAmount
public int getAmount()Description copied from interface:IBuilderGet the amount of items in the stack.
Range: 1 toItemStack.getMaxStackSize()(inclusive) of the prototype.
If the patch amount is null (not set), the prototype's amount is returned.- Specified by:
getAmountin interfaceIBuilder<ItemBuilder>
-
customName
Description copied from interface:IBuilderGet the custom display name for the item.
Placeholders are set automatically viaSoftPlaceholderAPI.setPlaceholders(OfflinePlayer, String).
If the patch name is null (not set), the prototype's name will be returned (if available).- Specified by:
customNamein interfaceIBuilder<ItemBuilder>
-
lore
Description copied from interface:IBuilderGet the custom lore for the item.
If the patch lore is null (not set), the prototype's lore will be returned (if available).- Specified by:
lorein interfaceIBuilder<ItemBuilder>
-
isUnbreakable
public boolean isUnbreakable()Description copied from interface:IBuilderGet if the item is unbreakable or not.
If the patch unbreakable is null (not set), the prototype's unbreakable value will be returned.- Specified by:
isUnbreakablein interfaceIBuilder<ItemBuilder>
-
hasItemFlag
public boolean hasItemFlag(@NotNull @NotNull com.cryptomorin.xseries.XItemFlag flag) Description copied from interface:IBuilderGet if the item has the specified item flag.
If the patch does not specify the presence of this flag, the prototype's value will be returned.- Specified by:
hasItemFlagin interfaceIBuilder<ItemBuilder>
-
getItemFlags
Description copied from interface:IBuilderGet a set of ALL item flags on the item.
This is the combination of the prototype's item flags and the patch item flag overrides.
This set is never null, but can be empty if no item flags are present on the prototype or patch.- Specified by:
getItemFlagsin interfaceIBuilder<ItemBuilder>
-
getEnchantmentLevel
public int getEnchantmentLevel(@NotNull @NotNull com.cryptomorin.xseries.XEnchantment enchant) Description copied from interface:IBuilderGet the level of an enchantment on the item, or 0 if the item does not have this enchantment.
If the patch does not specify a level for this enchantment, the prototype's value will be returned.- Specified by:
getEnchantmentLevelin interfaceIBuilder<ItemBuilder>
-
getEnchantments
Description copied from interface:IBuilderGet a map of ALL enchantments on the item.
This is the combination of the prototype's enchantments and the patch enchantment overrides.
This map is never null, but can be empty if no enchantments are present on the prototype or patch.- Specified by:
getEnchantmentsin interfaceIBuilder<ItemBuilder>
-
hasGlow
public boolean hasGlow()Description copied from interface:IBuilderGet if the item has an added glow effect.
If the patch glow is null (not set), the prototype's glow value will be returned.- Specified by:
hasGlowin interfaceIBuilder<ItemBuilder>
-
getSkullOwner
Description copied from interface:IBuilderGet the owner of a player head item, or null if not set / not a player head.
NOTE: This will always return null ifIBuilder.willUseSkullOwner()returns false.- Specified by:
getSkullOwnerin interfaceIBuilder<ItemBuilder>
-
willUseSkullOwner
public boolean willUseSkullOwner()Description copied from interface:IBuilderCheck if the prototype item supports setting a skull owner (is a player head).
If this returns true, then the following methods will modify the item:
-IBuilder.setSkullOwner(String)
-IBuilder.resetSkullOwner()
-IBuilder.getSkullOwner()
If this returns false, calling those methods have no effect andIBuilder.getSkullOwner()will always return null.- Specified by:
willUseSkullOwnerin interfaceIBuilder<ItemBuilder>
-
getDamage
public int getDamage()Description copied from interface:IBuilderGet the damage of a damageable item, or 0 if not damageable / undamaged.
NOTE: This will always return 0 ifIBuilder.willUseDamage()returns false.- Specified by:
getDamagein interfaceIBuilder<ItemBuilder>
-
willUseDamage
public boolean willUseDamage()Description copied from interface:IBuilderCheck if the prototype item supports setting damage (is damageable).
If this returns true, then the following methods will modify the item:
-IBuilder.setDamage(int)
-IBuilder.resetDamage()
-IBuilder.getDamage()
If this returns false, calling those methods have no effect andIBuilder.getDamage()will always return 0.- Specified by:
willUseDamagein interfaceIBuilder<ItemBuilder>
-
replaceName
@NotNull public @NotNull ItemBuilder replaceName(@NotNull @NotNull String find, @NotNull @NotNull VersionedComponent replacement) Description copied from interface:IBuilderPATCH PROPERTY HELPER - Replaces all occurrences of a substring in the name with another component.
This transformation only applies to the name patch, if no name patch is set this does nothing.
It does NOT modify the prototype's name.
It will serialize the name into message format, perform the replacement, then deserialize it back to a component.- Specified by:
replaceNamein interfaceIBuilder<ItemBuilder>- Parameters:
find- The substring to findreplacement- The component to replace each occurrence with- Returns:
- This builder, for chaining
-
replaceNamePAPI
Description copied from interface:IBuilderPATCH PROPERTY HELPER - Replaces all PlaceholderAPI placeholders in the name with their respective values.
This transformation only applies to the name patch, if no name patch is set this does nothing.
It does NOT modify the prototype's name.- Specified by:
replaceNamePAPIin interfaceIBuilder<ItemBuilder>- Parameters:
player- The player to use for PlaceholderAPI replacements, or null to skip player-specific placeholders- Returns:
- This builder, for chaining
-
replaceLoreLineComponent
@NotNull public @NotNull ItemBuilder replaceLoreLineComponent(@NotNull @NotNull Predicate<@NotNull VersionedComponent> filter, @NotNull @NotNull List<@NotNull VersionedComponent> replacements) Description copied from interface:IBuilderPATCH PROPERTY HELPER - Replaces all occurrences of lines matching the given predicate in the lore with replacement lines.
This transformation only applies to the lore patch, if no lore patch is set this does nothing.
It does NOT modify the prototype's lore.
For each line, it checks if the predicate returns true, and if so that line is replaced with the replacement lines.- Specified by:
replaceLoreLineComponentin interfaceIBuilder<ItemBuilder>- Parameters:
filter- The predicate to test each lore line against, if it returns true that line is replacedreplacements- The lines to swap in, in place of the entire line containing the find string- Returns:
- This builder, for chaining
-
replaceLore
@NotNull public @NotNull ItemBuilder replaceLore(@NotNull @NotNull String find, @NotNull @NotNull VersionedComponent replacement) Description copied from interface:IBuilderPATCH PROPERTY HELPER - Replaces all occurrences of a substring in each lore line with another component.
This transformation only applies to the lore patch, if no lore patch is set this does nothing.
It does NOT modify the prototype's lore.
It will serialize each lore line into mini message format, perform the replacement, then deserialize it back to a component.- Specified by:
replaceLorein interfaceIBuilder<ItemBuilder>- Parameters:
find- The substring to find in each lore linereplacement- The component to replace each occurrence with- Returns:
- This builder, for chaining
-
replaceLorePAPI
Description copied from interface:IBuilderPATCH PROPERTY HELPER - Replaces all PlaceholderAPI placeholders in the lore with their respective values.
This transformation only applies to the lore patch, if no lore patch is set this does nothing.
It does NOT modify the prototype's lore.- Specified by:
replaceLorePAPIin interfaceIBuilder<ItemBuilder>- Parameters:
player- The player to use for PlaceholderAPI replacements, or null to skip player-specific placeholders- Returns:
- This builder, for chaining
-
addLoreComponents
@NotNull public @NotNull ItemBuilder addLoreComponents(@NotNull @NotNull List<@NotNull VersionedComponent> lines) Description copied from interface:IBuilderPATCH FUNCTION - Appends additional lines to the current lore.
If no lore patch is currently set, this will create a new lore patch with the provided lines.
If a lore patch is already set, the new lines will be added to the end of the existing lore.
Colors are assumed to be already handled in the components.
Placeholders are set automatically viaSoftPlaceholderAPI.setPlaceholders(OfflinePlayer, String).- Specified by:
addLoreComponentsin interfaceIBuilder<ItemBuilder>- Parameters:
lines- The lore lines to append- Returns:
- This builder, for chaining
-
clone
- Specified by:
clonein interfaceIBuilder<ItemBuilder>- Overrides:
clonein classObject
-
cloneWithNewPrototype
@NotNull public @NotNull ItemBuilder cloneWithNewPrototype(@NotNull @NotNull ItemStack newPrototype) Description copied from interface:IBuilderCreate a clone of this builder with all the same patches, but a different prototypeItemStack.- Specified by:
cloneWithNewPrototypein interfaceIBuilder<ItemBuilder>
-
load
Load a fullItemBuilderfrom a configuration section.
The section can define the material, amount, name, lore, and many additional attributes of the item.- Returns:
- The loaded
ItemBuilderwhere the config values were set as IBuilder PATCHES. - Throws:
IllegalArgumentException- If any part of the parsing failed (for example if no valid material was defined).
-
load
@NotNull public static @NotNull ItemBuilder load(@NotNull @NotNull com.cryptomorin.xseries.XMaterial material, @NotNull @NotNull ConfigurationSection section) Load anItemBuilderfrom a prototypeItemStackand a configuration section which defines additional patches to apply to the item.
The section can define the amount, name, lore, and many additional attributes of the item. (Everything except the material type)- Parameters:
material- The material to use for the prototype. Used as the base for the ItemBuilder.section- The configuration section to load additional patches from.
-
load
@NotNull public static @NotNull ItemBuilder load(@NotNull @NotNull ItemStack prototype, @NotNull @NotNull ConfigurationSection section) Load anItemBuilderfrom a prototypeItemStackand a configuration section which defines additional patches to apply to the item.
The section can define the amount, name, lore, and many additional attributes of the item. (Everything except the material type)- Parameters:
prototype- The prototype item stack to base the ItemBuilder on, this defines the material type and any existing item meta.section- The configuration section to load additional patches from.
-