Check if particular item in Inventory is clicked

I wrote this as a test to see if SlotPos.getX() would give me a proper value:

@Listener
public void onInventoryClick(ClickInventoryEvent event){
   Logger.debug("ClickInventoryEvent run");
   for (SlotTransaction t: event.getTransactions()){
      Slot s = t.getSlot();
      SlotPos pos = s.getProperty(SlotPos.class, null).get();
      Logger.debug(pos.getX() + " " + pos.getY()); // Custom class, ignore.
   }
}

and it threw a java.util.NoSuchElementException: No value present exception.

Checking with if(...isPresent()) will just not run anything within the if statement.