Source: https://www.spigotmc.org/resources/api-packetlistenerapi.2930/
- Donation Link:
- https://www.patreon.com/inventivetalent
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.
@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
@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)
@Override
public void onSend(SentPacket packet) {
if (packet.getPacketName().equals(“PacketPlayOutSpawnEntity”)) {
// Currently spawning an entity.
}
}
@Override
public void onReceive(ReceivedPacket packet) {
}
});
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)
public void onPacketSend(PacketSendEvent e) {
if(e.getPacketName().equals(“PacketPlayOutSpawnEntity”)) {
// Currently spawning an entity.
}
}
Modifying Field values
@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) {
}
});
APIManager
This API is compatible with APIManger.
Click here for information on how to implement it.
Links
Donations to support me or this resource are also very much appreciated.