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 )


Solution 1:

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.