{"id":29080851,"url":"https://github.com/imperazim/libpacket","last_synced_at":"2025-06-27T18:38:17.200Z","repository":{"id":300895685,"uuid":"1007042172","full_name":"ImperaZim/LibPacket","owner":"ImperaZim","description":"Packet handler library for PocketMine (Minecraft PE)","archived":false,"fork":false,"pushed_at":"2025-06-24T05:47:26.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"stable","last_synced_at":"2025-06-24T06:31:43.701Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/ImperaZim.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":"2025-06-23T11:25:55.000Z","updated_at":"2025-06-24T05:47:29.000Z","dependencies_parsed_at":"2025-06-24T06:31:47.138Z","dependency_job_id":"7394fe29-e00f-4faf-93cb-0ea4a10f1d1b","html_url":"https://github.com/ImperaZim/LibPacket","commit_stats":null,"previous_names":["imperazim/libpacket"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ImperaZim/LibPacket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ImperaZim%2FLibPacket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ImperaZim%2FLibPacket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ImperaZim%2FLibPacket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ImperaZim%2FLibPacket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ImperaZim","download_url":"https://codeload.github.com/ImperaZim/LibPacket/tar.gz/refs/heads/stable","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ImperaZim%2FLibPacket/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262313853,"owners_count":23292216,"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":[],"created_at":"2025-06-27T18:38:13.862Z","updated_at":"2025-06-27T18:38:17.191Z","avatar_url":"https://github.com/ImperaZim.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LibPacket\n\nLibPacket is a PHP library for PocketMine-MP that simplifies packet handling by letting you register specific handlers instead of writing long `if ($packet instanceof …)` chains.  In other words, it helps “put an end to the if-elseif instanceof hell”.  It provides a clean API to handle data packets per network session.\n\n## Project Description\n\n* **Packet Monitor:** Use this if you want to *observe* packet events without changing them.  A Packet Monitor registers callbacks for `DataPacketReceiveEvent`/`DataPacketSendEvent` at the `MONITOR` priority, which by convention means your code should not alter the packet.  This is useful for logging or debugging packets (e.g. dumping packet contents or tracking packet flow).\n* **Packet Interceptor:** Use this to *handle and possibly modify* packets before they reach the rest of the system.  Interceptors register callbacks at a lower priority (by default `NORMAL`).  In an interceptor you can cancel a packet or change its data (for example, blocking certain packet types or injecting new data) before PocketMine processes it.\n\nThese components let your plugin focus on relevant packets and actions, without needing manual `instanceof` checks for each packet type.\n\n## Installation\n\nNo special installation steps or dependencies are required.  Simply include or autoload LibPacket in your plugin (for example via Composer or by placing the files in your plugin folder).  LibPacket works out of the box with PocketMine-MP plugins.\n\n## Usage\n\nUse `LibPacket::createMonitor($plugin)` or `LibPacket::createInterceptor($plugin)` to create the respective component, then register your handlers.  For example, to intercept `AvailableCommandsPacket` you could write:\n\n```php\n$interceptor = LibPacket::createInterceptor($this);\n$interceptor-\u003eregisterIncoming(new LibCommandInterceptor());\n```\n\nThen implement the handler class. Here’s an example of a `LibCommandInterceptor` that implements `PacketHandlerInterface` to process the `AvailableCommandsPacket`:\n\n```php\nclass LibCommandInterceptor implements \\imperazim\\packet\\handler\\PacketHandlerInterface {\n    public function getPacketIds(): array {\n        // Specify which packet types this handler should receive\n        return [\\pocketmine\\network\\mcpe\\protocol\\AvailableCommandsPacket::class];\n    }\n\n    public function handle($packet, $session): bool {\n        if ($packet instanceof \\pocketmine\\network\\mcpe\\protocol\\AvailableCommandsPacket) {\n            // Manipulate the packet’s data here (e.g. filter out commands).\n        }\n        // Return true to allow the packet, or false to cancel it.\n        return true;\n    }\n}\n```\n\nIn this example, `getPacketIds()` tells LibPacket which packet classes to listen for.  The `handle()` method will be called for each matching packet: if you return `false`, the packet event is canceled (preventing PocketMine from processing it), and if you return `true`, PocketMine will continue as normal.  This makes it easy to modify or block packets on the fly (for instance, to remove commands or change packet flags).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimperazim%2Flibpacket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimperazim%2Flibpacket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimperazim%2Flibpacket/lists"}