[Help]Find who launched projectile

Discussion in 'Plugin Development' started by dajako, Aug 12, 2013.

Thread Status:
Not open for further replies.
  1. Code:
        public void grapple(ProjectileHitEvent event) {
            if(event.getEntity() instanceof Fish){
    }
    I need to find out who the player who launches the projectile is.

    Do I need to setup a PlayerInteractEvent event to get this? If so how do I transfer the information from event.getPlayer(); to the ProjectileHitEvent so that I can use the player there?

    I really hope this makes sense because I feel like cannot explain this any better. :(
     
  2. Offline

    werter318

    event.getEntity() returns the Projectile! so you can do event.getEntity().getShooter();
     
  3. Ah, lol. I forgot about that! Thanks! :)

    Ah.
    Player player = event.getEntity().getShooter(); Mismatch cannot convert from living entity to Player.

    Any ideas to how I can fix that?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  4. Offline

    Bammerbom

    dajako
    if(event.getEntity().getShoother() instanceof Player){
    And then i think you can cast it. (I don't have eclipse here. Not tested)
     
  5. I don't know anything about casting, could I get some code for that?
     
  6. Offline

    The_Doctor_123

    Code:
    Player player = (Player) event.getEntity().getShooter();
    
     
  7. Offline

    Bammerbom

    dajako
    Code:
    if(event.getEntity().getShoother() instanceof Player){
        Player player = (Player) event.getEntity().getShooter();
    }
    Ps. Casting is the (Player).
     
  8. Thanks! :)
     
Thread Status:
Not open for further replies.

Share This Page