[SPIGOT-6057] InventoryCloseEvent MerchantInventory getMerchant() is not an instance of a Villager Created: 11/Aug/20  Updated: 17/Aug/20

Status: Reopened
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Radiant_Shiny Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: api, bug, spigot

Attachments: PNG File image-2020-08-12-21-50-29-471.png    
Version: git-Spigot-9639cf7-f622793 (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   
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.



 Comments   
Comment by Radiant_Shiny [ 13/Aug/20 ]

The problem was on my end. Eclipse dubugger went wild, sorry.

Comment by md_5 [ 13/Aug/20 ]

CraftVillager absolutely can be cast to Villager lol

Comment by Radiant_Shiny [ 13/Aug/20 ]

inventory,getHolder() returns an instance of org.bukkit.craftbukkit.v1_16_R1.entity.CraftVillager which cannot be casted to a Villager

This was an IDE bug, inventory.getHolder() does return a Villager instance. The issue can be closed. Sorry for bothering and thank you.

Comment by Black Hole [ 11/Aug/20 ]

inventory.getHolder() should return the villager.

Comment by Radiant_Shiny [ 11/Aug/20 ]

Ok, it is o_rg.bukkit.craftbukkit.v1_16_R1.inventory.CraftMerchant_ according to the debugger. If event is not supposed to give any access to an entity, then it's not really a bug, but a feature request. Though I see no other way to check villager's state right after player finished interacting with it.

Comment by md_5 [ 11/Aug/20 ]

Well what is it instanceof?

Generated at Sat Apr 05 09:38:10 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.