What event is used to test if a player deals damage?

Discussion in 'Plugin Development' started by Zankz, Nov 21, 2014.

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

    Zankz

    Question in title.
     
  2. Offline

    Creeoer

    Zankz
    There is no event, try using the entitydamagebyentity event or entity damage event and use one of the entity methods to return the player that deals the damage. I think it's e.getDamager();
     
  3. Offline

    Zankz

    I have tried this but it did not work :(
    What code did u use for this?
     
  4. Offline

    mythbusterma

    Zankz

    public void onEvent(EntityDamageByEntityEvent event)

    I don't understand what's difficult about this.
     
  5. Offline

    Creeoer

    Zankz
    public void entityDamager(EntityDamageByEntityEvent e) {
    Entity killer = e.getDamager();

    }
    Just check to make the killer is an instanceof a player if you're doing anything player specific.
     
  6. Offline

    Zankz

  7. Offline

    Creeoer

    Zankz
    You're getting the entity which I believe gets the "vicitim" or defender. If you're trying to get the entity that deals the damage just use e.getDamager();
     
  8. Zankz
    First check that the entity doing/receiving the damage is a player. If not, you'll receive errors. Then, do anything player-related.
     
  9. Offline

    teej107

    Zankz
    What if a entity doing the damage was an Arrow? Good luck trying to make a Player out of an Arrow.
     
    SirMonkeyFood likes this.
  10. Offline

    hellboyPS

    That would be arrow.getShooter().
     
  11. Offline

    teej107

    Yes, however that method is not getting called. And you have to make sure that the entity is a projectile to even call that method. My what if was an example of telling what would happen if you tried to blindly cast an Entity to a Player. You can substitute Arrow out for any other entity in my what if example.
     
  12. Offline

    mastermustard

    make sure you use an if statement to check that the entity is a player and then you can proceed with the code if it is
     
Thread Status:
Not open for further replies.

Share This Page