Get player inventory after death

Hello everyone.
I would like get the player inventary after a player death.
I have been working in something like:

public void onPlayerDeath(DestructEntityEvent.Death event){
Living living = event.getTargetEntity();
if ( living.getType().equals(EntityTypes.PLAYER)){ //Check if target is a player
Player player = (Player) living;
Inventory inv = player.getInventory();
}
}

But the previous piece of code always return an empty inventory. I almost tried using @Listener(order=Order.PRE) but no way.
Can you give me some clues.
Thank you very much, and have a nice day.

Good chance the inventory is already been dropped. Also I would check if Entity is Player like this

if(living instanceof Player) {
    Player player = (Player) living;
}

Cache the UUID, and listen for a DropItemEvent.Destruct, with the @First player having the same UUID. You can then use getEntities() to return the list of Items.

Thank you for your advice. I will explore that way. The problem is that DropItemEvent is triggered first. Maybe I can cache inventory, and set it on player spawn event.

You could listen for damage events on players and check if it will cause death.

Yes, but that is not spongy because a mod could have some extra reason for them not to die.

1 Like

Thank you all by your help :D.
Finally I got it it DropItemEvent.destroy like pie_flavor suggested.
I would be delighted if Sponge had implemented a playerDeathevent or similar which contains the inventory at death time.
Anyway, thanks by your help again. Have a nice day :wink: