@Throws(Exception::class) fun writeToBuffer(buffer: ByteBuf?) { if (id !== -1) { Type.VAR_INT.write(buffer, id) } if (readableObjects.size() > 0) { packetValues.addAll(readableObjects) readableObjects.clear() } var index = 0 for (packetValue in packetValues) { try { var value: Any? = packetValue.getValue() if (value != null) { if (!packetValue.getKey().getOutputClass().isAssignableFrom(value.javaClass)) { if (packetValue.getKey() is TypeConverter<*, *>) { value = (packetValue.getKey() as TypeConverter<*, *>).from(value) } else { println( "Possible type mismatch: " + value.javaClass.name + " -> " + packetValue.getKey() .getOutputClass() ) } } } packetValue.getKey().write(buffer, value) } catch (e: Exception) { throw InformativeException(e).set("Index", index) .set("Type", packetValue.getKey().getTypeName()).set( "Packet ID", id ).set("Data", packetValues) } index++ } writeRemaining(buffer) }
Write the current output to a buffer .