Emperor Frederick II built a massive castle in Trani .
Many churches , palaces , and castles were built in Trani during this time .