Solved ProjectileHitEvent - If Player is hitted

Discussion in 'Plugin Development' started by ostylk, Mar 25, 2014.

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

    ostylk

    Hi,
    Does someone know how to get if a player is hitted by an egg???
    Example Code:
    Code:java
    1. @EventHandler
    2. public void onHit(ProjectileHitEvent e){
    3. if(e.getEntity() instanceof Egg){
    4. if(/*Here if player is hitted*/){
    5. Location l = e.getEntity().getShooter().getLocation;
    6. Location l1 = /*The player who is hitted*/.getLocation;
    7. e.getEntity().getShooter().teleport(l1);
    8. /*THe player who is hitted*/.teleport(l);
    9. e.setDamage(0.0);
    10. }else{
    11.  
    12. }
    13. }
    14. }

    thx for everybody who answers!

    ostylk
     
  2. ostylk Try using EntityDamageByEntityEvent instead.
     
  3. Offline

    ostylk

    AdamQpzm
    Can you post an example code?
     
  4. Offline

    Maurdekye

    ostylk Use an EntityDamageByEntityEvent, and check if the damaging entity is an egg, and the damaged entity a player. And no, I'm not going to post code for you. This isn't that kind of forum.
     
    ostylk likes this.
  5. Offline

    JeZPvP

    Code:
        @EventHandler
        public void onHit(EntityDamageByEntityEvent e) {
            if(e.getDamager() instanceof Projectile) {
                Projectile proj = (Projectile) e.getDamager();
                    if(proj.getType() == EntityType.EGG) {
                        if(proj.getShooter() instanceof Player) {
                            Player shooter = (Player)proj.getShooter();
                            if(e.getEntity() instanceof Player){
                                Player hit = (Player) e.getEntity();
                                Location l = shooter.getLocation();
                                Location ll = hit.getLocation();
                                shooter.teleport(ll);
                                hit.teleport(l);
                                e.setDamage(0.0);
                               
        }else{
           
        }
        }
        }
        }
    }
    There you go, EntityDamageByEntityEvent is better than your Event.
     
    ostylk likes this.
  6. Offline

    ostylk

Thread Status:
Not open for further replies.

Share This Page