You have to know which inventory holder they opened to use that function. There currently doesn't exist a function that returns the location or entity of the inventory holder of the inventory the player is currently viewing. However, it does seem possible with the current Bukkit API. I'll look into adding this.

So it returns null if it's a virtual inventory and returns the player's UUID if there is no inventory open or they're viewing their own inventory. (There's no way to tell if they have their own inventory open or not)

I'm going deeper on this. I'm now adding virtual inventory support in core, something I've wanted to do for a while. This way I don't have to change the output of this new function later. I might also change the function name, as I'm not happy with it.