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
ItemStack
s 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();
-
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 ItemBuilder
addGlow()
PATCH FUNCTION - Sets whether the item should have an added glow effect.
Clear this patch by callingIBuilder.removeGlow()
.@NotNull ItemBuilder
addItemFlag
(@NotNull com.cryptomorin.xseries.XItemFlag flag) PATCH FUNCTION - Adds an item flag to the item.
Remove an item flag viaIBuilder.removeItemFlag(XItemFlag)
.@NotNull ItemBuilder
addItemFlags
(@NotNull Collection<com.cryptomorin.xseries.XItemFlag> flags) PATCH FUNCTION - Adds several item flags to the item.
Remove an item flag viaIBuilder.removeItemFlag(XItemFlag)
.@NotNull ItemBuilder
addLoreLines
(@NotNull List<@NotNull String> 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.
Color translations usingStringUtilP.p(OfflinePlayer, String)
will be applied duringIBuilder.build(Player)
automatically.@NotNull ItemStack
Compiles the patches, applying them on top of the prototype.@NotNull ItemBuilder
clone()
@NotNull ItemBuilder
cloneWithNewPrototype
(@NotNull ItemStack newPrototype) Create a clone of this builder with all the same patches, but a different prototypeItemStack
.int
Get 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.int
Get the damage of a damageable item, or 0 if not damageable / undamaged.
NOTE: This will always return 0 ifIBuilder.willUseDamage()
returns false.int
getEnchantmentLevel
(@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.getLore()
Get the custom lore for the item.
If the patch lore is null (not set), the prototype's lore will be returned (if available).@Nullable String
getName()
Get the custom display name for the item.
Color translations usingStringUtilP.p(OfflinePlayer, String)
will be applied duringIBuilder.build(Player)
automatically.
If the patch name is null (not set), the prototype's name will be returned (if available).@NotNull ItemStack
Get the prototypeItemStack
this 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 String
Get 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.boolean
hasGlow()
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.boolean
hasItemFlag
(@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.boolean
Get 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 ItemBuilder
load
(@NotNull com.cryptomorin.xseries.XMaterial material, @NotNull ConfigurationSection section) Load anItemBuilder
from a prototypeItemStack
and 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 ItemBuilder
load
(@NotNull ConfigurationSection section) Load a fullItemBuilder
from a configuration section.
The section can define the material, amount, name, lore, and many additional attributes of the item.static @NotNull ItemBuilder
load
(@NotNull ItemStack prototype, @NotNull ConfigurationSection section) Load anItemBuilder
from a prototypeItemStack
and 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.@NotNull ItemBuilder
removeEnchantment
(@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 ItemBuilder
PATCH 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 ItemBuilder
removeItemFlag
(@NotNull com.cryptomorin.xseries.XItemFlag flag) PATCH FUNCTION - Removes an item flag from the item.
Add an item flag viaIBuilder.addItemFlag(XItemFlag)
.@NotNull ItemBuilder
removeItemFlags
(@NotNull Collection<com.cryptomorin.xseries.XItemFlag> flags) PATCH FUNCTION - Removes several item flags from the item.
Add an item flag viaIBuilder.addItemFlag(XItemFlag)
.@NotNull ItemBuilder
replaceLore
(@NotNull String find, @NotNull String replacement) PATCH PROPERTY HELPER - Replaces all occurrences of a substring in each lore line with another string.
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 ItemBuilder
replaceLoreLine
(@NotNull String find, @NotNull List<@NotNull String> replacement) PATCH PROPERTY HELPER - Searches for a substring in the lore and replaces that entire line 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.
UsesChatColor.stripColor(String)
for comparison to ignore color formatting.@NotNull ItemBuilder
replaceLorePAPI
(@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 ItemBuilder
replaceName
(@NotNull String find, @NotNull String replacement) PATCH PROPERTY HELPER - Replaces all occurrences of a substring in the name with another string.
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 ItemBuilder
replaceNamePAPI
(@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 ItemBuilder
PATCH 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 ItemBuilder
PATCH 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 ItemBuilder
PATCH 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 ItemBuilder
PATCH 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 ItemBuilder
resetEnchantment
(@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 ItemBuilder
resetItemFlag
(@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 ItemBuilder
PATCH 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 ItemBuilder
PATCH 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 ItemBuilder
PATCH 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 ItemBuilder
PATCH 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 ItemBuilder
setAmount
(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 ItemBuilder
setDamage
(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 ItemBuilder
setEnchantment
(@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 ItemBuilder
setEnchantments
(@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 ItemBuilder
PATCH FUNCTION - Sets the custom lore for the item.
Color translations usingStringUtilP.p(OfflinePlayer, String)
will be applied duringIBuilder.build(Player)
automatically.
Clear this patch by callingIBuilder.resetLore()
.@NotNull ItemBuilder
PATCH FUNCTION - Sets the custom lore for the item.
Color translations usingStringUtilP.p(OfflinePlayer, String)
will be applied duringIBuilder.build(Player)
automatically.
Clear this patch by callingIBuilder.resetLore()
.@NotNull ItemBuilder
PATCH FUNCTION - Applies a custom display name for the item.
Color translations usingStringUtilP.p(OfflinePlayer, String)
will be applied duringIBuilder.build(Player)
automatically.
Clear this patch by callingIBuilder.resetName()
.@NotNull ItemBuilder
setSkullOwner
(@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 ItemBuilder
setUnbreakable
(boolean unbreakable) PATCH FUNCTION - Sets if the item is unbreakable or not.
Clear this patch by callingIBuilder.resetUnbreakable()
.boolean
Check 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.boolean
Check 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, wait
Methods inherited from interface com.kamikazejam.kamicommon.item.IBuilder
addLoreLines, build, cloneWithNewPrototype, cloneWithNewPrototype, disableGlow, getMaterial, hideAttributes, isAddGlow, removeLore, replaceBoth, replaceBothPAPI, replaceBothPAPI, replaceLorePAPI, replaceNamePAPI, setDisplayName, setDurability, setDurability, setGlow, setItemFlag, 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:IBuilder
Get the prototypeItemStack
this 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:
getPrototype
in interfaceIBuilder<ItemBuilder>
- Returns:
- The prototype
ItemStack
this builder is based on.
-
build
Description copied from interface:IBuilder
Compiles the patches, applying them on top of the prototype.- Specified by:
build
in interfaceIBuilder<ItemBuilder>
- Parameters:
viewer
- ThePlayer
viewing this item, for PlaceholderAPI support. (Can be null)- Returns:
- The final
ItemStack
with all patches applied.
-
setAmount
Description copied from interface:IBuilder
PATCH 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:
setAmount
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
resetAmount
Description copied from interface:IBuilder
PATCH 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:
resetAmount
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
setDamage
Description copied from interface:IBuilder
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()
.- Specified by:
setDamage
in interfaceIBuilder<ItemBuilder>
- Parameters:
damage
- The damage value to set (0 = undamaged)- Returns:
- This builder, for chaining
-
resetDamage
Description copied from interface:IBuilder
PATCH 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:
resetDamage
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
setName
Description copied from interface:IBuilder
PATCH FUNCTION - Applies a custom display name for the item.
Color translations usingStringUtilP.p(OfflinePlayer, String)
will be applied duringIBuilder.build(Player)
automatically.
Clear this patch by callingIBuilder.resetName()
.- Specified by:
setName
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
resetName
Description copied from interface:IBuilder
PATCH 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:
resetName
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
setLore
Description copied from interface:IBuilder
PATCH FUNCTION - Sets the custom lore for the item.
Color translations usingStringUtilP.p(OfflinePlayer, String)
will be applied duringIBuilder.build(Player)
automatically.
Clear this patch by callingIBuilder.resetLore()
.- Specified by:
setLore
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
setLore
Description copied from interface:IBuilder
PATCH FUNCTION - Sets the custom lore for the item.
Color translations usingStringUtilP.p(OfflinePlayer, String)
will be applied duringIBuilder.build(Player)
automatically.
Clear this patch by callingIBuilder.resetLore()
.- Specified by:
setLore
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
resetLore
Description copied from interface:IBuilder
PATCH 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:
resetLore
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
setUnbreakable
Description copied from interface:IBuilder
PATCH FUNCTION - Sets if the item is unbreakable or not.
Clear this patch by callingIBuilder.resetUnbreakable()
.- Specified by:
setUnbreakable
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
resetUnbreakable
Description copied from interface:IBuilder
PATCH 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:
resetUnbreakable
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
addItemFlag
@NotNull public @NotNull ItemBuilder addItemFlag(@NotNull @NotNull com.cryptomorin.xseries.XItemFlag flag) Description copied from interface:IBuilder
PATCH FUNCTION - Adds an item flag to the item.
Remove an item flag viaIBuilder.removeItemFlag(XItemFlag)
.- Specified by:
addItemFlag
in 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:IBuilder
PATCH FUNCTION - Adds several item flags to the item.
Remove an item flag viaIBuilder.removeItemFlag(XItemFlag)
.- Specified by:
addItemFlags
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
removeItemFlag
@NotNull public @NotNull ItemBuilder removeItemFlag(@NotNull @NotNull com.cryptomorin.xseries.XItemFlag flag) Description copied from interface:IBuilder
PATCH FUNCTION - Removes an item flag from the item.
Add an item flag viaIBuilder.addItemFlag(XItemFlag)
.- Specified by:
removeItemFlag
in 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:IBuilder
PATCH FUNCTION - Removes several item flags from the item.
Add an item flag viaIBuilder.addItemFlag(XItemFlag)
.- Specified by:
removeItemFlags
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
resetItemFlag
@NotNull public @NotNull ItemBuilder resetItemFlag(@NotNull @NotNull com.cryptomorin.xseries.XItemFlag flag) Description copied from interface:IBuilder
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)
- Specified by:
resetItemFlag
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
resetAllItemFlags
Description copied from interface:IBuilder
PATCH 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:
resetAllItemFlags
in interfaceIBuilder<ItemBuilder>
-
setEnchantment
@NotNull public @NotNull ItemBuilder setEnchantment(@NotNull @NotNull com.cryptomorin.xseries.XEnchantment enchant, int level) Description copied from interface:IBuilder
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)
- Specified by:
setEnchantment
in 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:IBuilder
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)
- Specified by:
setEnchantments
in 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:IBuilder
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)
- Specified by:
removeEnchantment
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
resetEnchantment
@NotNull public @NotNull ItemBuilder resetEnchantment(@NotNull @NotNull com.cryptomorin.xseries.XEnchantment enchant) Description copied from interface:IBuilder
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)
- Specified by:
resetEnchantment
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
resetAllEnchantments
Description copied from interface:IBuilder
PATCH 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:
resetAllEnchantments
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
addGlow
Description copied from interface:IBuilder
PATCH FUNCTION - Sets whether the item should have an added glow effect.
Clear this patch by callingIBuilder.removeGlow()
.- Specified by:
addGlow
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
removeGlow
Description copied from interface:IBuilder
PATCH 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:
removeGlow
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
setSkullOwner
Description copied from interface:IBuilder
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()
.- Specified by:
setSkullOwner
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
resetSkullOwner
Description copied from interface:IBuilder
PATCH 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:
resetSkullOwner
in interfaceIBuilder<ItemBuilder>
- Returns:
- This builder, for chaining
-
getAmount
public int getAmount()Description copied from interface:IBuilder
Get 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:
getAmount
in interfaceIBuilder<ItemBuilder>
-
getName
Description copied from interface:IBuilder
Get the custom display name for the item.
Color translations usingStringUtilP.p(OfflinePlayer, String)
will be applied duringIBuilder.build(Player)
automatically.
If the patch name is null (not set), the prototype's name will be returned (if available).- Specified by:
getName
in interfaceIBuilder<ItemBuilder>
-
getLore
Description copied from interface:IBuilder
Get 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:
getLore
in interfaceIBuilder<ItemBuilder>
-
isUnbreakable
public boolean isUnbreakable()Description copied from interface:IBuilder
Get 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:
isUnbreakable
in interfaceIBuilder<ItemBuilder>
-
hasItemFlag
public boolean hasItemFlag(@NotNull @NotNull com.cryptomorin.xseries.XItemFlag flag) Description copied from interface:IBuilder
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.- Specified by:
hasItemFlag
in interfaceIBuilder<ItemBuilder>
-
getItemFlags
Description copied from interface:IBuilder
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.- Specified by:
getItemFlags
in interfaceIBuilder<ItemBuilder>
-
getEnchantmentLevel
public int getEnchantmentLevel(@NotNull @NotNull com.cryptomorin.xseries.XEnchantment enchant) Description copied from interface:IBuilder
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.- Specified by:
getEnchantmentLevel
in interfaceIBuilder<ItemBuilder>
-
getEnchantments
Description copied from interface:IBuilder
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.- Specified by:
getEnchantments
in interfaceIBuilder<ItemBuilder>
-
hasGlow
public boolean hasGlow()Description copied from interface:IBuilder
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.- Specified by:
hasGlow
in interfaceIBuilder<ItemBuilder>
-
getSkullOwner
Description copied from interface:IBuilder
Get 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:
getSkullOwner
in interfaceIBuilder<ItemBuilder>
-
willUseSkullOwner
public boolean willUseSkullOwner()Description copied from interface:IBuilder
Check 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:
willUseSkullOwner
in interfaceIBuilder<ItemBuilder>
-
getDamage
public int getDamage()Description copied from interface:IBuilder
Get the damage of a damageable item, or 0 if not damageable / undamaged.
NOTE: This will always return 0 ifIBuilder.willUseDamage()
returns false.- Specified by:
getDamage
in interfaceIBuilder<ItemBuilder>
-
willUseDamage
public boolean willUseDamage()Description copied from interface:IBuilder
Check 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:
willUseDamage
in interfaceIBuilder<ItemBuilder>
-
replaceName
@NotNull public @NotNull ItemBuilder replaceName(@NotNull @NotNull String find, @NotNull @NotNull String replacement) Description copied from interface:IBuilder
PATCH PROPERTY HELPER - Replaces all occurrences of a substring in the name with another string.
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:
replaceName
in interfaceIBuilder<ItemBuilder>
- Parameters:
find
- The substring to findreplacement
- The sub- Returns:
- This builder, for chaining
-
replaceNamePAPI
Description copied from interface:IBuilder
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.- Specified by:
replaceNamePAPI
in interfaceIBuilder<ItemBuilder>
- Parameters:
player
- The player to use for PlaceholderAPI replacements, or null to skip player-specific placeholders- Returns:
- This builder, for chaining
-
replaceLoreLine
@NotNull public @NotNull ItemBuilder replaceLoreLine(@NotNull @NotNull String find, @NotNull @NotNull List<@NotNull String> replacement) Description copied from interface:IBuilder
PATCH PROPERTY HELPER - Searches for a substring in the lore and replaces that entire line 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.
UsesChatColor.stripColor(String)
for comparison to ignore color formatting.- Specified by:
replaceLoreLine
in interfaceIBuilder<ItemBuilder>
- Parameters:
find
- The string to search for in the lore (color codes will be stripped for comparison)replacement
- 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 String replacement) Description copied from interface:IBuilder
PATCH PROPERTY HELPER - Replaces all occurrences of a substring in each lore line with another string.
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:
replaceLore
in interfaceIBuilder<ItemBuilder>
- Parameters:
find
- The substring to find in each lore linereplacement
- The string to replace each occurrence with- Returns:
- This builder, for chaining
-
replaceLorePAPI
Description copied from interface:IBuilder
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.- Specified by:
replaceLorePAPI
in interfaceIBuilder<ItemBuilder>
- Parameters:
player
- The player to use for PlaceholderAPI replacements, or null to skip player-specific placeholders- Returns:
- This builder, for chaining
-
addLoreLines
Description copied from interface:IBuilder
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.
Color translations usingStringUtilP.p(OfflinePlayer, String)
will be applied duringIBuilder.build(Player)
automatically.- Specified by:
addLoreLines
in interfaceIBuilder<ItemBuilder>
- Parameters:
lines
- The lore lines to append- Returns:
- This builder, for chaining
-
clone
- Specified by:
clone
in interfaceIBuilder<ItemBuilder>
- Overrides:
clone
in classObject
-
cloneWithNewPrototype
@NotNull public @NotNull ItemBuilder cloneWithNewPrototype(@NotNull @NotNull ItemStack newPrototype) Description copied from interface:IBuilder
Create a clone of this builder with all the same patches, but a different prototypeItemStack
.- Specified by:
cloneWithNewPrototype
in interfaceIBuilder<ItemBuilder>
-
load
Load a fullItemBuilder
from a configuration section.
The section can define the material, amount, name, lore, and many additional attributes of the item.- Returns:
- The loaded
ItemBuilder
where 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 anItemBuilder
from a prototypeItemStack
and 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 anItemBuilder
from a prototypeItemStack
and 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.
-