Solved Snowballs?

Discussion in 'Plugin Development' started by Theodossis, Sep 27, 2012.

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

    Theodossis

    How i can check if the snowball hits the player?
    Thanks,
    Theodossis
     
  2. Offline

    makskay

    Not sure if this works for snowballs as they don't inflict "damage" on hit per se, but every other projectile that hits an entity throws an EntityDamageByEntityEvent. I'd start by listening for EntityDamageByEntityEvents and checking to see if the damager is a snowball and the damaged is a player.
     
  3. Offline

    SnowGears

  4. Offline

    Theodossis

    Thanks :)

    But how i can use it? If snowball hits the player?
    Help,
    Theodossis

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  5. Offline

    SnowGears

    ProjectileHitEvent is fired when a projectile hits something. So you know it has already happened. Just check if the projectile ( event.getEntity() ) is an instanceof a snowball. Then do whatever you need

    EDIT: also check if the thing it hit was a Player
     
  6. Offline

    Theodossis

    Ok thanks :)
     
  7. Offline

    Muddr

    you can use EntityDamageByEntityEvent with snowballs. here's some code I did for someone that made it cause damage to a player with snowballs.
    Code:
    @EventHandler
    public void EntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
        Entity entity = event.getEntity();
        DamageCause cause = event.getCause();
        Entity damager = event.getDamager();
     
        if (cause == DamageCause.PROJECTILE && entity instanceof Player && damager instanceof Snowball) {
            Player damagee = (Player) entity;
            Snowball sb = (Snowball) damager;
            Entity shooter = sb.getShooter();
            if (shooter != null && shooter instanceof Player) {
                Player player = (Player) shooter;
                damagee.damage(50, player);
            }
        }
    }
     
    Theodossis likes this.
  8. Offline

    Theodossis

    Thanks you so much!
     
Thread Status:
Not open for further replies.

Share This Page