If an individual wants to gain an individual benefit from their work instead of giving it to the community, what would prevent them from bartering for more personal good than they'd get otherwise?
Sharing one's fruits with the community not only benefits the community itself, but the individual as well. This is anarcho-communism. I'm not the best person to describe it since I'm not that knowledgeable about politics, but I'd encourage you to read The Conquest of Bread, it's actually a pretty straightforward read: https://theanarchistlibrary.org/library/petr-kropotkin-the-conquest-of-bread
But why would some people not benefit more than average by bartering then by sharing? They would get benefit from both, but it seems like some people could get more benefit than the average community benefits through alternative channels, since not everyone will produce the exact same amount of value.
When your needs are met by the state, you tend to be less selfish. Or not selfish at all since you don't need to hoard the item. Besides Conquest of Bread, I'd suggest reading Wage-Labor And Capital for more understanding. At least if you are legit wanting to learn.