Inventory API
Players expose getInventory() and getEnderChest(). Items are immutable ItemStack values created through the server.
package dev.example;
import dev.zernyth.api.player.Player;
import dev.zernyth.api.plugin.JavaPlugin;
import java.util.List;
public final class ItemsPlugin extends JavaPlugin {
void reward(Player player) {
var item = getServer().createItemStack("minecraft:diamond", 3);
var named = item.withItemMeta(item.getItemMeta().withDisplayName("Reward"));
var leftover = player.getInventory().addItems(List.of(named));
if (!leftover.isEmpty()) player.sendMessage("Inventory full");
}
}Rules
- Only the player inventory and the Ender Chest are supported. Custom containers and armor or offhand slots are not.
nullmeans an empty slot.- Amounts range from 1 to the item's native limit, and air is rejected as an item.
addItemsandremoveItemsreturn what could not be processed, keyed by input index.- All items of a batch are validated first. A later native failure is not rolled back as a transaction.
equalsincludes the amount.isSimilarcompares type, data and metadata.
ItemStack.read and write are an internal transport format, not a storage format.