Create your items

Creating an item is very straightforward.

Actually create the item

To create the item, you have to provide an ID that will allow the plugin to see the difference between it and another item.

AbilityItem testItem = AbilityItem.newItem("testItem");

Give the item its ItemStack

If you are familiar with the Spigot API, you are obviously familiar with the ItemStack class. Here, you have to provide an ItemStack that the AbilityItem will represent. Here is how:

ItemStack itemStack = new ItemStack(Material.STICK);
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName(ChatColor.BOLD+"THE STICK");
itemStack.setItemMeta(meta);

testItem.from(itemStack);

Lock the item

There are two ways to lock an item.

  1. Lock it completely in the slot it is in (cannot be removed unless death or /clear)

testItem.lockInSlot();
  1. Stop it from being dropped

testItem.denyDrop();

Set the quantity

Even though you can set the quantity in the ItemStack, you can also set it using

testItem.setQuantity(3);

Set what happens on interact

If you have dealt with Spigot event, you should know the PlayerInteractEvent one (if not, here's the javadocs link). Here you can completely set what will happen when the item is clicked on. Here:

testItem.setClickEvent(event -> {
        event.getPlayer().sendMessage(ChatColor.ITALIC+"You clicked da stick...");
    })

When a player clicks on the item, they will receive the message You clicked da stick...

Finally, build it up

When you are done making the item, you have to build it using:

testItem.build();

Straight configuration

You can also make configurating an item more compact, like this:

ItemStack itemStack = new ItemStack(Material.STICK);
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName(ChatColor.BOLD+"THE STICK");
itemStack.setItemMeta(meta);

AbilityItem testItem = AbilityItem.newItem("testItem").from(itemStack).lockInSlot().setQuantity(3).setClickEvent(event -> {
    event.getPlayer().sendMessage(ChatColor.ITALIC+"You clicked da stick...");
}).build();

Give the item

You then have a very simple way to give the item:

testItem.give(Bukkit.getPlayerExact("Notch"));

Last updated