Jump to content

[1.8] Get source of damage when player is attacked


Jedispencer21

Recommended Posts

LivingHurtEvent and the various attack events all have a DamageSource field which has the getSourceOfDamage() method - that returns the entity ultimately responsible for causing the damage, such as the shooter of an arrow or melee attacker.

 

You'll want to double-check that the event is firing on the client side - for non-players, these are server only events.

Link to comment
Share on other sites

You could do that and print the result to the console, or use your logger to print a message and it will automatically let you know which side it printed from.

 

But I'm 90% sure that those specific events also get called on the client when the entity involved is a player, but maybe that is only if the attacking entity is a player... can't remember off the top of my head, which is why I suggested testing it for yourself.

 

If it turns out that LivingHurtEvent is only called server side when attacked by mobs (which, now that I think about it more, I believe is the case), you will have to send a packet.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.