Event on villager trade


I’m trying to catch the event emited when a player trade with a villager

I’ve done some tests on the TargetContainerEvent but how can I be sure that the event is actually related to a sucessful trade because the event is triggered when a player click on the inventory.

Maybe a combinaison of checking that the event is a ClickInventoryEvent$Primary and check that event transactions contain the desired items is enought ?

Also I don’t know how to check if the targetInventory is a ContainerMerchant inventory since this a Minecraft class.

Thx for your help!

Check if the Slot is an OutputSlot.

Not sure if this will actually work because on the whole this is probably not very much implemented.