How to /testfor a player's gamemode

Instead of testing for a gamemode NBT tag, why don't you use the gamemode selector instead?

/execute if entity @a[gamemode=adventure]

If you want to mark players, you can use a /scoreboard command with the selectors set to @a[gamemode=adventure].


Before 1.13, it is /testfor @a[m=2], but as of 1.13, m was renamed to gamemode, /testfor was renamed to /execute if entity, and the argument is now the name of the mode.

Props to @ppperry for notifying me of this.


To complete what aytimothy said, `@a[m=M] targets all Players with gamemode M:

0 for Survival, 1 for Creative, 2 for Adventure, 3 for Spectator. For targeting Players that are, fer example, in gamemode 0 or 2, use scoreboards (vis my answer):

First, create a dummy scoreboard objective:

/scoreboard objectives add gameM dummy  

Then, add all Players with gamemode Survival and Adventure to the "selectMe":

/scoreboard players set @e[m=0] gameM 1  
/scoreboard players set @e[m=2] gameM 1  

Now you can enter your command:

/testfor @a[score_gameM_min=1,r=15]