@Override public RecyclableCollection<PacketData> toData(ProtocolVersion version) { PacketData serializer = PacketData.create(ClientBoundPacket.PLAY_ENTITY_REL_MOVE_ID, version); serializer.writeInt(entityId); serializer.writeByte(relX); serializer.writeByte(relY); serializer.writeByte(relZ); return RecyclableSingletonList.create(serializer); }
@Override public RecyclableCollection<PacketData> toData(ProtocolVersion version) { PacketData serializer = PacketData.create(ClientBoundPacket.PLAY_SCOREBOARD_OBJECTIVE_ID, version); serializer.writeString(name); serializer.writeString(mode == 1 ? "" : value); serializer.writeByte(mode); return RecyclableSingletonList.create(serializer); }
@Override public void encode(ChannelHandlerContext ctx, Packet<PacketListener> packet, ByteBuf output) throws Exception { Channel channel = ctx.channel(); EnumProtocol currentProtocol = channel.attr(currentStateAttrKey).get(); final Integer packetId = currentProtocol.a(direction, packet); if (packetId == null) { throw new IOException("Can't serialize unregistered packet"); } ClientBoundMiddlePacket<RecyclableCollection<PacketData>> packetTransformer = dataRemapperRegistry.getTransformer(currentProtocol, packetId); if (packetTransformer != null) { serverdata.clear(); packet.b(serverdata); if (packetTransformer.needsPlayer()) { packetTransformer.setPlayer(ChannelUtils.getBukkitPlayer(channel)); } packetTransformer.readFromServerData(serverdata); packetTransformer.setLocalStorage(storage); packetTransformer.handle(); RecyclableCollection<PacketData> data = packetTransformer.toData(version); try { for (PacketData packetdata : data) { ByteBuf senddata = Allocator.allocateBuffer(); senddata.writeByte( packetIdRegistry.getNewPacketId(currentProtocol, packetdata.getPacketId())); senddata.writeBytes(packetdata); ctx.write(senddata); } ctx.flush(); } finally { for (PacketData packetdata : data) { packetdata.recycle(); } data.recycle(); } } }
@Override public RecyclableCollection<PacketData> toData(ProtocolVersion version) { PacketData serializer = PacketData.create(ClientBoundPacket.PLAY_HELD_SLOT_ID, version); serializer.writeByte(slot); return RecyclableSingletonList.create(serializer); }