ProtocolLib

Services.get("ProtocolLib")

Overview

API Reference

registerListener()

ProtocolLib.registerListener(priority, handler, packetTypes)

Registers a new packet listener.

  • priority: "LOW", "NORMAL", "HIGH", or "MONITOR"

  • handler: JavaScript object containing onSend(event) and/or onReceive(event)

  • packetTypes: Array of packet names, e.g., "Play.Server.BLOCK_CHANGE"

Returns: a listener object

const ProtocolLib = Services.get("ProtocolLib")
const listener = ProtocolLib.registerListener("NORMAL", {
  onSend(event) {
    const packet = event.getPacket();
    // handle packet here
  }
}, ["Play.Server.BLOCK_CHANGE"]);

Additional info on packetTypes:

The packetType is specified relative to the com.comphenix.protocol.PacketType class. For example, Play.Server.BLOCK_CHANGE corresponds to com.comphenix.protocol.PacketType.Play.Server.BLOCK_CHANGE. All provided packet types follow this structure and are based on their original class path.


unregisterListener()

ProtocolLib.unregisterListener(listener)

Unregisters a previously registered packet listener.


Packet Event Object

The event passed into your handler (onSend / onReceive) provides access to:

Method
Description

getPacket()

Returns the actual ProtocolLib packet

getPacketType()

Returns packet type as enum (e.g. Play.Server.CHAT)

You can use:

  • read(index) / write(index, value) to access fields

  • Packet-specific methods like getBlockData() or getBlockDataArrays()


Example Script: Block Spoofing

This script replaces all changing blocks with a spoofed OAK_LOG block:


Best Practices

  • Unregister unused listeners with ProtocolLib.unregisterListener(...)

  • Avoid modifying packets in "MONITOR" priority (read-only phase)

  • Use getMethod() and invoke() carefully for wrapper class access

Last updated

Was this helpful?