I cannot get Inventory.Builder#listener() to fire for a custom inventory I’m creating. I am not sure if I am doing wrong or if this is an issue I should report on GitHub. It’s hard to figure out because I don’t see anything about the inventory builder at all on the Sponge Docs website.
Here’s code to reproduce my problem:
@Listener
public void onTest(MessageChannelEvent.Chat event, @First Player player) {
if (!event.getRawMessage().toPlain().equalsIgnoreCase("!test")) return;
Inventory custom = Inventory.builder()
.of(InventoryArchetypes.CHEST)
.property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of("Fancy custom inventory")))
// Log to the console whenever something in the inventory is clicked on
.listener(ClickInventoryEvent.class, e -> logger.info("Click inside custom inventory"))
.build(plugin);
custom.query(GridInventory.class)
.query(SlotPos.of(1, 1))
.offer(ItemStack.of(ItemTypes.DIAMOND, 1));
player.openInventory(custom);
}
Write “!test” in chat and click the diamond. I’d expect something to be logged in the console, but not getting anything.
- Am I doing something wrong or is this a bug?
- What events are applicable for the
listener()method? - Is there any documentation about the inventory builder? I have no idea how inventory properties, archetypes or queries work at all other than guessing my way through a lot of it. I’ve looked through the Sponge Documentation website but haven’t found anything about the
listener()method at all. Googling results in very few results. As with many Sponge things, I just have to guess how to use things. How are new Sponge users supposed to figure these things out? I often feel very lost when working towards the Sponge API because of the lack of documentation or guidance.
Any help or insight would be greatly appreciated ![]()
spongevanilla-1.12.2-7.0.0-BETA-341.jar
EDIT
Someone else reported it as a bug: