Minecraft 1.16] e.getDamager () instanceof Arrow?

Ba
2

How can I find out whether I was killed by an arrow that was dropped, for example, from a dispenser? Not from a player or other mobs. I did the following:

if (e.getEntity (). GetLastDamageCause () instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent lastDamageCause = (EntityDamageByEntityEvent) e.getEntity (). GetLastDamageCause ();
if (lastDamageCause.getDamager () instanceof Arrow) {
Arrow arrow = (Arrow) lastDamageCause.getDamager ();
if (arrow.getShooter () instanceof Arrow) {
e.setDeathMessage (Main.pre + "§e" + p.getName () + "§f was shot by §ePfeil §ferschuß.");
}
}
}

Something is not quite right even if no error is returned. Applying it may be wrong, but how do I do it right?

an

If (arrow.getShooter () instanceof Arrow) {

This line is wrong. The arrow wasn't shot from an arrow - it was shot from a dispenser.

instanceof BlockProjectileSource

could fit.

as

In the third "if" query:

if (arrow.getShooter () instanceof Arrow) {…}

Here you ask whether the arrow was shot by an arrow, you should rather something like:

BlockProjectileSource

to take.

PS. You can already see this in @ MrAmazing2's answer.