-
Notifications
You must be signed in to change notification settings - Fork 3
Item Builder
ItemBuilder allows you to create ItemStack objects with edited ItemMeta, such as display name, lore, etc without having to go through the hassle of editing the ItemMeta yourself.
ItemBuilder is really simple to use and can reduce the code needed to make an ItemStack with custom ItemMeta, thus increasing the readability of your code.
All you need to do is create a new ItemBuilder object using its constructor. This can be achieved by parsing an already-existing ItemStack to the constructor or a Material. This can be down as follows:
ItemBuilder itemBuilder = new ItemBuilder(itemStack);
The lore of the item can be set using two methods:
- ItemBuilder#setLore(String... lore)
- ItemBuilder#setLore(List lore)
ItemBuilder itemBuilder = new ItemBuilder(Material.DIAMOND_SWORD);
itemBuilder.setName("&e&lDIAMOND SWORD");
itemBuilder.setLore(" ", "&7This is a diamond sword!");
// This will give you the completed ItemStack object
ItemStack itemStack = itemBuilder.build();
Other methods are available as well, such as:
itemBuilder.parsePlaceholders(PlaceholderBuilder placeholderBuilder)
itemBuilder.addLoreLine(...)
itemBuilder.removeLoreLine(...)
itemBuilder.addItemFlag(ItemFlag flag)
itemBuilder.removeItemFlag(ItemFlag flag)
itemBuilder.addUnsafeEnchantment(Enchantment enchantment, Level level)
itemBuilder.removeEnchantment(Enchantment enchantment)
itemBuilder.setData(short data)
itemBuilder.setUnbreakable()
Please keep in mind that the Strings in both the name and lore automatically have colour codes converted and applied. This works with hex colour codes as well as with legacy codes.