Solved ProjectileHitEvent how to get the wounded entity?

Discussion in 'Plugin Development' started by InflamedSebi, Apr 25, 2013.

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

    InflamedSebi

    i need to listen if an arrow hits a block or an entity ...
    the block hit is working, but if i shoot at an entity it will trigger the block effect (additionally)... and i can't find a way to get if the arrow hit an entity in the ProjctileHitEvent ...

    Code:java
    1.  
    2. public void onProjectileHit(ProjectileHitEvent evt) {
    3. Projectile projectile = evt.getEntity();
    4. if (!plugin.watchlist.containsKey(projectile)) // arrow on watchlist?
    5. return;
    6. Arrow arrow = (Arrow) projectile;
    7.  
    8. logger.log("Entity: " + evt.getEntity(), 4); // <-- tells me "Craftarrow" not the wounded entity
    9.  
    10. Entity entity = ?????
    11.  
    12. if(entity == null){ // wounded entity?
    13. //block hit
    14. } else {
    15. //entity hit
    16. }
    17.  
    18.  
    19. }
     
  2. Offline

    xmarinusx

    Perhaps you can use EntityDamageByEntityEvent and then check if the damager is an Arrow?
     
  3. Offline

    InflamedSebi

    but I have to use the ProjectileHitEvent() and i have no idea, how to get the corresponding damage event ...
     
  4. InflamedSebi
    That code can be done with EntityDamageByEntityEvent, just check if attacker is instanceof Arrow then cast but you also have access to getEntity() which is the victim of the arrow.

    You can use ProjectileHitEvent to detect if it's a block hit only after checking if the other event triggered... how you're going to sync those is up to you.
     
  5. Offline

    InflamedSebi

    Digi
    Yeah the sync is the problem ... i dont know how much time is between those events ... and if multiple players use bows at the same time, they will interfere each other :/
     
  6. You can easily find out with console messages (in-game messages are not that reliable), see which one triggers first.
    And if you design it properly they won't interfere as you are not limited to storing one thing at a time.
     
Thread Status:
Not open for further replies.

Share This Page