ProtocolLib 2.5.0

Details

  • Filename
    ProtocolLib-2.5.0.jar
  • Uploaded by
  • Uploaded
    Jul 22, 2013
  • Size
    946.85 KB
  • Downloads
    12,441
  • MD5
    5babd0f14baa86cbb966fb508de3f36d

Supported Bukkit Versions

  • 1.6.2
  • 1.5.2
  • 1.2.5

Changelog

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