ScalaPB case classes are immutable. In your example,
addPlayers would not modify the instance it's called on, but return a new instance of
PacketPlayer that has the additional players.
It is possible to avoid mutable arrays and vars in constructing the new object. For example:
val players = onlinePlayers.keySet.map(makePacketPlayer) val packetPlayers = PacketPlayers().withPlayers(players)