Test for a player using a command
Okay, I've a problem. I need a command that tests for a player running a specified command.
For example, check whether a player is using /gamemode 1 (in order to reset them)
Best Answer
Actually very simple to do, all you need to do is create a new scoreboard, and for an example let's just call it Admin...
/scoreboard objectives add Admin dummy
then create whatever value you want the Admin score to be... and then in a new command block, just have it test for anyone not with that Admin number and in gamemode 1 if it finds someone, have that player be changed to gamemode 2 or whatever...
testfor @a[score_Admin=(Number 1 less than Admin number),score_Admin_min=(Number 1 more than Admin Number),m=1]
gamemode 2 @a[score_Admin=(Number 1 less than Admin number),score_Admin_min=(Number 1 more than Admin Number),m=1]
so for example, lets say the Admin number is 2026
testfor @a[score_Admin=2025,score_Admin_min=2027,m=1]
gamemode 2 @a[score_Admin=2025,score_Admin_min=2027,m=1]
and you can even add a message to tell those players...
/tellraw @a[score_Admin=2025,score_Admin_min=2027,m=1] {"text":"","extra":[{"text":"Creative is not allowed","color":"white","italic":"true"}]}
Hope this info helps. Play around with it. Also, this way, you can give out Admin number to whomever the admins are, and the admin number can be changed, but make sure to turn off whatever clock you have running (or in 1.9 take off the always active part) before changing numbers in the command blocks and the admins must change to the new number.
Let me know if this helps and if you need help in anything else.
Pictures about "Test for a player using a command"



How do I use the Testfor player command?
You can give a player any item whenever you want using the /give command in Minecraft.How to detect a player using command blocks! | /execute command tutorial for 1.16 Minecraft Java
More answers regarding test for a player using a command
Answer 2
If there is a certain part of game you don't want them to turn creative, you can somehow (Secretly) power a repeat command block that sets the gamemode to survival or adventure. That way if a noob player decides to turn creative, the game will turn back the mode before the noob player can do something. This will ruin the upper left corner of the screen, saying "set game mode to survival" a bunch of times, But its better than a big command. And search the command I forgot it.
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Anete Lusina, Vanessa Loring, RF._.studio, Fardad Postwala
