It was built in the 14th century for the king James II of Majorca . It was used as a military prison during the 18th and 19th centuries. Now it is one of the touristic attractions of the island.