Snowballs and Other Projectiles

Discussion in 'Plugin Development' started by bennyty, Jan 30, 2011.

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

    bennyty

  2. Offline

    LRFLEW

    I had a similar issue making my in-progress snowball tag game.

    Code:
    @Override
    public void onEventDamageByProjectile(EntityDamageByProjectileEvent event) {
    
    }
    in the EntityListener class is called when hit by a snowball.
    Code:
    if (event.getProjectile() instanceof Snowball) {
         //Code here
    }
    Will run if the projectile is a snowball.

    Other things to know:
    Code:
    ((Snowball)event.getProjectile()) //allows you to call snowball specific functions
    Code:
    event.getDamager() //gets the person who threw the snowball
    Hope this helps
    --- merged: Jan 30, 2011 8:23 PM ---
    to answer the request's questions:

    when: when onEntityDamageByEntity() is called :p
    where:
    Code:
    event.getPlayer().getLocation()
    who:
    Code:
    event.getPlayer()
     
  3. Offline

    bennyty

  4. Offline

    highz

    You can convert an entity to player with this code

    Player p = (Player)event.getEntity();
    If you use the search function you will find all your answers
     
  5. Offline

    8e8

    First you'd want to make sure that the Entity is an instance of Player before you cast it as one. It will throw an error otherwise.
     
  6. Offline

    1337

    entity = event.getentity();
    if (entity instaceofplayer){
    //the entity is a player do stuff
    }
     
Thread Status:
Not open for further replies.

Share This Page