{"id":15142881,"url":"https://github.com/muqsit/invmenu","last_synced_at":"2026-02-19T10:10:36.520Z","repository":{"id":28956136,"uuid":"119814237","full_name":"Muqsit/InvMenu","owner":"Muqsit","description":"A PocketMine-MP virion to create and manage virtual inventories!","archived":false,"fork":false,"pushed_at":"2024-03-17T20:02:17.000Z","size":304,"stargazers_count":207,"open_issues_count":18,"forks_count":76,"subscribers_count":20,"default_branch":"pm5","last_synced_at":"2025-04-04T14:06:32.703Z","etag":null,"topics":["gui","inventory","pmmp","pocketmine","virion"],"latest_commit_sha":null,"homepage":"https://poggit.pmmp.io/ci/Muqsit/InvMenu/~","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Muqsit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-01T09:34:34.000Z","updated_at":"2025-03-28T02:00:31.000Z","dependencies_parsed_at":"2024-12-13T19:10:12.350Z","dependency_job_id":"bbe0dc9d-dde6-41b4-860b-a6e130ad64fe","html_url":"https://github.com/Muqsit/InvMenu","commit_stats":{"total_commits":197,"total_committers":12,"mean_commits":"16.416666666666668","dds":"0.30456852791878175","last_synced_commit":"cd268cb359f9953632c9f55649479f7ccb1a3bda"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2FInvMenu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2FInvMenu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2FInvMenu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2FInvMenu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Muqsit","download_url":"https://codeload.github.com/Muqsit/InvMenu/tar.gz/refs/heads/pm5","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190250,"owners_count":20898702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gui","inventory","pmmp","pocketmine","virion"],"created_at":"2024-09-26T10:00:48.380Z","updated_at":"2026-02-19T10:10:36.513Z","avatar_url":"https://github.com/Muqsit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# InvMenu\nCreate and manage virtual inventories in PocketMine-MP.\n\n## Installation and setup\nDownload the compiled .phar file from [Poggit CI](https://poggit.pmmp.io/ci/Muqsit/InvMenu/~) and place it in your `virions/` folder.\nRead [installation](https://github.com/Muqsit/InvMenu/wiki/Installation) and [using in a plugin](https://github.com/Muqsit/InvMenu/wiki/Using-InvMenu-in-a-plugin)\nfor a more elaborate guide on how to setup InvMenu library.\n\n\u003e [!NOTE]\n\u003e You must register `InvMenuHandler` before you can use InvMenu.\n\u003e ```php\n\u003e // in class MyPlugin extends PluginBase:\n\u003e protected function onEnable() : void{\n\u003e \tif(!InvMenuHandler::isRegistered()){\n\u003e \t\tInvMenuHandler::register($this);\n\u003e \t}\n\u003e }\n\n## Create a virtual inventory\nQuick start, use `InvMenu::create(InvMenu::TYPE_CHEST)-\u003esend($player);` to display a virtual chest inventory to a player.\n\n`InvMenu::create($identifier)` creates an InvMenu instance. `$identifier` may be an identifier of a registered `InvMenuType` object.\nInvMenu comes with 3 pre-registered inventory types of different sizes:\n- `InvMenu::TYPE_CHEST` - a 27-slot normal chest inventory\n- `InvMenu::TYPE_DOUBLE_CHEST` - a 54-slot double chest inventory\n- `InvMenu::TYPE_HOPPER` - a 5-slot hopper inventory\n\n```php\n$menu = InvMenu::create(InvMenu::TYPE_CHEST);\n$inventory = $menu-\u003egetInventory();\n```\n\nAs `$inventory` implements [PocketMine's Inventory interface](https://github.com/pmmp/PocketMine-MP/blob/stable/src/inventory/Inventory.php), you get to access all the fancy PocketMine inventory methods.\n```php\n$menu-\u003egetInventory()-\u003esetContents([\n\tVanillaItems::DIAMOND_SWORD(),\n\tVanillaItems::DIAMOND_PICKAXE()\n]);\n$menu-\u003egetInventory()-\u003eaddItem(VanillaItems::DIAMOND_AXE());\n$menu-\u003egetInventory()-\u003esetItem(3, VanillaItems::GOLD_INGOT());\n```\nTo send a menu to a player, use:\n```php\n/** @var Player $player */\n$menu-\u003esend($player);\n```\n\u003e [!TIP]\n\u003e One `InvMenu` can be sent to multiple players—even 2 players in different worlds, so everyone views and edits the same inventory as if it were one chest.\n\n\n## Set a custom name\nThere are two ways to name an InvMenu. You can either specify a global name (see method A), or you can set a name at the time you send the menu (see method B).\n```php\n$menu-\u003esetName(\"Custom Name\"); // method A\n$menu-\u003esend($player, \"Greetings, \" . $player-\u003egetName()); // method B\n```\n\n## Verify whether a menu is sent successfully\n`InvMenu::send()` is not guaranteed to succeed. A failure may arise from plugins cancelling InventoryOpenEvent, a disconnected player, or the player refusing the request (e.g., because they are in pause menu).\nUse the `$callback` parameter to verify whether a menu has been opened.\n```php\n$menu-\u003esend($player, callback: function(bool $success) : void{\n\tif($success){\n\t\t// player is viewing the menu\n\t}\n});\n```\n\n## Monitor movement of items\nInvMenu comes with a listener whereby developers can write logic to monitor movement of items in and out of inventory, and thereby take action.\nA listener is a callback with the following signature:\n```php\n/**\n * @param InvMenuTransaction $transaction\n *\n * Return $transaction-\u003econtinue() to continue the transaction.\n * Return $transaction-\u003ediscard() to cancel the transaction.\n * @return InvMenuTransactionResult\n */\nClosure(InvMenuTransaction $transaction) : InvMenuTransactionResult;\n```\n- `InvMenuTransaction::getPlayer()` returns the `Player` that triggered the transaction.\n- `InvMenuTransaction::getItemClicked()` returns the `Item` the player clicked in the menu. You may also use `InvMenuTransaction::getOut()`.\n- `InvMenuTransaction::getItemClickedWith()` returns the `Item` the player had in their hand when clicking an item. You may also use `InvMenuTransaction::getIn()`.\n- `InvMenuTransaction::getAction()` returns `SlotChangeAction` - you can get the slot that the player clicked in the menu.\n- `InvMenuTransaction::getTransaction()` returns the complete `InventoryTransaction` holding all the above information.\n```php\n$menu-\u003esetListener(function(InvMenuTransaction $transaction) : InvMenuTransactionResult{\n\t$player = $transaction-\u003egetPlayer();\n\t$itemClicked = $transaction-\u003egetItemClicked();\n\t$itemClickedWith = $transaction-\u003egetItemClickedWith();\n\t$action = $transaction-\u003egetAction();\n\t$txn = $transaction-\u003egetTransaction();\n\treturn $transaction-\u003econtinue();\n});\n```\nThe listener below does not allow players to take out apples from the menu:\n```php\n$menu-\u003esetListener(function(InvMenuTransaction $transaction) : InvMenuTransactionResult{\n\tif($transaction-\u003egetItemClicked()-\u003egetTypeId() === ItemTypeIds::APPLE){\n\t\t$player-\u003esendMessage(\"You cannot take apples out of that inventory.\");\n\t\treturn $transaction-\u003ediscard();\n\t}\n\treturn $transaction-\u003econtinue();\n});\n```\n\nThere are two methods you can use to prevent players from editing the menu. Either create a listener that `discard()`s\nthe transaction, or use `InvMenu::readonly()`.\n```php\n$menu-\u003esetListener(function(InvMenuTransaction $transaction) : InvMenuTransactionResult{\n\treturn $transaction-\u003ediscard();\n});\n\n$menu-\u003esetListener(InvMenu::readonly()); // equivalent shorthand of the above\n\n// you can also pass a callback in InvMenu::readonly()\n$menu-\u003esetListener(InvMenu::readonly(function(DeterministicInvMenuTransaction $transaction) : void{\n\t// do something\n}));\n```\nAlternatively, you may choose to write your own `InventoryTransactionEvent` listener that works on transactions on\n`$menu-\u003egetInventory()`. However, an InvMenu listener is enough to fulfil most tasks.\n\n## Execute a task post-transaction\nFew actions are not possible to invoke at the time a player is viewing an inventory, such as sending a form—a player\ncannot view a form while viewing an inventory. Close the menu and utilize `InvMenuTransactionResult::then()` callback to\nachieve this.\n```php\n$menu-\u003esetListener(function(InvMenuTransaction $transaction) : InvMenuTransactionResult{\n\t$transaction-\u003egetPlayer()-\u003eremoveCurrentWindow();\n\treturn $transaction-\u003ediscard()-\u003ethen(function(Player $player) : void{\n\t\t$player-\u003esendForm(new Form());\n\t});\n});\n\n// or if you are using InvMenu::readonly():\n$menu-\u003esetListener(InvMenu::readonly(function(DeterministicInvMenuTransaction $transaction) : void{\n\t$transaction-\u003egetPlayer()-\u003eremoveCurrentWindow();\n\t$transaction-\u003ethen(function(Player $player) : void{\n\t\t$player-\u003esendForm(new Form());\n\t});\n}));\n```\n\n## Monitor menu close events\nRegister an inventory close callback to run whenever a player closes the menu. An inventory close callback takes the\nfollowing signature:\n```php\n/**\n * @param Player $player the player that closed the menu\n * @param Inventory $inventory the inventory of the menu\n */\nClosure(Player $player, Inventory $inventory) : void;\n```\n```php\n$menu-\u003esetInventoryCloseListener(function(Player $player, Inventory $inventory) : void{\n\t$player-\u003esendMessage(\"You are no longer viewing the menu.\");\n});\n```\nInventory close listener is fired during both—server-initiated requests (i.e., `$player-\u003eremoveCurrentWindow()`) and\nwhen the player closes the inventory on their end.\n\n## Advanced usage: Register a custom InvMenuType\n\u003e [!IMPORTANT]\n\u003e PocketMine does not register a dispenser block. As of PocketMine v5, the task of registering missing vanilla blocks is\n\u003e excessively laborious and hence beyond the scope of this guide. [pmmp/RegisterBlocksDemoPM5](https://github.com/pmmp/RegisterBlocksDemoPM5)\n\u003e has a nice guide on how to achieve this. **Still overwhelmed?** I wrote a [drag-n-drop example plugin](https://gist.github.com/Muqsit/8884e0f75b317c332a56e01740bbfe98)\n\u003e that does all of it and registers a `/dispenser` command. With DevTools plugin installed, simply copy the code and\n\u003e paste it in a new \"DispenserInvMenuPlugin.php\" file in your server's plugin folder.\n\nInvMenu does not provide a 9-slot dispenser inventory. But you can still achieve this by registering a dispenser InvMenuType.\nYou'll need to specify inventory size, block actor identifier (tile identifier), and the window type (network property) for\nthe creation of the graphic (block) and inventory parts.\n```php\npublic const TYPE_DISPENSER = \"myplugin:dispenser\";\n\nprotected function onEnable() : void{\n\tInvMenuHandler::getTypeRegistry()-\u003eregister(self::TYPE_DISPENSER, InvMenuTypeBuilders::BLOCK_ACTOR_FIXED()\n\t\t-\u003esetBlock(ExtraVanillaBlocks::DISPENSER())\n\t\t-\u003esetSize(9)\n\t\t-\u003esetBlockActorId(\"Dispenser\")\n\t\t-\u003esetNetworkWindowType(WindowTypes::DISPENSER)\n\t-\u003ebuild());\n}\n```\nSweet! Now you can create a dispenser menu using:\n```php\n$menu = InvMenu::create(self::TYPE_DISPENSER);\n```\n\n## InvMenu Wiki\nApplications, examples, tutorials and featured projects using InvMenu can be found on the [InvMenu Wiki](https://github.com/Muqsit/InvMenu/wiki/InvMenu-v4.0).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuqsit%2Finvmenu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuqsit%2Finvmenu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuqsit%2Finvmenu/lists"}