How to work with entity death?

So, I need send two players a message where first kill second. I found DestructEntityEvent.Death, try to realese it and… nothing.
@Listener
public void onPlayerDeath(DestructEntityEvent.Death event) {
logger.info(“It works!”);
Player killer = event.getCause().first(Player.class).get();
Player killed = (Player) event.getTargetEntity();
killer.sendMessage(Text.of("Killer: " + killer.getName()));
killer.sendMessage(Text.of("Killed: " + killed.getName()));
}
Please, help, guys.

Use EntityDamageEvent, there is a method within that event called “willCauseDeath” which you can check before you process the event.

Eclipse does not know that event. It’s even absent in list variable classes. Maybe you mix up this class from Bukkit?

Sorry got Entity and Damage mixed up

@Listener
public void onPlayerDeath(DamageEntityEvent event) {
	logger.info("It works!");
	/*Player killer = event.getCause().first(Player.class).get();
	Player killed = (Player) event.getTargetEntity();
	killer.sendMessage(Text.of("Killer: " + killer.getName()));
	killer.sendMessage(Text.of("Killed: " + killed.getName()));*/
}

Unfortunately, it does not work again… maybe I misunderstand the event, as I understand it, it fires every time someone takes damage.

The event fires whenever an entity takes damage, however you can check if the damage that is fired with the event will cause a death of the entity. If true then it is effectivly a EntityDeathEvent

Based upon your code, you should be getting a message of “It Works!” whenever the event fires, when you say “it does not work again” do you mean that that message does not appear or something else? info is needed

Actually, yes, it message doesn’t appear in server console.
UPD: EntityDeathEvent does not exist.

I never said that event existed, i said you are effectivly creating that with that check.

As the event is not firing (as the message does not appear) it means that you have not registered the event listener. Are you listening to the event within your main (with @plugin) or external file?

I use it in file with @Plugin annotation.

Ok, is your plugin actually launching? you can check by putting a console message within the following

@Listener
public void onEnable(GameStartingServerEvent){
    System.out.println("Booting");
}

And then check the log for that message

I find the solve of problem. Eclipse saved plugin snapshots to invalid folder :smiley: