Skip to content

ItemStack arguments

An item stack argument with suggestions for Minecraft items

The ItemStackArgument class represents in-game items. As expected, this should be casted to Bukkit's ItemStack object. The ItemStack which is returned by the ItemStackArgument always has a size of 1.

Example – Giving a player an itemstack

Example – Giving a player an itemstack

Say we want to create a command that gives you items. For this command, we will use the following syntax:

mccmd
/item <itemstack>

With this syntax, we can easily create our command:

java
new CommandAPICommand("item")
    .withArguments(new ItemStackArgument("itemStack"))
    .executesPlayer((player, args) -> {
        player.getInventory().addItem((ItemStack) args.get("itemStack"));
    })
    .register();