Is there an alternative to a PlayerHitEvent?

El
7

I wanted to ask if anyone in Java Minecraft knows how to kill a player who was beaten by another?

Person A: If the person hits the person B, a command should be executed
Person B: If you are hacked, there will be no damage and the command will be sent.

Is that possible somehow?

an

This works with the EntityDamageByEntityEvent.

e.getEntity (); = The player who suffered the damage.

e.getDamager (); = The player who caused the damage.

Of course you have to check whether the entity was a player and then cast to player if necessary.

Documentation: https://hub.spigotmc.org/...Event.html

El

So I don't understand it, as soon as he gets damaged, the command '/ friend add "+ PLAYER' should be executed by whoever damaged him. Only how I should build it is the other question.

an

What exactly do you fail at?

How do you know events?

You also know how to cast the entity to player, and then e.g. Determine the name of the player, don't you?

So that the player executes the command, you can use one of the following:

player.chat ("/ friend add" + damagedPlayer);
player.performCommand ("friend add" + damagedPlayer);
Bukkit.getServer (). DispatchCommand (player, "friend add" + damagedPlayer);

El

This is embarrassing on my part. Uff thank you: 3

an

Got it done? ^^

El

Yep!

an

I'm happy: DD

Please: 3