Skip to content
ZERNYTH.

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.
  • null means an empty slot.
  • Amounts range from 1 to the item's native limit, and air is rejected as an item.
  • addItems and removeItems return 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.
  • equals includes the amount. isSimilar compares type, data and metadata.

ItemStack.read and write are an internal transport format, not a storage format.

Was this page helpful?