Sueta
[A

[API] PacketListenerAPI

3.9.10-SNAPSHOT

Simple API to manipulate sent and received packets | compatible with all versions

·Plugin

This API provides an easy way to listen for when a Packet is sent or received and includes functions to modify Fields of the Packet.

Versions after 3.8 require Java 11+

PacketListenerAPI.addPacketHandler(new PacketHandler() {

            @Override
            public void onSend(SentPacket packet) {
            }

            @Override
            public void onReceive(ReceivedPacket packet) {
            }

        });

The processed packets can also be limited by adding the @PacketOptions annotation.

If you are interested in manipulating packets directly on your BungeeCord server, check out the BungeeCord version of this API.

Examples

Checking a Packet

Checking packet for Entity spawn

1.) Not version save

PacketListenerAPI.addPacketHandler(new PacketHandler() {

            @Override
            public void onSend(SentPacket packet) {
                if (packet.getPacket() instanceof PacketPlayOutSpawnEntity) {// instanceof requires an import of the Packet, therefore not Version save
                    // Currently spawning an entity.
                }
            }

            @Override
            public void onReceive(ReceivedPacket packet) {
            }

        });

2.) version save (recommended)

PacketListenerAPI.addPacketHandler(new PacketHandler() {

            @Override
            public void onSend(SentPacket packet) {
                if (packet.getPacketName().equals("PacketPlayOutSpawnEntity")) {
                    // Currently spawning an entity.
                }
            }

            @Override
            public void onReceive(ReceivedPacket packet) {
            }

        });
Old version

1.) Not version save

@EventHandler
    public void onPacketSend(PacketSendEvent e) {
        if (e.getPacket() instanceof PacketPlayOutSpawnEntity) {// instanceof requires an import of the Packet, therefore not Version save
            // Currently spawning an entity.
        }
    }

2.) version save (recommended)

@EventHandler
    public void onPacketSend(PacketSendEvent e) {
        if(e.getPacketName().equals("PacketPlayOutSpawnEntity")) {
            // Currently spawning an entity.
        }
    }

Modifying Field values

Modify the Entity-Type of an Entity-spawn packet
PacketListenerAPI.addPacketHandler(new PacketHandler() {

            @Override
            public void onSend(SentPacket packet) {
                if(packet.getPacketName().equals("PacketPlayOutSpawnEntity")) {
                    packet.setPacketValue("f", <EntityID>);//f is the Field in the packet which defines the Entity-type as an Integer
                }
            }

            @Override
            public void onReceive(ReceivedPacket packet) {
            }

        });
Old version

1.) version save

@EventHandler
    public void onPacketSend(PacketSendEvent e) {
        if(e.getPacketName().equals("PacketPlayOutSpawnEntity")) {
            e.setPacketValue("f", <EntityID>);//f is the Field in the packet which defines the Entity-type as an Integer
        }
    }

Maven

<dependency>
        <groupId>org.inventivetalent.packetlistenerapi</groupId>
        <artifactId>api</artifactId>
        <version>VERSION-SNAPSHOT</version>
    </dependency>

https://jitpack.io/#org.inventivetalent/packetlistenerapi

APIManager
This API is compatible with APIManger.
Click here for information on how to implement it.

Links

Please leave a rating if you like this resource.
Donations to support me or this resource are also very much appreciated.

Similar projects

Plugin →