How to Check if two Inventories are the same

I’m using the event ClickInventoryEvent and trying to detect if the player clicked on their own inventory.

Could I just do if (targetInventory instanceof Player?
Is it possible to interact with another player’s inventory?

Edit: I obviously didn’t think about this before posting

No. The targetInventory is a Container viewing an Inventory.
Try getting the parent of a Slot in the transactions.

Yes you can view another player inventory. But it will only display the main inventory + hotbar.

That works! Thank you!
The only issue I have is if someone clicks a slot with no items in it, I get an IndexOutOfBounds Exception.
Should I just surround the getSlot in a try?

Edit: I just put it in a loop and test each transaction. Before I was just getting transaction 0