This will take some time and planning, as rushing in can lead to your demise long before you take 30 towns. Towns captured both peacefully and by force count towards this but if you are short on time, resort to taking each town by force. Having said that, it is a good idea to try and take 5-10 towns peacefully while you build up your economy and fleet as this will reduce the time needed for the strategy below.
The following is a strategy that will allow you to take towns without causing an all out war in the Caribbean.
Firstly, ensure you have a strong convoy (10+ liners and/or war galleons) that you will use on the towns, and a second convoy (8+ warships) preferably close to a pirate hideout. (The second convoy is optional as you can use your main convoy to attack the pirates provided it isn't too damaged.) Ensure you haven’t destroyed too many pirate hideouts as attempting this without them may prove frustrating. You will also need to raise your reputation with each nation to 100%. Also, if by chance you can obtain a letter of marquee against the nation you plan to attack, do so.
Once you have met the above requirements, launch an attack on 2 towns of your choosing. It is recommended that you try and find a town with no convoys defending it but this may take time, so it’s up to you. Once you have taken control of 2 towns, attack the pirate hideouts, ONLY fighting the convoys and not the hideouts themselves. This will raise you reputation back up to 100% and prevent the other nations from trying to retake their towns.
Rinse and repeat until you are in control of 30 towns. Depending on how many pirate hideouts you have on the map, you may have to spend some time waiting until they respawn convoys before continuing to annex towns.