If you’re on Xbox you can through Xbox settings turn off cross connection play.
To do this:
-Go to settings
-General
-Online Safety and Family
-Privacy and Online
-Xbox Live Privacy
-View Details and customize.
-Communications and multiplayer
The second box that states “You can play with people outside of Xbox live”, change from allow to “Block”.