(a) When an action is commenced to recover land or the possession thereof, the defendant may, at any time before the trial, suggest upon the record that he, and those whose possession he has, have, for three years next before the commencement of the action, had adverse possession thereof, which must be construed to mean the same character of possession as will put in operation the statute of limitations. In such case, if the jury finds for the plaintiff, it must also ascertain by its verdict whether such suggestion is true or false. If the jury finds it to be false, it must return a verdict for the damages as in ordinary cases. If the jury finds it to be true, it must assess the value, at the time of trial, of the permanent improvements made by the defendant, or those whose estate he has, and also ascertain by its verdict the value of the lands and of the use and occupation thereof, not including the increased value by reason of such improvements.
(b) If the value of the use and occupation as assessed exceeds the value of the permanent improvements made, judgment must be entered against the defendant for the excess. If the value of the improvements exceeds the value of the use and occupation, no writ of possession shall issue for one year after the entry of the judgment unless the plaintiff or his legal representative pays the defendant, or deposits with the clerk for him, the excess of the assessed value of the improvements over the value of the use and occupation. If the plaintiff or his legal representative neglects for the term of one year to pay such excess, and the defendant or his legal representative within three months after the expiration of the year pays to the plaintiff, or to the clerk for him, the value of the land and of the use and occupation thereof as assessed by the jury, the plaintiff is forever barred from his writ of possession and from commencing any action whatever against the defendant, his heirs or assigns to recover such land or the possession thereof.