Solved Snowballs?

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

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


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


    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


  4. Offline


    Thanks :)

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

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


    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


    Ok thanks :)
  7. Offline


    you can use EntityDamageByEntityEvent with snowballs. here's some code I did for someone that made it cause damage to a player with snowballs.
    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


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

Share This Page