Itemstack arguments
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
Say we want to create a command that gives you items. For this command, we will use the following syntax:
/item <itemstack>
With this syntax, we can easily create our command:
new CommandAPICommand("item")
.withArguments(new ItemStackArgument("itemStack"))
.executesPlayer((player, args) -> {
player.getInventory().addItem((ItemStack) args.get("itemStack"));
})
.register();
CommandAPICommand("item")
.withArguments(ItemStackArgument("itemStack"))
.executesPlayer(PlayerCommandExecutor { player, args ->
player.inventory.addItem(args["itemStack"] as ItemStack)
})
.register()
commandAPICommand("item") {
itemStackArgument("itemstack")
playerExecutor { player, args ->
player.inventory.addItem(args["itemstack"] as ItemStack)
}
}