I don't know how many times someone's asked this question before. It's the same thing every time, and I'm going to give the same answer every time: Take a look at TapToDo's source.
I know that -.- I was telling him to use the TapToDo Plugin. Please read the comment before replying.
He likely wants a code solution, not to be told to use the plugin. If you are trying to tell him to look at TapToDo's source, say that in your context.
PHP: public function onTap(PlayerInteractEvent $ev){if($ev->getAction() === PlayerInteractEvent::RIGHT_CLICK_BLOCK){//code here }}