DestructEntityEvent (DropItemEvent.Destruct) and ItemStack's

Hello all. I create plugin Grave.
Are no ideas, how:
1 - Get drop ItemStack’s from DestructEntityEvent;
2 - Prevent drop ItemsStack’s from DestructEntityEvent.

Take a look at the DropItemEvent or the DropItemEvent.Destruct :slight_smile:

1 Like

Not exactly. I want get itemStack’s, when the player dies.

DropItemEvent should be able do that. Theoretically you would get cause player and check if player is dead. Haven’t tried it which is why I say theoretically.

1 Like

DropItemEvent.Destruct and than check the Cause for a Player … This should then be the player-death drops only.

1 Like

In DropItemEvent.Destruct there is no method: getDroppedItems().

I believe it is the getEntities() method.

1 Like

In DropItemEvent.Pre - There is such.

I agree with everyone.
Event DropItemEvent.Destruct.
Method getEntities().

Event DropItemEvent.Destruct behaves strangely. Later, I upload videos.

I wrote code:

@Listener
public void onDropItem(DropItemEvent.Destruct event) {
      event.setCancelled(true);
      }
}

Event DropItemEvent.Destruct behaves strangely. SpongeForge #847.
Video:

post it on the github page.

1 Like

The event DropItemEvent.Destruct is now operating normally.

I am trying to check the Cause for a Player, when he dead.
I am use code: event.getCause().first(Player.class).get();

If player died - true;
If a player has killed the mob - true.
In both cases - true.

Both cases would be true. Doesn’t matter how the player died, its still a player.

you want to test the root cause, instanceof Player to distinguish cases

I want check that the items dropped it from the player at the event DropItemEvent.Destruct.

I got to achieve the desired.
I am use two conditions:
boolean playerCause = event.getCause().first(Player.class).isPresent();
boolean damageCause = event.getCause().first(DamageSource.class).isPresent();
And logical operator &;

Result code:

    @Listener
    public void onDropItem(DropItemEvent.Destruct event) {
        boolean playerCause = event.getCause().first(Player.class).isPresent();
        boolean damageCause = event.getCause().first(DamageSource.class).isPresent();
        if (playerCause & damageCause == true){
            logger.info("Condition true");
        } else {
            logger.info("Condition false");
        }
    }

Slightly off topic:
== true” is never a good idea … i’d suggest:

    @Listener
    public void onDropItem(DropItemEvent.Destruct event) {
        boolean playerCausePresent = event.getCause().first(Player.class).isPresent();
        boolean damageCausePresent = event.getCause().first(DamageSource.class).isPresent();
        if (playerCausePresent && damageCausePresent){
            logger.info("Condition true");
        } else {
            logger.info("Condition false");
        }
    }

:wink:

1 Like

@Blue, Thanks for the tip.

The issue is solved.