Get the Shooter and Hitted of Snowball?

Discussion in 'Plugin Development' started by Tauryuu, Mar 19, 2012.

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

    Tauryuu

    I tried looking in ProjectileHitEvent but it only gives me the option to get the Shooter. I'm trying to get the shooter of a snowball and the player who got hit by that Snowball.

    Thanks in advance. :)
     
  2. Offline

    Prgr

    Does a snow ball cause damage?
    You might need to do a entity damage event:
    Code:java
    1.  
    2. @EventHandler(priority = EventPriority.LOW)
    3. public void onDamage(final EntityDamageEvent event) {
    4. if(event.getCause() == DamageCause.PROJECTILE){
    5. if(event.getEntity() instanceof Player){
    6. Player player = (Player) event.getEntity();
    7. player.getName();
    8. }
    9. }
    10. }
    11.  

    Then again I don't know how you want to pair that up with the Snowball Check
     
  3. Offline

    Tauryuu

    Snowballs don't cause damage. :/
     
  4. Offline

    theguynextdoor

    Actually they do.

    Code:java
    1. @EventHandler
    2. public void onEntityDamage(EntityDamageEvent e) {
    3. if (e instanceof EntityDamageByEntityEvent) {
    4. Entity attacker = ((EntityDamageByEntityEvent) e).getDamager();
    5.  
    6. if (attacker instanceof Snowball) {
    7. Entity damaged = e.getEntity();
     
  5. Offline

    Father Of Time

    I find it easiest to handle this from an EntityDamagedByEntityEvent:

    Code:
        @EventHandler
        public void onEntityDamageByEntity ( EntityDamageByEntityEvent event )
        {
            Entity damagedentity = event.getEntity();
            Entity damagerentity = event.getDamager();
         
            if( damagerentity instanceof Snowball )
            {
                Snowball snowball = (Snowball)damagerentity;
                Player shooter = snowball.getShooter();
                // Code here for when you are hit by a snowball
            }
        }
    in the above example the shooter is known as "shooter" and is a player, the entity that was shot is known as "damagedentity" and is an entity, but of coarse you can cast things as you need...

    I hope this helps, good luck!
     
    Milkywayz and Tauryuu like this.
  6. Offline

    Milkywayz

    Helped a lot, thanks so much.
     
  7. Offline

    Father Of Time

    I'm happy to be of assistance, good luck with the remainder of your project! :D
     
Thread Status:
Not open for further replies.

Share This Page