Minecraft – Test if a player has drank a water bottle

minecraft-commandsminecraft-java-edition

I'm making a minigame with a water system.
Is there a command to test if a player has drunk a water bottle, and activate a command off of that?

Best Answer

First run this command once:

/scoreboard objectives add HasDrunk stat.useItem.minecraft.potion

This makes a scoreboard value that will increase by one for anyone who drinks a potion (which, by the game code, includes water bottles).

Next, in a repeating command block set to always active (number one in the below picture), write whatever command you want to activate, using @a[score_HasDrunk_min=1] instead of the player's name. Run another command if you want from the number 2 command block. Add as many as necessary all facing the same direction. Finally, in the last command block, write:

/scoreboard players set @a[score_HasDrunk_min=1] HasDrunk 0

Disclaimer:

You cannot use this with conjunction with drinkable potions. As a workaround, you could only give people splash potions