Ejemplo n.º 1
0
 @Override
 public void split(ChannelHandlerContext ctx, ByteBuf input, List<Object> list) throws Exception {
   input.markReaderIndex();
   final byte[] array = new byte[3];
   for (int i = 0; i < array.length; ++i) {
     if (!input.isReadable()) {
       input.resetReaderIndex();
       return;
     }
     array[i] = input.readByte();
     if (array[i] >= 0) {
       final PacketDataSerializer packetDataSerializer =
           new PacketDataSerializer(
               Unpooled.wrappedBuffer(array), ProtocolVersion.MINECRAFT_1_7_10);
       try {
         final int length = packetDataSerializer.readVarInt();
         if (input.readableBytes() < length) {
           input.resetReaderIndex();
           return;
         }
         list.add(input.readBytes(length));
         return;
       } finally {
         packetDataSerializer.release();
       }
     }
   }
   throw new CorruptedFrameException("length wider than 21-bit");
 }
 @Override
 public void readFromServerData(PacketDataSerializer serializer) throws IOException {
   entityId = serializer.readVarInt();
   type = serializer.readUnsignedByte();
   x = serializer.readInt();
   y = serializer.readInt();
   z = serializer.readInt();
   pitch = serializer.readUnsignedByte();
   yaw = serializer.readUnsignedByte();
   objectdata = serializer.readInt();
   if (objectdata > 0) {
     motX = serializer.readShort();
     motY = serializer.readShort();
     motZ = serializer.readShort();
   }
 }
Ejemplo n.º 3
0
 @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 void readFromServerData(PacketDataSerializer serializer) throws IOException {
   super.readFromServerData(serializer);
   effectId = serializer.readByte();
 }
 @Override
 public void readFromServerData(PacketDataSerializer serializer) throws IOException {
   worldAge = serializer.readLong();
   timeOfDay = serializer.readLong();
 }
 @Override
 public void readFromServerData(PacketDataSerializer serializer) throws IOException {
   entityId = serializer.readVarInt();
   animation = serializer.readUnsignedByte();
 }
 @Override
 public void readFromServerData(PacketDataSerializer serializer) throws IOException {
   messageJson = serializer.readString(Short.MAX_VALUE);
 }