> For the complete documentation index, see [llms.txt](https://axelrindle.gitbook.io/pocketknife/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://axelrindle.gitbook.io/pocketknife/usage/pocketinventory.md).

# PocketInventory

```kotlin
class ShopCommand(
    private val plugin: TestPlugin
) : PocketCommand() {

    private val inventory: PocketInventory = PocketInventory(plugin, "Shop", 4)

    init {
        // golden apple
        inventory.setItem(11, ItemStack(Material.GOLDEN_APPLE)) { /* buy logic */ }

        // close item
        inventory.setItem(53, ItemStack(Material.DARK_OAK_DOOR_ITEM)) { it.view.close() }
    }

    override fun getName(): String {
        return "shop"
    }

    override fun handle(sender: CommandSender, command: Command, args: Array<out String>): Boolean {
        inventory.open(sender)
        return true
    }

    override fun requirePlayer(): Boolean {
        return true
    }
}
```

It is common to create custom inventories in connection with commands. When calling the command, the custom inventory will be shown to the player.

The fulfill the requirement of a `Player`, the `requirePlayer` method is overridden to return `true`.

This example implementation of the `PocketInventory` creates an inventory with 4 rows and two items contained: a **golden apple** in the middle of the second row and a **dark oak door** at the bottom right corner.

While living inside a `PocketCommand` the inventory is shown every player calling the associated command (`/shop` in this case).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://axelrindle.gitbook.io/pocketknife/usage/pocketinventory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
