Solved EntityDamageByEntity and EntityDamage

Discussion in 'Plugin Development' started by Quantum64, Mar 15, 2014.

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

    Quantum64

    So there have been several threads about this, none of which have had satisfactory answers. If I have an EntityDamageEvent listener set up, and an EntityDamageByEntityEvent listener set up, both fire when an EntityDamageByEntityEvent is called, which, I obviously don't want to happen, but when I check if EntityDamageEvent is an instanceof EntityDamageByEntityEvent, even if it is, the actual EntityDamageEvent. even though is extends EntityDamageByEntityEvent, event is not.

    So at this point I am at a loss of how to listen for both entity damage to players and non entity damage to players, without the entity damage firing twice.
     
  2. Offline

    ShadowLAX

    Quantum64 Just use the EntityDamageEvent. It gets fired when an entity damages and when a non entity damages.
     
  3. Offline

    Quantum64

    ShadowLAX Then I cannot get the damager of the player, or if it was really an entity that damaged the player, both crucial to my plugin.
     
  4. Offline

    ShadowLAX

    Quantum64 You can use the getCause() method to get the cause of the entities damaging. If you wish to get the entity (if it was indeed an entity that damaged the player), just cast it to the appropriate entity.
     
  5. Offline

    Quantum64

    ShadowLAX Ahh, I did not consider this, but there is still a problem, I need to actually GET the entity, for instance if the damager is a player, I need to be able to access that player's object.
     
  6. Offline

    ShadowLAX

    Quantum64 I see. In that case, for the EntityDamageEvent, just use an if/else statement to check if the damage is not from an entity. That way, only the EntityDamageByEntityEvent is used.
     
    Quantum64 likes this.
  7. Offline

    Garris0n

  8. Offline

    Quantum64

    Oh my gawd your a genious. I need to test this now.
     
  9. Offline

    Garris0n

    I'm not sure if it will even help with what you're doing, I just realized I never read the OP. Either way it's something else to play with I suppose...
     
  10. Offline

    Quantum64

    Two working solutions right on top of each other... Nice!

    Garris0n That does return the EntityDamageByEntity by the way.
     
    Garris0n likes this.
  11. Offline

    Garris0n

Thread Status:
Not open for further replies.

Share This Page