I read a theory and it goes like this....
Law planned the rocky port incident and lured the pirates of pirate island at rocky port.
Why rocky port? Because if we go by name then it's seem like a trading station and one plot Oda consistently touched is underworld network and trading.
Now, BB being there could be because of Wang zhi and him having some info regarding Rocks.
But why coby was there? Now theory gave two explanations
1) Coby is member of SWORDS and was investigating underground trading...
2)Or law is actually a double agent and conspired with SWORDs to take on the pirates.
Now, we know law took hearts of 100 pirates and he can only do so by using shambles in his room and it could be possible that citizens were collateral damage in this action along with the destruction event would have caused. Here comes coby into the mix..
But wang zhi was too much to handle for them and BB stepped in and they could have collaborated to defeat Wang zhi