During the late 18th and 19th centuries , Great Britain established colonies and protectorates in the area of current Malaysia ; these were occupied by Japan from 1942 to 1945 .