Suppose the world has 5 islands. There are players on all the island. So, I don't want to send the data of players, items, enemies and other entities that are on Island 1 to the players of other islands. I mean there is no point in doing that. So, is this the right approach ? I mean is this how people usually go about doing this ?Uhhh... I suspect you mean "player lobbies" in where each island represents one lobby?
I mean, one good way of doing this is just to keep all the player data, and the location of that player on the server back end. Then, just share the data with players that are within that location. Let your server handle how to organize the players, and also handle the information you send back to players.
This is something I thought:
I store the player's data in an ArrayList. So, I was thinking of making an ArrayList for all the islands and then players of the same island will share their data. But, I figured as the no. of islands will increase, things will get unorganized and complex.
So can you guys help me on how to handle this ?
Well, unless you have 1 million islands, I don't see it as the case. However, to relieve confusion, I would literally track it by player and give each player a "location ID". Then, if multiple players have matching "location ID"'s, I'd send all the data necessary in a group to only those players. There is literally no reason to track the islands as a player literally can't be in two places at once.
Hopefully that clears up a little, and my way is only one idea. There are other ways to do it, so feel free to experiment if this way doesn't work for you.