Get Last Damager when player dies of fall damage

Discussion in 'Plugin Development' started by LegoPal92, Sep 14, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    LegoPal92

    So, as the title says, I am trying to get the last damager, which in this instance I know will be a player, when the player dies of fall damage. I know this is possible, or at least it should be, because of the context of the default message when a player dies of fall damage. eg: LegoPal92 fell to his death trying to escape Bob.

    What I am trying to do is get Bob. How would I go about doing this? I have looked on google, and I found nothing of help, I may have searched the wrong thing, but I don't think so.
     
  2. Offline

    adam753

    You can use player.getKiller(), but be aware that it can return null (if the player has no apparent killer). I've never used it myself so I don't know if it will return null when you want to use it, but I don't see any reason why it should be different from the death messages.
     
  3. Offline

    LegoPal92

    I think that would return null, because what is actually killing the player is the fall damage.

    Shameful bump.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. Offline

    UnlikeAny

    LegoPal92
    I spend a lot of time trying to figure out how to do it without logging it yourself. I've searched CraftBukkit source code and if I fully understood, then you simply can't.

    You could:
    1. Listen for EntityDamageByEntityEvent, log it, and if the player dies use it. Also delete log after x amount of time.
    2. Parse it from death message.
    If you are going to parse then it should look something like this:
    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent e) {
    3. if (e.getEntity().getLastDamageCause().getCause() != DamageCause.FALL)
    4. return;
    5.  
    6. String[] parsed = e.getDeathMessage().split("by ");
    7.  
    8. if (parsed.length != 2)
    9. return;
    10.  
    11. Player p = Bukkit.getPlayerExact(parsed[1]);
    12.  
    13. if (p != null) {
    14. // Do something.
    15. }
    16. }
     
    LegoPal92 likes this.
  5. Offline

    LegoPal92

    UnlikeAny
    I was afraid of that. I didn't want to have to make my own system for this, but if I have to I will, thanks for taking the time to help out, I greatly appreciate it! Here, have a diamond. [diamond]
     
Thread Status:
Not open for further replies.

Share This Page