ItemBuilder

Since 1.0.0

Creating custom ItemStacks can result in big chunks of code as you have to get the item meta, edit it, then set it... That's why MCUtils contains a simplified way to do this, the ItemBuilder class.

Creating items

For a basic example, let's create a new ItemStack that will be one diamond helmet with the custom colored name "<#FFFHeavy Diamond Helmet#0EF>", taking advantage of color patterns, this diamond helmet will also have some lore with one empty line and another line with the text "&7&oMade with &e&oMCUtils" as well as being unbreakable.

import net.codersky.mcutils.builders.ItemBuilder;

ItemStack item = new ItemBuilder(Material.DIAMOND_HELMET)
    .setDisplayName("<#FFFHeavy Diamond Helmet#0EF>")
    .addLore("", "&7&oMade with &e&oMCUtils")
    .setUnbreakable(true)
    .build(); // Converts the builder to ItemStack
  

SkullBuilder

This type of ItemBuilder makes it easy to create player skulls, it works in a very similar way as the ItemBuilder but adds a few skull-specific methods. Please note that the setUrl method currently only allows Minecraft urls. In order to get urls you can use a website like MineSkin.

import net.codersky.mcutils.builders.SkullBuilder;

ItemStack skull = new SkullBuilder()
    // Set by player
    .setOwner(Bukkit.getPlayer("xDec0de_"))
    // ... Or by url
    .setUrl("http://textures.minecraft.net/...")
    .build();

Last updated