{"id":19013111,"url":"https://github.com/vectrix-space/protocolcontrol","last_synced_at":"2025-04-23T00:10:26.180Z","repository":{"id":40549485,"uuid":"275995637","full_name":"vectrix-space/protocolcontrol","owner":"vectrix-space","description":"Protocol Control - A minimal packet manipulation library for Sponge.","archived":false,"fork":false,"pushed_at":"2022-05-03T05:19:16.000Z","size":251,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-17T16:04:45.833Z","etag":null,"topics":["java","minecraft-protocol","sponge-plugin"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vectrix-space.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-30T04:19:39.000Z","updated_at":"2022-06-20T10:09:00.000Z","dependencies_parsed_at":"2022-08-09T22:51:01.513Z","dependency_job_id":null,"html_url":"https://github.com/vectrix-space/protocolcontrol","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vectrix-space%2Fprotocolcontrol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vectrix-space%2Fprotocolcontrol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vectrix-space%2Fprotocolcontrol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vectrix-space%2Fprotocolcontrol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vectrix-space","download_url":"https://codeload.github.com/vectrix-space/protocolcontrol/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250343948,"owners_count":21415040,"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":["java","minecraft-protocol","sponge-plugin"],"created_at":"2024-11-08T19:21:56.156Z","updated_at":"2025-04-23T00:10:26.154Z","avatar_url":"https://github.com/vectrix-space.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Protocol Control\n================\n\n**Under development and not stable!**\n\nA minimal packet manipulation library for Sponge.\n\n## Prerequisites\n* [Java] 8\n\n## Building\n__Note:__ If you do not have [Gradle] installed then use ./gradlew for Unix systems or Git Bash and gradlew.bat for Windows systems in place of any 'gradle' command.\n\nIn order to build ProtocolControl you simply need to run the `gradle` command. You can find the compiled JAR file in `./build/libs` labeled similarly to 'protocolcontrol-x.x.x-SNAPSHOT.jar'.\n\n## Dependency\nUsing `ProtocolControl` in your plugin requires you to use ForgeGradle and add `ProtocolControl` as a compile-time dependency.\n\n```gradle\nrepositories {\n  maven { url \"https://repo.ichorpowered.com/repository/maven-public\" }\n}\n\ndependencies {\n  compile \"com.ichorpowered:protocolcontrol:0.0.2\"\n}\n```\n\n## Usage\nTo get started, you will need to get the instance of the `ProtocolService` from the `ServiceManager`.\n\n```java\nOptional\u003cProtocolService\u003e protocolService = Sponge.getServiceManager().provide(ProtocolService.class);\n```\n\n### Creating a Listener\nTo create a packet listener, you need to add the `@Subscribe` annotation on your listener methods, with a parameter for `PacketEvent` with a generic argument of the `Packet\u003c?\u003e` type you are listening for.\n\n```java\n@Subscribe\npublic void onLoginEvent(PacketEvent\u003cSPacketLoginSuccess\u003e event) {\n  ...\n}\n```\n\nYou can register the listener by passing in the listener object to `ProtocolEvent#register`. You can also unregister the listener with `ProtocolEvent#unregister`.\n\nThe `ProtocolEvent` is acquired from `ProtocolService#events`.\n\n### Manipulating a Packet\nThe event has a method to get the `ChannelProfile` the packet is going to or coming from and the `PacketDirection`.\n\nYou have access to the original instance of the packet as well as a way to override the packet.\n\n```java\n@Subscribe\npublic void onLoginEvent(PacketEvent\u003cSPacketLoginSuccess\u003e event) {\n  SPacketLoginSuccess packet = event.packet(); // Gets the packet instance.\n  event.packet(...); // Override the packet instance.\n}\n```\n\nYou can also prevent a packet from reaching its destination by cancelling the event.\n\n```java\n@Subscribe\npublic void onLoginEvent(PacketEvent\u003cSPacketLoginSuccess\u003e event) {\n  if (!event.cancel()) event.cancel(true); // If the packet is not already cancelled, cancel it.\n}\n```\n\n### Wrapping a Packet\n`PacketRemapper` provides an optional wrapper for your packet, which provides methods to `get` and `set` the fields for a packet. This is particularly useful but not limited to packets that do not provide convenient getters or setters. You just need to know the field type and the index for the field of that type in order to use them.\n\n```java\n@Subscribe\npublic void onLoginEvent(PacketEvent\u003cSPacketLoginSuccess\u003e event) {\n  PacketRemapper.Wrapper\u003cSPacketLoginSuccess\u003e wrapper = this.remapper.wrap(event.packet());\n  GameProfile profile = wrapper.\u003cGameProfile\u003eget(GameProfile.class, 0); // Gets the game profile.\n  wrapper.\u003cGameProfile\u003eset(GameProfile.class, 0, ...); // Sets the game profile.\n}\n```\n\nThe `PacketRemapper` is acquired from `ProtocolService#remapper`.\n\n### Sending a Packet\nYou can send a new packet to the client or to the server using the `ChannelProfile#send` method. \n\n```java\n@Listener\npublic void onPlayerMove(final MoveEntityEvent event, final @First Player player) {\n  final Location\u003cWorld\u003e location = player.getLocation();\n  final ChannelProfile profile = this.protocolChannel.profile(player.getUniqueId());\n    \n  try {\n    final PacketRemapper.Wrapped\u003cSPacketBlockChange\u003e blockChange = this.remapper.wrap(new SPacketBlockChange());\n    blockChange.set(BlockPos.class, 0, new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()));\n    blockChange.set(IBlockState.class, 0, (IBlockState) BlockTypes.WATER.getDefaultState());\n\n    profile.send(PacketDirection.OUTGOING, blockChange.packet()); // Sends the block change packet to the client.\n  } catch(Throwable throwable) {\n    throwable.printStackTrace();\n  }\n}\n```\n\nThe `ProtocolChannel` is acquired from `ProtocolService#channels`. You can then grab the players `ChannelProfile` using `ProtocolChannel#profile`.\n\n[Gradle]: https://www.gradle.org/\n[Java]: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvectrix-space%2Fprotocolcontrol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvectrix-space%2Fprotocolcontrol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvectrix-space%2Fprotocolcontrol/lists"}