Package dev.demeng.pluginbase.item
Class ItemBuilder
java.lang.Object
dev.demeng.pluginbase.item.ItemBuilder
A utility for quickly creating
ItemStacks.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a single line of lore on top of the current lore.amount(int amount) Changes the amount of the item.armorColor(@Nullable org.bukkit.Color color) Sets the color of leather armor.Clears any enchantments that have been applied.Clears all current item flags.Clears the item lore.@NotNull ItemBuildercopy()Clones this item builder.static @NotNull ItemBuildercreate(@Nullable org.bukkit.inventory.ItemStack stack) Creates a new builder from an existing item stack.static @NotNull ItemBuildercreate(@Nullable org.bukkit.Material material) Creates a new builder from a simple material.static @NotNull ItemBuildercreate(@Nullable org.bukkit.Material material, int amount) Creates a new builder from a material and an amount.static @NotNull ItemBuildercreate(@Nullable org.bukkit.Material material, int amount, short damage) Creates a new builder from a material, amount, and damage.durability(short durability) Changes the durability of the item.Adds all the enchants specified in the map, with the key being the enchantment and the value being the level.enchant(@NotNull org.bukkit.enchantments.Enchantment enchant, int level) Adds a safe enchantment.enchant(@NotNull org.bukkit.enchantments.Enchantment enchant, int level, boolean safe) Adds an enchantment with customizable safety.flags(@NotNull org.bukkit.inventory.ItemFlag... flags) Sets the item flags.@NotNull org.bukkit.inventory.ItemStackget()Gets the current item stack.static @NotNull org.bukkit.inventory.ItemStackgetMaterial(@Nullable String strMaterial) Gets a material from a string.static @NotNull org.bukkit.inventory.ItemStackgetMaterialOrDef(@Nullable String strMaterial, @NotNull org.bukkit.inventory.ItemStack def) Attempts to get a material from a string, but returns the default item stack if the result of the provided material string is invalid or unsupported, instead of throwing an error and just returning stone likegetMaterial(String).static @NotNull Optional<org.bukkit.inventory.ItemStack>getMaterialSafe(@Nullable String strMaterial) Gets a material from a string.glow(boolean glow) Sets if the item should be given a durability enchantment to make it appear glowing and add a hide enchantment item flag.Sets the lore to the specified string(s).Sets the lore to the specified list.Sets the custom model data of the item, which is only supported in 1.14+.Sets the display name of the item.skullOwner(@NotNull String owner) Sets the skull owner of a skull item.skullOwner(@NotNull UUID owner) Sets the skull owner of a skull item.skullTexture(@NotNull String texture) Sets the skull texture to the provided base64 encoded string.unbreakable(boolean unbreakable) Sets if the item should be unbreakable.unenchant(@NotNull org.bukkit.enchantments.Enchantment enchant) Removes the specified enchantment.
-
Constructor Details
-
ItemBuilder
public ItemBuilder()
-
-
Method Details
-
create
@NotNull public static @NotNull ItemBuilder create(@Nullable @Nullable org.bukkit.inventory.ItemStack stack) Creates a new builder from an existing item stack.- Parameters:
stack- The item stack to clone, replaced with STONE item stack if null- Returns:
- The builder
-
create
@NotNull public static @NotNull ItemBuilder create(@Nullable @Nullable org.bukkit.Material material, int amount, short damage) Creates a new builder from a material, amount, and damage.- Parameters:
material- The material of the stack, replaced with STONE if nullamount- The amount of the stackdamage- The damage (a.k.a. the durability) of the stack- Returns:
- The builder
-
create
@NotNull public static @NotNull ItemBuilder create(@Nullable @Nullable org.bukkit.Material material, int amount) Creates a new builder from a material and an amount.- Parameters:
material- The material of the stack, replaced with STONE if nullamount- The amount of the stack- Returns:
- The builder
-
create
@NotNull public static @NotNull ItemBuilder create(@Nullable @Nullable org.bukkit.Material material) Creates a new builder from a simple material.- Parameters:
material- The material of the stack, replaced with STONE if null- Returns:
- The builder
-
amount
Changes the amount of the item.- Parameters:
amount- The new amount- Returns:
- this
-
durability
Changes the durability of the item.- Parameters:
durability- The new durability- Returns:
- this
-
name
Sets the display name of the item.- Parameters:
name- The new display name, colorized internally- Returns:
- this
-
enchant
public ItemBuilder enchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchant, int level, boolean safe) Adds an enchantment with customizable safety.- Parameters:
enchant- The enchantment to addlevel- The level of the enchantmentsafe- If the enchantment should be safe- Returns:
- this
-
enchant
public ItemBuilder enchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchant, int level) Adds a safe enchantment.- Parameters:
enchant- The enchantment to addlevel- The level of the enchantment- Returns:
- this
-
enchant
public ItemBuilder enchant(@NotNull @NotNull Map<org.bukkit.enchantments.Enchantment, Integer> enchants) Adds all the enchants specified in the map, with the key being the enchantment and the value being the level.- Parameters:
enchants- The enchants to add- Returns:
- this
-
unenchant
Removes the specified enchantment.- Parameters:
enchant- The enchantment to remove- Returns:
- this
-
clearEnchants
Clears any enchantments that have been applied.- Returns:
- this
-
lore
Sets the lore to the specified list.- Parameters:
lore- The lore lines, colorized internally- Returns:
- this
-
lore
Sets the lore to the specified string(s). Each string represents a new line.- Parameters:
lore- The lore line(s), colorized internally- Returns:
- this
-
addLore
Adds a single line of lore on top of the current lore.- Parameters:
line- The lore line to add, colorized internally- Returns:
- this
-
clearLore
Clears the item lore.- Returns:
- this
-
unbreakable
Sets if the item should be unbreakable.- Parameters:
unbreakable- If the item should be unbreakable- Returns:
- this
-
flags
Sets the item flags.- Parameters:
flags- The flags to set- Returns:
- this
-
clearFlags
Clears all current item flags.- Returns:
- this
-
glow
Sets if the item should be given a durability enchantment to make it appear glowing and add a hide enchantment item flag. Setting this to true will also hide all of your other enchantments in the lore. This should only be enabled for GUI aesthetic purposes.Note: When the glow is applied, it should be permanent. It is not recommended that you call this method again to remove the glow since it can effect enchantments and item flags from other sources.
- Parameters:
glow- If the item should have a glowing effect applied- Returns:
- this
-
modelData
Sets the custom model data of the item, which is only supported in 1.14+. If the server version does not support custom model data, this option is simply ignored.- Parameters:
modelData- The custom model data- Returns:
- this
-
skullOwner
Sets the skull owner of a skull item. Ignored if the item type is not a player skull.- Parameters:
owner- The username of the skull owner- Returns:
- this
-
skullOwner
Sets the skull owner of a skull item. Ignored if the item type is not a player skull.- Parameters:
owner- The UUId of the skull owner- Returns:
- this
-
skullTexture
Sets the skull texture to the provided base64 encoded string. Ignored if the item type is not a player skull.- Parameters:
texture- The base64 encoded texture- Returns:
- this
-
armorColor
Sets the color of leather armor. Ignored if the item type is not leather armor.- Parameters:
color- The color to change the armor to- Returns:
- this
-
get
@NotNull public @NotNull org.bukkit.inventory.ItemStack get()Gets the current item stack.- Returns:
- The current item stack
-
copy
Clones this item builder.- Returns:
- The cloned instance
-
getMaterialSafe
@NotNull public static @NotNull Optional<org.bukkit.inventory.ItemStack> getMaterialSafe(@Nullable @Nullable String strMaterial) Gets a material from a string. Note that this actually returns an item stack as a data values may need to be included on legacy versions.- Parameters:
strMaterial- The string material to parse- Returns:
- A standard item stack with no meta, or null if the material is invalid or unsupported
-
getMaterial
@NotNull public static @NotNull org.bukkit.inventory.ItemStack getMaterial(@Nullable @Nullable String strMaterial) Gets a material from a string. Throws an error if the material is invalid or unsupported, unlikegetMaterialSafe(String).- Parameters:
strMaterial- The string material to parse- Returns:
- A standard item stack with no meta, or stone if invalid/unsupported
- See Also:
-
getMaterialOrDef
@NotNull public static @NotNull org.bukkit.inventory.ItemStack getMaterialOrDef(@Nullable @Nullable String strMaterial, @NotNull @NotNull org.bukkit.inventory.ItemStack def) Attempts to get a material from a string, but returns the default item stack if the result of the provided material string is invalid or unsupported, instead of throwing an error and just returning stone likegetMaterial(String).- Parameters:
strMaterial- The string material to parsedef- The default material if the provided material is invalid or unsupported- Returns:
- A standard item stack with no meta, or the default stack if invalid/unsupported
- See Also:
-