ProtocolLib

ProtocolLib 2.5.0

Change log

Build: #111

This update contains a number of new exciting features for plugin developers, including a PacketAdapter builder and the ability to read and write a raw packet data to the connected client. I've described them in more detailed here, but I'll attach a few code examples nevertheless.

First, the new PacketAdapter builder allows packet listeners to be constructed without having to deal with the tens of different PacketAdapter constructor (which seems to often fail in Eclipse):

ProtocolLibrary.getProtocolManager().addPacketListener(
  new PacketAdapter(PacketAdapter.params(this, Packets.Client.CHAT).
                    clientSide()) {
    @Override
    public void onPacketReceiving(PacketEvent event) {
        System.out.println(
            "Intercepted message: " + 
            event.getPacket().getStrings().read(0));
    }
});

Next, I've added the ability to read the raw incoming packet data as a DataInputStream or ByteBuffer:

ProtocolLibrary.getProtocolManager().addPacketListener(
  new PacketAdapter(PacketAdapter.params(this, 
    Packets.Client.SET_CREATIVE_SLOT).clientSide().optionIntercept()) {
    
    @Override
    public void onPacketReceiving(PacketEvent event) {
        DataInputStream input = event.getNetworkMarker().getInputStream();
     
        // Can occur if the packet is "sent" by a plugin using 
        // recieveClientPacket
        if (input == null)
            return;
     
        try {
        // Read slot
            int slot = input.readShort();
            ItemStack stack = event.getNetworkMarker().getSerializer().
                deserializeItemStack(input);
     
            // Do something
     
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
});

This should come in handy if CraftBukkit removes or alters the packet while its being read, before ProtocolLib has a chance to invoke the packet events. In fact, this is already necessary if you need unfettered access to an ItemStack sent by the client, as CraftBukkit will scrub it for any unknown NBT tags and unimplemented features (attributes).

You can also alter how the packet should be written and sent to the network stream.

Change log

Features

API

Compatibility

Bug fixes

Small fixes

Facts

Uploaded on
Jul 22, 2013
Game version
  • 1.6.2
  • 1.5.2
  • 1.2.5
Filename
ProtocolLib-2.5.0.jar
Size
946.8 KiB
MD5
5babd0f14baa86cbb966fb508de3f36d
Type
Release
Status
Semi-normal
Downloads
11,335

Authors