ModsJava
[API] PacketListenerAPI
Java mod listed for Minecraft 1.16–1.17. Download on the author's site.
⬇ Download on SpigotThis 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
Modifying Field values
Maven
https://jitpack.io/#org.inventivetalent/packetlistenerapi
APIManager
This API is compatible with APIManger.
Click here for information on how to implement it.
Links
Versions after 3.8 require Java 11+
Code (Text):
PacketListenerAPI.addPacketHandler(new PacketHandler() {
@Override
public void onSend(SentPacket packet) {
}
@Override
public void onReceive(ReceivedPacket packet) {
}
});
If you are interested in manipulating packets directly on your BungeeCord server, check out the BungeeCord version of this API.
Examples
Checking a Packet
Spoiler: 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 ) {
}
} ) ;
Code (Java):
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)
Code (Java):
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 ) {
}
} ) ;
Spoiler: Old version
1.) Not version save
2.) version save (recommended)
Code (Text):
@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.
}
}
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.
}
}
Code (Text):
@EventHandler
public void onPacketSend(PacketSendEvent e) {
if(e.getPacketName().equals("PacketPlayOutSpawnEntity")) {
// Currently spawning an entity.
}
}
public void onPacketSend(PacketSendEvent e) {
if(e.getPacketName().equals("PacketPlayOutSpawnEntity")) {
// Currently spawning an entity.
}
}
Modifying Field values
Spoiler: 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 ) {
}
} ) ;
Code (Java):
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 ) {
}
} ) ;
Spoiler: Old version
1.) version save
Code (Text):
@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
}
}
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
Code (Text):
<dependency>
<groupId>org.inventivetalent.packetlistenerapi</groupId>
<artifactId>api</artifactId>
<version>VERSION-SNAPSHOT</version>
</dependency>
<groupId>org.inventivetalent.packetlistenerapi</groupId>
<artifactId>api</artifactId>
<version>VERSION-SNAPSHOT</version>
</dependency>
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.
Donations to support me or this resource are also very much appreciated.
Quick facts
- Edition: Minecraft Java
- File type: .jar
- Minecraft versions listed: 1.16, 1.17
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.
[API] PacketListenerAPI is a free Minecraft Java mod. Compatible with Minecraft 1.16, 1.17. Downloaded 160,943 times (via Spigot). Download it and open it directly in the game.