public class Bar implements Listener { @EventHandler public void onVillagerFinishTrade(InventoryCloseEvent e) { if (e.getInventory() instanceof MerchantInventory) { MerchantInventory mi = (MerchantInventory) e.getInventory(); Merchant m = mi.getMerchant(); if (m instanceof Villager) { //this line of code is never reached } } } }
When player closes villager trading menu MerchantInventory object does not return a merchant that is an instance of a Villager. This does not allow to perform any actions related to this villager.