Minecraft – How to detect if a player logs out of the game in Minecraft

minecraft-commandsminecraft-java-edition

I am building a Minecraft survival games map, in which the battle area is on a floating island. My friends discovered that if they are falling to the ground, they can quickly logout and log back in to escape fall damage and not die, thus cheating.

Is there anyway to detect if a player logs out so I can increment their Death score?

I'm building it vanilla, I'm trying to make a whole map automated with just command blocks and redstone, this is the last thing I need to do now.

Best Answer

First, you should set up a scoreboard objective of type stat.leaveGame:

/scoreboard objectives add JustLeft stat.leaveGame

When a player leaves the world, their JustLeft score will increase by 1 because of its type.

On a clock somewhere, you should then have:

/scoreboard players set @a[score_JustLeft_min=1] Death 1

To set the death score of players who have just relogged to 1. Followed by:

/scoreboard players set @a[score_Death_min=1] JustLeft 0

So that their JustLeft score is reset after their Death score is set, preventing them being continually killed.

@a only selects online players, so they should only have their Death score set and then reset when they rejoin the world, even though their JustLeft stat will increase to 1 straight away.