-
Notifications
You must be signed in to change notification settings - Fork 1
Items
You can simply create an ItemBuilder
by getting a new instance of it:
ItemBuilder ib = new ItemBuilder();
If you have already an ItemStack
with the same properties as the ones you want to put on the Builder, you can easily copy them with the #clone(ItemStack)
method:
ItemStack item = new ItemStack(Material.GRASS);
ItemBuilder grassBuilder = new ItemBuilder().clone(item);
Of course, before performing the build of the ItemStack object, it's necessary to give to the Builder the item's properties. It wouldn't be able to build something for you if you didn't even give him any details. So, let's see how to tell to the Builder every single property.
The values we can modify are:
-
Material (Yeah, we have provided a full legacy materials support, so you can use it with almost every Spigot's version)
-
Name (It's the custom name of the item)
-
Lore (It's a custom multiple-line description of the item, you can see it by hovering the cursor on the item)
-
Amount (The custom quantity of the item, it SHOULD NOT be set over than 64. Do it at your own risk)
-
Metadata (It's a custom value owned only by some items, used to distinguish e.g. some wool or glass blocks from other ones with different colors. It's also called "Durability" because, in other items which aren't unbreakable, it can edit how much broken they are)
-
Glowing (You know, that cool effect on enchanted items...)
Note: any of these values support placeholders! The #addPlaceHolder(String, Object)
method seen previously in the Messages section is also available here!
ItemBuilder ib = new ItemBuilder();
ib.addPlaceHolder("%owner%", "Pedro");
ib.setName("&aSword of %owner%");
ib.setMaterial("DIAMOND_SWORD"); // also works #setMaterial(276) OR #setMaterial(Material.DIAMOND_SWORD)
ib.setLore("&aThis is", "&ba very cool", "&csword!", "&7Owner: %owner%");
ib.setAmount(1);
ib.setMetadata((short) 1561);
ib.setGlowing(true);
Now, our Builder has all the information needed: we can get the ItemStack by using the #build()
method.
ItemStack item = ib.build();