DamageByEntityEvent being called without damage loss

Discussion in 'Plugin Development' started by Fedmand, May 24, 2014.

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

    Fedmand

    Hello there!

    For some reason the EntityDamageByEntityEvent is not only being called when the player or entity takes damage. It's being called pretty much like the interact event. Am I the only one having this problem? Is there any way I can tell if the player/entity was actually taking damage? Or is there another sulotion?

    Thanks alot
     
  2. You can use the EntityDamageByEntity to do this.
    here is some example code
    Code:java
    1.  
    2. @EventHandler
    3. public void onDamageByEntity(EntityDamageByEntityEvent event){
    4. if(event.getEntity() instanceof Player){
    5. if(event.getDamager() instanceof Zombie){
    6. //If player is damaged by zombie
    7. }
    8. }
    9. }
    10.  
     
  3. Offline

    mythbusterma

    EntityDamageByEntity's parent class specifies a method called double getDamage() doing a simple if(event.getDamage () > 0.00001) would provide what you need.
     
  4. Offline

    rsod

    Nope. There was some hacky method with something I don't really remember, noDamageTicks or something like that, to detect when an entity actually receiving damage...
     
  5. Offline

    mythbusterma

    That may be, but I don't see any reason my far simpler solution wouldn't work.
     
  6. Offline

    rsod

    The problem is that e.getDamage() will return correct amount of damage that player sending.It can be 10, 100, 100500, but will not be handled.
     
  7. Offline

    Fedmand

    The problem is that yours isn't working. The event is still reading the damage amount even though it's not actually dealt.

    rsod Maybe you could help me find this sacret noDamageTicks thing?
     
  8. Offline

    mythbusterma

    Set the priority to monitor and check to make sure neither the sender nor reciver is null and check for damage. If you do all that and you're still getting issues where it's not doing anything then report it to bukkit, but I don't see any reason for it not to. My money is on whenever you used it last you didn't set the listener priority to monitor.

    TLDR: make sure getEntity () and getDamager() aren't null, set EventPriority.MONITOR
     
  9. Offline

    Fedmand

    I found the sulotion!
    http://forums.bukkit.org/threads/will-entitydamagebyentityevent-be-cancelled.269304/#post-2499256
    Thank you for your help :D
     
Thread Status:
Not open for further replies.

Share This Page