Networking
The network API observes metadata of serialized Bedrock packets: type, direction, size and context. It does not decode gameplay fields, and it does not modify, cancel or send packets.
package dev.example;
import dev.zernyth.api.event.EventPriority;
import dev.zernyth.api.network.PacketFilter;
import dev.zernyth.api.plugin.JavaPlugin;
public final class PacketsPlugin extends JavaPlugin {
@Override
public void onEnable() {
var network = getServer().getNetworkManager();
getLogger().info("Protocol " + network.getProtocol().protocolVersion());
network.listen(PacketFilter.all(), EventPriority.MONITOR, packet ->
getLogger().fine(packet.type().name() + " " + packet.direction() + " " + packet.payloadSize()));
}
}Compatibility
The metadata adapter requires the reported release and protocol it was built for. Other values disable the capability and stop registration and callbacks. Check getCapabilities(). Registering with an incompatible protocol or filter throws UnsupportedPacketException.
Listeners are synchronous, so keep them fast. getMetrics() returns delivery and error counters.