Package de.maxbossing.maxapi.Builders
Class ItemStackBuilder
java.lang.Object
de.maxbossing.maxapi.Builders.ItemStackBuilder
ItemStackBuilder
- Author:
- max
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA class containing sensitive NMS code for manipulating NBT data on an item stack. -
Constructor Summary
ConstructorsConstructorDescriptionItemStackBuilder(ItemStackBuilder builder) Deprecated.This constructor is deprecated and will be removed in a future version.ItemStackBuilder(org.bukkit.configuration.file.FileConfiguration cfg, String path) Constructs a new ItemStackBuilder with the ItemStack from the specified path in the given FileConfiguration.ItemStackBuilder(org.bukkit.inventory.ItemStack item) Constructs a new ItemStackBuilder with the specified ItemStack.ItemStackBuilder(org.bukkit.Material material) Constructs a new ItemStackBuilder with the specified material.ItemStackBuilder(org.bukkit.Material material, int amount) Constructs a new ItemStackBuilder with the specified material and amount.ItemStackBuilder(org.bukkit.Material material, int amount, String displayname) Constructs a new ItemStackBuilder with the specified material, amount, and display name.ItemStackBuilder(org.bukkit.Material material, String displayname) Constructs a new ItemStackBuilder with the specified material and display name. -
Method Summary
Modifier and TypeMethodDescriptionamount(int amount) Sets the amount of the material for the ItemStack.Applies the properties of an item stack builder from a JSON string to the current builder.org.bukkit.inventory.ItemStackbuild()Builds the item stack using the current builder's properties.customModelData(int customModelData) Sets the Custom Model Data of the ItemStack.damage(short damage) Deprecated.This method is deprecated and will be removed in a future version.data(org.bukkit.material.MaterialData data) Sets the data for the ItemStack.displayname(String displayname) Sets the display name for the ItemStack.durability(short damage) Sets the durability (damage) for the ItemStack.Sets theEnchantments for the ItemStack.enchant(org.bukkit.enchantments.Enchantment enchant, int level) Adds an Enchantment to the ItemStack.Sets the flags for the item stack.flag(org.bukkit.inventory.ItemFlag flag) Adds anItemFlagto the ItemStack.fromConfig(org.bukkit.configuration.file.FileConfiguration cfg, String path) Loads the item stack from a configuration file at the specified path.static ItemStackBuilderReturns an item stack builder from a JSON string.intReturns the stack size of the item stack.booleanReturns whether the and symbol is replaced with the section symbol (§).shortDeprecated.org.bukkit.material.MaterialDatagetData()Deprecated.Returns the display name of the item stack.shortReturns the durability of the item stack.Returns the enchantments and their levels for the item stack.List<org.bukkit.inventory.ItemFlag>getFlags()Returns the flags for the item stack.getLore()Deprecated.getLores()Returns the lore lines for the item stack.org.bukkit.MaterialReturns the material of the item stack.org.bukkit.inventory.meta.ItemMetagetMeta()Returns the item meta of the item stack.glow()Adds a glowing effect to the item stack.Adds a line of lore to the ItemStack.Deprecated.uselore(String)insteadSets a line of lore at a specific index in the ItemStack.Sets the lore for the ItemStack.Deprecated.UseItemBuilder#lorematerial(org.bukkit.Material material) Sets the material for the ItemStack.meta(org.bukkit.inventory.meta.ItemMeta meta) Sets the meta data for the ItemStack.Deprecated.replaceAndSymbol(boolean replace) Sets whether to replace the and symbol with the section symbol (§).Saves the item stack to a configuration file at the specified path.static voidtoConfig(org.bukkit.configuration.file.FileConfiguration cfg, String path, ItemStackBuilder builder) Saves the item stack to a configuration file at the specified path.Toggles the replacement of the and symbol with the section symbol (§).Toggles the use of stack sizes larger than the maximum stack size for the item.toJson()Returns the item stack as a JSON string.static StringtoJson(ItemStackBuilder builder) Returns the item stack as a JSON string.unbreakable(boolean unbreakable) Sets the unbreakable status for the item stack.unsafe()Returns an Unsafe instance for the item stack builder, which contains the nbt methods.unsafeStackSize(boolean allow) Enables or disables the use of stack sizes larger than the maximum stack size for the item.
-
Constructor Details
-
ItemStackBuilder
public ItemStackBuilder(org.bukkit.Material material) Constructs a new ItemStackBuilder with the specified material. If the material is null, it will default to Material.AIR.- Parameters:
material- the material for the ItemStack
-
ItemStackBuilder
public ItemStackBuilder(org.bukkit.Material material, int amount) Constructs a new ItemStackBuilder with the specified material and amount. If the material is null, it will default to Material.AIR. If the amount is greater than the material's maximum stack size or less than or equal to zero, the amount will default to 1 unless `unsafeStackSize` is set to true.- Parameters:
material- the material for the ItemStackamount- the amount of the material for the ItemStack
-
ItemStackBuilder
Constructs a new ItemStackBuilder with the specified material, amount, and display name. If the material is null, it will default to Material.AIR. If the amount is greater than the material's maximum stack size or less than or equal to zero, the amount will default to 1 unless `unsafeStackSize` is set to true. The display name must not be null.- Parameters:
material- the material for the ItemStackamount- the amount of the material for the ItemStackdisplayname- the display name for the ItemStack- Throws:
NullPointerException- if the display name is null
-
ItemStackBuilder
Constructs a new ItemStackBuilder with the specified material and display name. If the material is null, it will default to Material.AIR. The display name must not be null.- Parameters:
material- the material for the ItemStackdisplayname- the display name for the ItemStack- Throws:
NullPointerException- if the display name is null
-
ItemStackBuilder
public ItemStackBuilder(org.bukkit.inventory.ItemStack item) Constructs a new ItemStackBuilder with the specified ItemStack. The ItemStack must not be null. The new ItemStackBuilder will have the same material, amount, data, damage, enchantments, display name, lore, and flags as the original ItemStack.- Parameters:
item- the ItemStack to create a new ItemStackBuilder from- Throws:
NullPointerException- if the ItemStack is null
-
ItemStackBuilder
Constructs a new ItemStackBuilder with the ItemStack from the specified path in the given FileConfiguration. The FileConfiguration must not be null. If the path is invalid or the ItemStack at the specified path is null, the ItemStackBuilder will default to a new ItemStack with Material.AIR.- Parameters:
cfg- the FileConfiguration to retrieve the ItemStack frompath- the path in the FileConfiguration to the ItemStack- Throws:
NullPointerException- if the FileConfiguration is null
-
ItemStackBuilder
Deprecated.This constructor is deprecated and will be removed in a future version. Use the copy constructor instead.Constructs a new ItemStackBuilder with the properties of the specified ItemStackBuilder. The ItemStackBuilder must not be null.- Parameters:
builder- the ItemStackBuilder to copy the properties from- Throws:
NullPointerException- if the ItemStackBuilder is null
-
-
Method Details
-
amount
Sets the amount of the material for the ItemStack. If the amount is greater than the material's maximum stack size or less than or equal to zero, the amount will default to 1 unless `unsafeStackSize` is set to true.- Parameters:
amount- the amount of the material for the ItemStack- Returns:
- the current ItemStackBuilder
-
data
Sets the data for the ItemStack. The data must not be null.- Parameters:
data- the data for the ItemStack- Returns:
- the current ItemStackBuilder
- Throws:
NullPointerException- if the data is null
-
damage
Deprecated.This method is deprecated and will be removed in a future version. Usedurability(short)instead.Sets the damage (durability) for the ItemStack.- Parameters:
damage- the damage for the ItemStack- Returns:
- the current ItemStackBuilder
-
durability
Sets the durability (damage) for the ItemStack.- Parameters:
damage- the durability for the ItemStack- Returns:
- the current ItemStackBuilder
-
material
Sets the material for the ItemStack. The material must not be null.- Parameters:
material- the material for the ItemStack- Returns:
- the current ItemStackBuilder
- Throws:
NullPointerException- if the material is null
-
meta
Sets the meta data for the ItemStack. The meta data must not be null.- Parameters:
meta- the meta data for the ItemStack- Returns:
- the current ItemStackBuilder
- Throws:
NullPointerException- if the meta data is null
-
enchant
Adds an Enchantment to the ItemStack.- Parameters:
enchant- the Enchantment to add to the ItemStacklevel- the level of the Enchantment- Returns:
- the current ItemStackBuilder
- Throws:
NullPointerException- if the Enchantment is null
-
enchant
Sets theEnchantments for the ItemStack. The enchantments must not be null.- Parameters:
enchantments- the enchantments for the ItemStack- Returns:
- the current ItemStackBuilder
- Throws:
NullPointerException- if the enchantments are null
-
displayname
Sets the display name for the ItemStack. The display name must not be null. If `andSymbol` is set to true, the display name will be formatted- Parameters:
displayname- the display name for the ItemStack- Returns:
- the current ItemStackBuilder
- Throws:
NullPointerException- if the display name is null
-
lore
Adds a line of lore to the ItemStack. The line of lore must not be null. If `andSymbol` is set to true, the line of lore will be formatted.- Parameters:
line- the line of lore to add to the ItemStack- Returns:
- the current ItemStackBuilder
- Throws:
NullPointerException- if the line of lore is null
-
lore
Sets the lore for the ItemStack. The lore must not be null. If `andSymbol` is set to true, the lines of lore will be formatted.- Parameters:
lore- the lore for the ItemStack- Returns:
- the current ItemStackBuilder
- Throws:
NullPointerException- if the lore is null
-
lores
Deprecated.UseItemBuilder#loreAdds one or more Lines to the Lore of the ItemStack- Parameters:
lines- One or more Strings for the ItemStack Lore- Returns:
- the current ItemStackBuilder
-
lore
Deprecated.uselore(String)insteadAdds lines of lore to the ItemStack. The lines of lore must not be null. If `andSymbol` is set to true, the lines of lore will be formatted.- Parameters:
lines- the lines of lore to add to the ItemStack- Returns:
- the current ItemStackBuilder
- Throws:
NullPointerException- if the lines of lore are null
-
lore
Sets a line of lore at a specific index in the ItemStack. The line of lore must not be null. If `andSymbol` is set to true, the line of lore will be formatted.- Parameters:
line- the line of lore to set in the ItemStackindex- the index in the lore list to set the line of lore- Returns:
- the current ItemStackBuilder
- Throws:
NullPointerException- if the line of lore is nullIndexOutOfBoundsException- if the index is out of range
-
customModelData
Sets the Custom Model Data of the ItemStack. The param must be not null.- Parameters:
customModelData- the CustomModelData the Item should have- Returns:
- the current itemStackBuilder
- Throws:
NullPointerException- is the param is null
-
flag
Adds anItemFlagto the ItemStack. The item flag must not be null.- Parameters:
flag- the item flag to add to the ItemStack- Returns:
- the current ItemStackBuilder
- Throws:
NullPointerException- if the item flag is null
-
flag
Sets the flags for the item stack.- Parameters:
flags- the flags to set for the item stack- Returns:
- the current
ItemStackBuilderinstance - Throws:
NullPointerException- if the flags list is null
-
unbreakable
Sets the unbreakable status for the item stack.- Parameters:
unbreakable- whether the item stack should be unbreakable or not- Returns:
- the current
ItemStackBuilderinstance
-
glow
Adds a glowing effect to the item stack.- Returns:
- the current
ItemStackBuilderinstance
-
unsafe
Returns an Unsafe instance for the item stack builder, which contains the nbt methods.- Returns:
- an Unsafe instance for the item stack builder
-
replaceAndSymbol
Deprecated.Deprecated. UsereplaceAndSymbol(boolean)instead.- Returns:
- the current
ItemStackBuilderinstance
-
replaceAndSymbol
Sets whether to replace the and symbol with the section symbol (§).- Parameters:
replace- whether to replace the and symbol or not- Returns:
- the current
ItemStackBuilderinstance
-
toggleReplaceAndSymbol
Toggles the replacement of the and symbol with the section symbol (§).- Returns:
- the current
ItemStackBuilderinstance
-
unsafeStackSize
Enables or disables the use of stack sizes larger than the maximum stack size for the item.- Parameters:
allow- whether to allow unsafe stack sizes or not- Returns:
- the current
ItemStackBuilderinstance
-
toggleUnsafeStackSize
Toggles the use of stack sizes larger than the maximum stack size for the item.- Returns:
- the current
ItemStackBuilderinstance
-
getDisplayname
Returns the display name of the item stack.- Returns:
- the display name of the item stack
-
getAmount
public int getAmount()Returns the stack size of the item stack.- Returns:
- the stack size of the item stack
-
getEnchantments
Returns the enchantments and their levels for the item stack.- Returns:
- the enchantments and their levels for the item stack
-
getDamage
Deprecated.Deprecated. UsegetDurability()instead.- Returns:
- the durability of the item stack
-
getDurability
public short getDurability()Returns the durability of the item stack.- Returns:
- the durability of the item stack
-
getLores
Returns the lore lines for the item stack.- Returns:
- the lore lines for the item stack
-
getAndSymbol
public boolean getAndSymbol()Returns whether the and symbol is replaced with the section symbol (§).- Returns:
- true if the and symbol is replaced, false otherwise
-
getFlags
Returns the flags for the item stack.- Returns:
- the flags for the item stack
-
getMaterial
public org.bukkit.Material getMaterial()Returns the material of the item stack.- Returns:
- the material of the item stack
-
getMeta
public org.bukkit.inventory.meta.ItemMeta getMeta()Returns the item meta of the item stack.- Returns:
- the item meta of the item stack
-
getData
Deprecated.Deprecated. MaterialData is subject to removal instead.- Returns:
- the material data of the item stack
-
getLore
Deprecated.Deprecated. UsegetLores()instead.- Returns:
- the lore lines for the item stack
-
toConfig
Saves the item stack to a configuration file at the specified path.- Parameters:
cfg- the configuration file to save topath- the path to save the item stack at- Returns:
- the current
ItemStackBuilderinstance
-
fromConfig
public ItemStackBuilder fromConfig(org.bukkit.configuration.file.FileConfiguration cfg, String path) Loads the item stack from a configuration file at the specified path.- Parameters:
cfg- the configuration file to load frompath- the path to load the item stack from- Returns:
- a new
ItemStackBuilderinstance with the loaded item stack
-
toConfig
public static void toConfig(org.bukkit.configuration.file.FileConfiguration cfg, String path, ItemStackBuilder builder) Saves the item stack to a configuration file at the specified path.- Parameters:
cfg- the configuration file to save topath- the path to save the item stack atbuilder- the item stack builder to save
-
toJson
Returns the item stack as a JSON string.- Returns:
- the item stack as a JSON string
-
toJson
Returns the item stack as a JSON string.- Parameters:
builder- the item stack builder to convert to a JSON string- Returns:
- the item stack as a JSON string
-
fromJson
Returns an item stack builder from a JSON string.- Parameters:
json- the JSON string to convert to an item stack builder- Returns:
- an item stack builder from the JSON string
-
applyJson
Applies the properties of an item stack builder from a JSON string to the current builder.- Parameters:
json- the JSON string to apply to the current builderoverwrite- whether to overwrite the current builder's properties or not- Returns:
- the current
ItemStackBuilderinstance
-
build
public org.bukkit.inventory.ItemStack build()Builds the item stack using the current builder's properties.- Returns:
- the built item stack
-