How can I detect when a player breaks a mob spawner?

I am working on a map that I want to test if a player breaks a spawner. Then it gives the player a spawner, and maybe some XP. I want to use a scoreboard command, but /scoreboard objectives add SB stat.mineBlock.minecraft.mob_spawner
doesn't work even though the spawner ID is mob_spawner. What is the correct way to write this?
(Forgot: I need it to be any spawner, natural or placed :P )
Best Answer
If you have multiple spawners, but every single one is known to you (as opposed to natural world generation), I suggest manually summoning an armor stand with a custom name at the position of every single one, e.g. using
summon ArmorStand x y z {CustomName:"ZombieSpawner",Marker:1b,Invisible:1b,NoGravity:1b}
Afterwards, use the detect
scheme of the execute
command to detect an air block.
execute @e[type=ArmorStand,name=ZombieSpawner] ~ ~ ~ detect ~ ~ ~ minecraft:air -1 <command @p>
execute @e[type=ArmorStand,name=ZombieSpawner] ~ ~ ~ detect ~ ~ ~ minecraft:air -1 kill @e[type=ArmorStand,name=ZombieSpawner,c=1,r=1]
Use differently named markers for different spawners if necessary.
Automating the placement of these armorstands is possible, but I can't think of a way to do so quickly and/or lag-free.
Pictures about "How can I detect when a player breaks a mob spawner?"



Is there a command to locate mob spawners?
Spawners cannot be obtained in Survival, even with Silk Touch.Can you use silk touch on a spawner?
No item would drop and the block break would not be detected. If the player simply drops an item, a "block break" would be detected. If a mob dies and drops items, a "block break" would be detected. (But who knows, maybe you have a large bedrock room filled with nothing but sand; this solution would work.)How do I know if my block is broken?
In the case of a spawner, players need to be at a distance of at least 16 blocks distance from the spawner to activate it. When AFK-ing at a spawner-based farm, players should be at a distance of less than 16 blocks from the spawner.If Your Mob Grinder Isn't Working, Watch This!
More answers regarding how can I detect when a player breaks a mob spawner?
Answer 2
If it's just a single spawner, not multiple, you can use /testforblock
Answer 3
If you're OK with using mods, from what I remember Craftable Spawners makes spawners actually drop iron bars. You could check the inventory for them. The problem would be that you could not keep apart spawners and iron bars, but you could use some custom structure worldgen mod that adds a world type where ONLY custom structures are generated, and add each structure as custom structure, but without iron bars. And you could use a mod for crafting recipe blocking, and disallow all iron bar crafting recipes. If such a solution is considerable, you should check out PlanetMinecraft - that forum has an insane amount of different mods, and some combination will surely fit your needs.
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Harrison Haines, Nicola Barts, Budgeron Bach, Andrea Piacquadio