So far, I've been able to detect when a diamond is placed into a chest's inventory but how can I detect who placed that diamond?
I'd prefer not to use the nearest player because someone else could potentially be falsely identified. (I have a command chain that trades players emeralds in exchange for experience levels and it also sometimes robs random nearby players.)
Some context: I'm making a race to be the first to deposit a diamond. I could constrain the player accessing the chest and just check who is standing on a block, but if I did that, I could also just test the player's inventory directly. But that seems boring. Adding the chest adds to the drama, I feel. Like, if someone fumbles last minute and deposits dirt on accident, someone else could easily win, which is fun.
My command chain is currently:
if block x y z chest{Items:[{id:"minecraft:diamond"}]}
say Diamond Detected
Edit: The diamonds are mined and as such, I will not necessarily be able to tag them for each player. Another user suggested I could scan the inventories of the users at every tick and tag the diamonds in their inventory with their name. I don't know how to do this, though I believe this is the direction where I will find my answer.