Uses:
use refaltor\inventoryapi\inventories\{SimpleChestInventory, DoubleInventory};
Create Simple Inventory:
$simpleInventory = InventoryAPI::createSimpleChest(isViewOnly: false);
$simpleInventory->setName('SimpleInventory');
$simpleInventory->setContents([
VanillaItems::GOLD_INGOT(),
VanillaItems::STEAK()
]);
$simpleInventory->setClickListener(function (Player $player, BaseInventoryCustom $inventory, Item $sourceItem, Item $targetItem, int $slot): void {
if ($slot === 0) {
$inventory->transactionCancel();
} else {
$inventory->addItem(VanillaItems::COAL()->setCustomName("Example"));
}
});
$simpleInventory->setCloseListener(function (Player $player, BaseInventoryCustom $inventory): void {
Server::getInstance()->broadcastMessage("Hello close chest !");
});
$simpleInventory->send($player);
Create Double Chest Inventory:
$doubleChestInventory = InventoryAPI::createDoubleChest(isViewOnly: false);
$doubleChestInventory->setName('DoubleChestInventory');
$doubleChestInventory->setContents([
VanillaItems::GOLD_INGOT(),
VanillaItems::STEAK()
]);
$doubleChestInventory->setClickListener(function (Player $player, BaseInventoryCustom $inventory, Item $sourceItem, Item $targetItem, int $slot): void {
if ($slot === 0) {
$inventory->transactionCancel();
} else {
$inventory->addItem(VanillaItems::COAL()->setCustomName("Example"));
}
});
$doubleChestInventory->setCloseListener(function (Player $player, BaseInventoryCustom $inventory): void {
Server::getInstance()->broadcastMessage("Hello close chest !");
});
$doubleChestInventory->send($player);