8000 Item Builder · frosxt/light Wiki · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Item Builder

frosxt edited this page Jul 4, 2023 · 1 revision

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.

Creating an instance

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);

Setting the lore

The lore of the item can be set using two methods:

  • ItemBuilder#setLore(String... lore)
  • ItemBuilder#setLore(List lore)

Example Usage

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.

Clone this wiki locally
0