{"id":15680599,"url":"https://github.com/muqsit/invmenuutils","last_synced_at":"2025-07-14T05:33:29.289Z","repository":{"id":92516697,"uuid":"257571869","full_name":"Muqsit/InvMenuUtils","owner":"Muqsit","description":"A utility virion for InvMenu implementing some commonly used procedures","archived":false,"fork":false,"pushed_at":"2020-04-21T12:04:49.000Z","size":9,"stargazers_count":17,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T11:16:54.230Z","etag":null,"topics":["gui","inventory","pmmp","pocketmine","virion"],"latest_commit_sha":null,"homepage":"https://poggit.pmmp.io/ci/Muqsit/InvMenuUtils","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"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":null,"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,"zenodo":null}},"created_at":"2020-04-21T11:21:47.000Z","updated_at":"2023-08-13T11:15:45.000Z","dependencies_parsed_at":"2023-03-13T17:28:29.284Z","dependency_job_id":null,"html_url":"https://github.com/Muqsit/InvMenuUtils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Muqsit/InvMenuUtils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2FInvMenuUtils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2FInvMenuUtils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2FInvMenuUtils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2FInvMenuUtils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Muqsit","download_url":"https://codeload.github.com/Muqsit/InvMenuUtils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2FInvMenuUtils/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265245965,"owners_count":23734108,"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-10-03T16:43:21.996Z","updated_at":"2025-07-14T05:33:29.240Z","avatar_url":"https://github.com/Muqsit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# InvMenuUtils\nA utility virion for the [InvMenu](https://github.com/Muqsit/InvMenu) virion implementing some commonly used procedures.\n\n## Assigning multiple listeners to one `InvMenu`\nMultiple listeners have different behaviour for readonly and non-readonly InvMenu instances.\nFor non-readonly InvMenu instances, listeners are prioritised in the order they were passed to the `InvMenuListenerUtils::multiple()` method.\nA listener will not be executed if the previous listener cancelled the transaction (i.e returned false).\n```php\n$menu = InvMenu::create(InvMenu::TYPE_CHEST);\n$menu-\u003esetListener(InvMenuListenerUtils::multiple(\n\t$menu,\n\tfunction(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : bool{\n\t\techo \"This listener is called first\" . PHP_EOL;\n\t\treturn true;\n\t},\n\tfunction(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : bool{\n\t\techo \"This listener is called second.\" . PHP_EOL;\n\t\treturn false;\n\t},\n\tfunction(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : bool{\n\t\t// This listener is not called as the previous listener cancelled the transaction\n\t\t// by returning false.\n\t\treturn true;\n\t}\n));\n```\nFor readonly InvMenu instances, all listeners will be executed as the transaction is anyway forcefully cancelled.\n```php\n\n$menu = InvMenu::create(InvMenu::TYPE_CHEST);\n$menu-\u003ereadonly();\n$menu-\u003esetListener(InvMenuListenerUtils::multiple(\n\t$menu,\n\tfunction(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : void{\n\t\techo \"This listener is called first\" . PHP_EOL;\n\t},\n\tfunction(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : void{\n\t\techo \"This listener is called second.\" . PHP_EOL;\n\t},\n\tfunction(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : void{\n\t\techo \"This listener is called third.\" . PHP_EOL;\n\t}\n));\n```\n\n## Assigning slot-specific listeners to an `InvMenu`\nListen or handle specific slots, or handle each slot separately.\u003cbr\u003e\nIndex your listeners to the slot you'd like the listener to handle/listen.\u003cbr\u003e\nTIP: Use index `-1` to \"catch-all\" (fallback).\n```php\n$menu-\u003esetListener(InvMenuListenerUtils::slotSpecific($menu, [\n\t8 =\u003e function(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : bool{\n\t\t$player-\u003esendMessage(\"You clicked slot #8\");\n\t\treturn true;\n\t},\n\t16 =\u003e function(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : bool{\n\t\t$player-\u003esendMessage(\"You clicked slot #16\");\n\t\treturn true;\n\t},\n\t-1 =\u003e function(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : bool{\n\t\t$player-\u003esendMessage(\"Fallback: You clicked slot #\" . $action-\u003egetSlot());\n\t\treturn true;\n\t}\n]));\n```\n\n## Blacklisting specific slots\n**NOTE:** This method is applicable ONLY to non-readonly InvMenu instances.\u003cbr\u003e\nBlacklisting an array of slots disallows players from modify those slots.\n```php\n$menu = InvMenu::create(InvMenu::TYPE_CHEST);\n$menu-\u003esetListener(InvMenuListenerUtils::blacklistSlots([0, 4, 8]));\n```\nYou can even use this in combination with `InvMenuListenerUtils::multiple()`.\n```php\n$menu = InvMenu::create(InvMenu::TYPE_CHEST);\n$menu-\u003esetListener(InvMenuListenerUtils::multiple(\n\t$menu,\n\tInvMenuListenerUtils::blacklistSlots([0, 1, 2]),\n\tfunction(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : bool{\n\t\t$player-\u003esendMessage(\"You didn't click any of these slots: 0, 1, 2\");\n\t\treturn true;\n\t}\n));\n```\n\n## Whitelisting specific slots\n**NOTE:** This method is applicable ONLY to non-readonly InvMenu instances.\u003cbr\u003e\nWhitelisting an array of slots allows players to modify ONLY those slots.\n```php\n$menu = InvMenu::create(InvMenu::TYPE_CHEST);\n$menu-\u003esetListener(InvMenuListenerUtils::whitelistSlots([0, 4, 8]));\n```\nSimilar to `InvMenuListenerUtils::blacklistSlots()`, you can use this in combination with `InvMenuListenerUtils::multiple()`.\n```php\n$menu = InvMenu::create(InvMenu::TYPE_CHEST);\n$menu-\u003esetListener(InvMenuListenerUtils::multiple(\n\t$menu,\n\tInvMenuListenerUtils::whitelistSlots([0, 1, 2]),\n\tfunction(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : bool{\n\t\t$player-\u003esendMessage(\"You click one of these slots: 0, 1, 2\");\n\t\treturn true;\n\t}\n));\n```\n\n## Filtering items with specific NBT tags\n**NOTE:** This method is applicable ONLY to non-readonly InvMenu instances.\u003cbr\u003e\nFilter items only with a specific NBT tag on them to allow players to take those items out of the inventory.\n```php\n$menu-\u003esetListener(InvMenuListenerUtils::onlyItemsWithTag(\"CustomItem\", StringTag::class));\n```\nFilter items only without a specific NBT tag on them to allow players to take those items out of the inventory.\n```php\n$menu-\u003esetListener(InvMenuListenerUtils::onlyItemsWithoutTag(\"Button\", ByteTag::class));\n```\nSimilar to `InvMenuListenerUtils::whitelistSlots()` and `InvMenuListenerUtils::blacklistSlots()`, this can be used in combination with `InvMenuListenerUtils::multiple()`.\n```php\n$menu-\u003esetListener(InvMenuListenerUtils::multiple(\n\t$menu,\n\tInvMenuListenerUtils::onlyItemsWithTag(\"Button\", ByteTag::class),\n\tfunction(Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) : bool{\n\t\t$player-\u003esendMessage(\"You clicked a button!\");\n\t\treturn false;\n\t}\n));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuqsit%2Finvmenuutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuqsit%2Finvmenuutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuqsit%2Finvmenuutils/lists"}