How to check if it's the custom inventory?

i created a custom inventory and now i want to do some stuff about the ClickInventoryEvent.
Now my problem is that i don’t know how to check if the player is in this custom inventory.


Inventory inventory = Inventory.builder()
                .property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(Text.of("Custom Inventory")))

I’ve tried to get the ArcheType event.getTargetInventory().getArchetype() but it returns always unknown.

Then i tried to get the InventoryTitle property.

event.getTargetInventory().getProperty(InventoryTitle.class, InventoryTitle.PROPERTY_NAME).get();

but it returns always Optional.empty.
I also tried to get other properties, but they return all Optional.empty

So, i don’t know what i’m doing wrong.
How can i check this?

Here my Listener:

    public void onClickInventoryPrimary (ClickInventoryEvent.Primary event) {

        Optional<Player> cause = event.getCause().first(Player.class);

        if (cause.isPresent()) {

            Player player = cause.get();

            if (is the custom inventory){
                if (event.getTransactions().get(0).getOriginal().getType().equals(ItemTypes.FISH)) {
                    // do some stuff.

You don’t have to. Use the .listener method of the builder, like below.

Inventory inventory = Inventory.builder()
                .listener(ClickInventoryEvent.Primary.class,  event -> { /* Your code here. I generally prefer using a private method. */ })

Now, unfortunately you won’t be able to use this with .listener, but it’s good to know about event filters regardless.

Instead of jumping through hoops to get your player from the cause, you should be doing the following:

public void onClickInventoryPrimary(ClickInventoryEvent.Primary event, @First Player player) {
    // 'player' is the player who clicked on the inventory. If a player isn't in the cause, this listener is not fired.

Just note that filters aren’t a magic solution, and they have a variety of drawbacks that I won’t get into.

It does not work because usually in events you’re interacting with a Container not the actual inventory.
(When a Player interacts with it it is ALWAYS a Container)

2 ways to detect your custom inventory:
Set a custom Carrier (just implement the interface)
Set a Identifieable Property
when constructing the custom inventory
and then later retreive it from the container it should both be present. (property i’m not 100% sure)

Thanks for your replies,

the solution of Simon solved my problem.
And thanks for the little digression, about filters.