I need to find out if a player has a certain item in their inventory. I tried to find it in the documentation, but it is so terrible (as for me) that I could not find it. So far, there is such a code that works, but it works when a player places or breaks a block with the item I need, and I need it to be constantly tracked. For example, I wrote a command and it turned out that there is such an object, or not.
@EventHandler
public void yes(PlayerInteractEvent e){
Player player = e.getPlayer();
ItemStack item = e.getItem();
if(item.getType() == Material.DIAMOND_ORE){
player.sendMessage("Yes");
}else{
player.sendMessage("No");
}
}