Howto get clicked slot position in the inventory

How to get position of clicked slot? (ClickInventoryEvent)

The event has a list of SlotTransactions. Each of those specify a Slot, and its original and new ItemStacks should the transaction not be cancelled.

You should be able to use that Slot for what you want to do.

Not understand.

I would like get coordinates of clicked slot - for example SlotPos(2,1)

Looking for sponge alternative to bukkit InventoryClickEvent.getSlot()

According to this thread:

slot.getProperty(SlotPos.class, null);

1 Like

Still no luck. SlotPos returns no value.

My code:

    @Listener(order = Order.FIRST)
    public void clickEvent(ClickInventoryEvent event) {
        
        if (event.getTargetInventory().getName().get().contains("Vote Rewards") ) {
            Transaction clickTransaction = event.getTransactions().get(0);
            Slot eventinventory = event.getTransactions().get(0).getSlot() ;
            SlotPos slotpos = eventinventory.getProperty(SlotPos.class, null).get(); // <- line 130 Optional.empty 

trace:

java.util.NoSuchElementException: No value present
	at java.util.Optional.get(Optional.java:135) ~[?:1.8.0_111]
	at net.rebelgames.voterewardmenu.VoteRewardMenu.clickEvent(VoteRewardMenu.java:130) ~[VoteRewardMenu.class:?]

I think Inventory Properties are incomplete atm, here’s a PR to implement it.

Thanks :slight_smile:

Looks like unimplemented for now :frowning:

Really need this PR to be merged :slight_smile: