How to detect fake players

In general, dealing with fake players can be quite problematic. I know that sponge’s event tracking system tries to detect the root cause in most cases. However, this will probably not work on all mod-specific use cases, so my question is:
Is there a way in the sponge API to detect if a Player object is real or not?

There’s no built-in way of doing that in the API. However what you could try is checking if the server finds a player by it’s UUID.
something like:

Sponge.getServer().getPlayer(testPlayer.getUniqueId());

If the return value is present then it’s a real player, otherwise probably is fake

1 Like

Most fake player names start with [, like [BuildCraft] or [CoFH]. Try checking if it starts with a bracket.

That’s not reliable and slow.

1 Like

Could also use the sponge config, https://docs.spongepowered.org/master/uk/server/getting-started/configuration/sponge-conf.html#global-properties-of-sponge

invalid-lookup-uuids

Is there no reliable way?

I think it’s reliable doing it that way actually. I just can’t guarantee it will always work in all cases
(possibly are edge-cases when real players are joining/leaving)

I looked around a bit more, seems that there is a method in SpongeCommon to check this. It’s just not exposed in the API…

I think although that way may be reliable, Going through n players will always be slower than doing one conditional statement. Checking for a bracket seems like a pretty decent way to do it, although I do not know the API that well, this is assuming that all mod authors are following standards, but if they were I think there wouldn’t be as many bugs.