First, use a code block, this is really difficult to read.
Second, you can get the server from the server level, but you can't know if you're on the server level until you check it via Level#isClientSide.
Third, you can use Level#getNearbyPlayers to get nearby players in the specified bounding box.