KItemStack
Description & Properties
The KItemStack
class is a utility class for creating ItemStack
objects with custom properties such as name, lore, material, amount, enchantments, and item flags. It provides a fluent builder pattern for constructing ItemStack
objects with the desired properties.
The class has the following properties and methods:
itemStack
: TheItemStack
object that is being built.builder()
: Returns a newBuilder
object to start building a newItemStack
.Builder
: A nested class that provides methods for setting the properties of theItemStack
and building the finalItemStack
object.name
: The display name of theItemStack
.lore
: The lore of theItemStack
.material
: The material type of theItemStack
.amount
: The amount of theItemStack
.enchants
: A list of enchantments to apply to theItemStack
.itemFlags
: A list of item flags to apply to theItemStack
.getListOfRandom(amount: Int)
: Generates a list of randomItemStack
objects with random materials.addItemFlag(itemFlag: ItemFlag)
: Adds an item flag to theItemStack
builder.addItemFlags(itemFlags: MutableList<ItemFlag>)
: Adds multiple item flags to theItemStack
builder.removeItemFlag(itemFlag: ItemFlag)
: Removes an item flag from theItemStack
builder.removeItemFlags(itemFlags: MutableList<ItemFlag>)
: Removes multiple item flags from theItemStack
builder.setName(name: String)
: Sets the display name of theItemStack
.setLore(lore: MutableList<String>)
: Sets the lore of theItemStack
.setLore(vararg lore: String)
: Sets the lore of theItemStack
using varargs.setMaterial(material: Material)
: Sets the material type of theItemStack
.setAmount(amount: Int)
: Sets the amount of theItemStack
.addEnchantment(enchantment: Enchantment)
: Adds an enchantment to theItemStack
.addEnchantments(enchantments: MutableList<Enchantment>)
: Adds multiple enchantments to theItemStack
.removeEnchantment(enchantment: Enchantment)
: Removes an enchantment from theItemStack
.removeEnchantments(enchantments: MutableList<Enchantment>)
: Removes multiple enchantments from theItemStack
.build()
: Builds the finalItemStack
object with the specified properties.
Example
You can use the KItemStack
class to create custom ItemStack
objects with specific properties and apply them to GUI elements, items, or other game mechanics. The fluent builder pattern allows you to easily set the desired properties of the ItemStack
and create it with a single method call.
Here is an example of how to create a custom ItemStack
using the KItemStack
class in Kotlin:
In this example, we create a custom ItemStack
object representing a diamond sword with a custom name, lore, enchantment, item flag, and amount. The KItemStack
class provides a convenient way to create and customize ItemStack
objects in a concise and readable manner.
Summary
The KItemStack
class simplifies the process of creating custom ItemStack
objects in Bukkit/Spigot plugins by providing a fluent builder pattern for setting the properties of the ItemStack
. By using the KItemStack
class, you can easily create and customize ItemStack
objects with specific attributes and apply them to various aspects of your plugin, such as GUIs, items, or game mechanics.