Can not cancel inventory click events/How to check inventories equality?

I created inventory:
Inventory inventory = Inventory.builder().of(InventoryArchetypes.CHEST).build(GWMCrates.getInstance()); //There is some manipulations with inventory. player.openInventory(inventory, GWMCrates.getInstance().getDefaultCause()); FIRST_GUI_INVENTORIES.put(inventory, player);
OKay, all good.
After this, I tried to cancel any clicks in this inventory:
@Listener(order = Order.LATE) public void cancelClick(ClickInventoryEvent event) { System.out.println(20); for (Inventory inventory : FirstGuiOpenManager.FIRST_GUI_INVENTORIES.keySet()) { System.out.println("inventory from set = " + inventory); } Container container = event.getTargetInventory(); System.out.println("event container = " + container); Optional<Inventory> optional_inventory = event.getCause().first(Inventory.class); if (!optional_inventory.isPresent()) return; Inventory inventory = optional_inventory.get(); System.out.println("event inventory = " + inventory); System.out.println("contains1 = " + FirstGuiOpenManager.FIRST_GUI_INVENTORIES.containsKey(container)); System.out.println("contains2 = " + FirstGuiOpenManager.FIRST_GUI_INVENTORIES.containsKey(inventory)); }
Not helps, I can click/drag/interact with items in this inventory, console output:

What Im doing wrong?(

OKay, I can not understood, how to compare inventories?
This not works too:
Optional<Container> optional_container = player.getOpenInventory(); if (optional_container.isPresent() && inventory.equals(optional_container.get())) {

Unless there’s something I’m not seeing, you never actually cancel the event, you just print stuff.

I want to cancel event only if clicked inventory, is in my Set FIRST_GUI_INVENTORIES.
But as you can see by text in console “contains1” and “contains2”, its never true, ever when I know that I now clicks on inventory, that my plugin created some moment ago, and added it Set FIRST_GUI_INVENTORIES.

In second post, I comparing “player.getOpenInventory() and my inventory”.
I 100% know, that Im now see that inventory, which my plugin created earlier, but got “false” as result of comparing…
Maybe I wrong compare them?
Maybe inv1.equaks(inv2) not suitable here?
Maybe there is another method?

It’s possible that player.getOpenInventory() in fact returns a view, combining the actual open inventory and the player’s own inventory. Try making your own InventoryProperty and applying it to your inventory during building, and then querying for it in your equality test. You could also just use the Identifiable InventoryProperty.

Edit: Also, NEVER use mutable values as HashMap keys. Not ever. Due to hash bucket calculation, if some property of the class ever changes, it’s easy for it to get lost in the map, and it won’t be findable by containsKey or get if this happens. The same will happen for any container implementation relying on hashing, such as HashSet.

Can you please write code example, how to set identifiable property to inventory, and how to get it?
I writed this code:
Inventory inventory = Inventory.builder().of(InventoryArchetypes.CHEST). property("identifiable", new Identifiable(UUID.randomUUID())). build(GWMCrates.getInstance()); Collection<Identifiable> properties = inventory.getProperties(Identifiable.class); if (properties.isEmpty()) { System.out.println("Created inventory empty properties!"); } else { properties.forEach(identifiable -> System.out.println("Identifiable from created inventory = " + identifiable)); }
But in console I see “empty properties”…

What version of Sponge are you running?

spongevanilla-1.11.2-7.0.0-BETA-271

Tried this:
Inventory inventory = Inventory.builder().of(InventoryArchetypes.CHEST). property("identifiable", new Identifiable(UUID.randomUUID())). build(GWMCrates.getInstance()); Optional<Identifiable> optional_property = inventory.getProperty(Identifiable.class, "identifiable"); if (optional_property.isPresent()) { System.out.println("Created inventory property = " + optional_property.get()); } else { System.out.println("Created inventory property not found!"); }
Got “Created inventory property not found”…

Try a stable 6.0 version.

Tried spongevanilla-1.11.2-6.1.0-BETA-6,
output the same “empty proprty”, “empty properties” :frowning:

make a SpongeCommon issue then

Oh, I’m not sure that my English knowledge is enough to describe the problem normally… OKay, I will try.

I solved the problem by comparing Container that returns by Player::openInventory

One more question.
How I can check in ClickInventoryEvent,
player clicked on opened inventory, or player clicked his inventory/hotbar?