# API Reference
Complete reference for the Chest-API interfaces. All classes reside in the `gg.lode.chestapi` and `gg.lode.chestapi.api` packages.
---
## ChestAPI
Static accessor for the API singleton. Located in `gg.lode.chestapi.ChestAPI`.
| Method | Return Type | Description |
|---|---|---|
| `getApi()` | `IChestAPI` | Returns the API instance, or `null` if Chest is not loaded. |
```java
IChestAPI api = ChestAPI.getApi();
```
---
## IChestAPI
Primary API interface. Provides convenience methods for common operations and access to the loot table manager.
| Method | Return Type | Description |
|---|---|---|
| `getLootTableManager()` | `ILootTableManager` | Returns the loot table manager instance. |
| `getVersion()` | `String` | Returns the plugin version string. |
| `reloadLootTables()` | `boolean` | Reloads all loot tables from disk. Returns `true` on success. |
| `getAvailableLootTables()` | `Set<String>` | Returns a set of all loot table names. |
| `lootTableExists(String name)` | `boolean` | Checks whether a loot table with the given name exists. |
| `populateInventory(String lootTableName, Inventory inventory)` | `boolean` | Populates an inventory with items from a loot table using default item count (3-6). Returns `false` if the table does not exist. |
| `populateInventoryFromMerged(List<String> lootTableNames, Inventory inventory)` | `boolean` | Populates an inventory by merging multiple loot tables. Uses default item count (3-6). |
| `populateInventoryFromMerged(List<String> lootTableNames, Inventory inventory, int minItems, int maxItems)` | `boolean` | Populates an inventory by merging multiple loot tables with custom item count bounds. |
| `getRandomItem(String lootTableName)` | `ItemStack` | Returns a single random item from the specified loot table, or `null` if not found. |
| `getRandomItems(String lootTableName, int count)` | `List<ItemStack>` | Returns multiple random items from the specified loot table. |
---
## ILootTableManager
Advanced loot table management interface. Access via `IChestAPI.getLootTableManager()`.
| Method | Return Type | Description |
|---|---|---|
| `createLootTable(String id)` | `boolean` | Creates a new loot table. Returns `false` if it already exists. |
| `createLootTable(String id, String name)` | `boolean` | Creates a new loot table with a display name. |
| `deleteLootTableById(String id)` | `boolean` | Deletes a loot table by ID. |
| `addItemToLootTable(String id, ItemStack item, int weight)` | `boolean` | Adds a weighted item to a loot table. Automatically saved to disk. |
| `removeItemFromLootTable(String lootTableName, int index)` | `boolean` | Removes an item from a loot table by index. Automatically saved to disk. |
| `getLootTableItems(String id)` | `List<ILootTableItem>` | Returns all items in a loot table, or `null` if not found. |
| `getLootTableItemCount(String id)` | `int` | Returns the item count, or `-1` if the table does not exist. |
| `mergeLootTables(List<String> lootTableIds)` | `ILootTable` | Creates a temporary merged loot table from multiple tables. |
| `saveLootTable(String id)` | `boolean` | Persists a loot table to disk. |
| `loadLootTable(String id)` | `boolean` | Loads a loot table from disk. |
| `getAvailableLootTables()` | `Set<String>` | Returns all available loot table IDs. |
| `lootTableExists(String id)` | `boolean` | Checks if a loot table exists. |
| `populateInventory(String id, Inventory inventory)` | `boolean` | Populates an inventory with default item count (3-6). |
| `populateInventory(String id, Inventory inventory, int minItems, int maxItems)` | `boolean` | Populates an inventory with custom item count bounds. |
| `serializeItemStack(ItemStack item)` | `String` | Serializes an `ItemStack` to a string. |
| `deserializeItemStack(String data)` | `ItemStack` | Deserializes a string to an `ItemStack`. Supports base64, YAML, and `material;amount` formats. |
| `getLootTableById(String id)` | `ILootTable` | Returns the loot table instance, or `null`. |
| `reload()` | `void` | Reloads all loot tables from disk. |
---
## ILootTable
Represents a single loot table containing weighted items.
| Method | Return Type | Description |
|---|---|---|
| `getName()` | `String` | Returns the display name of the loot table. |
| `getId()` | `String` | Returns the unique identifier of the loot table. |
| `getItems()` | `List<ILootTableItem>` | Returns all items in this table. |
| `addItem(ItemStack item, int weight)` | `void` | Adds an item with the specified weight. |
| `addItem(ILootTableItem item)` | `void` | Adds a pre-built loot table item. |
| `populate(Inventory inventory, int min, int max)` | `void` | Populates an inventory with a random number of items between `min` and `max`. |
| `getRandomItem()` | `ItemStack` | Returns a single random item based on weight, or `null` if empty. |
| `getRandomItems(int count)` | `List<ItemStack>` | Returns multiple random items. |
| `merge(ILootTable other)` | `void` | Merges another loot table into this one. |
| `getIcon()` | `Material` | Returns the icon material for GUI display. |
| `getMergedTables()` | `List<ILootTable>` | Returns all tables merged into this one. |
| `setName(String name)` | `void` | Sets the display name. |
| `setIcon(Material icon)` | `void` | Sets the icon material. |
---
## ILootTableItem
Represents a single weighted item entry in a loot table.
| Method | Return Type | Description |
|---|---|---|
| `getItem()` | `ItemStack` | Returns the item. |
| `getWeight()` | `int` | Returns the weight (higher weight = more likely to be selected). |
| `setWeight(int weight)` | `void` | Sets the weight value. |
---
## Related Pages
- [[Chest/Developers/Overview]] — Developer overview and quick start
- [[Lead/Server Owners/Overview]] — Plugin overview and installation