getTargetPlayer

Discussion in 'Plugin Development' started by goodstuff20, Sep 13, 2013.

Thread Status:
Not open for further replies.
  1. Hi guys,

    just wanted to know if its a simple way to find out instead of p.getTargetBlock p.getTargetPlayer or so. All help appreciated (as always)!

    Cheers
     
  2. Offline

    1Rogue

    Um, what is the question exactly?
     
  3. I jus wanna know if there exists a command for the target player (the player another player is lookin at)
     
  4. goodstuff20
    As far as I know, no. You can get a list of blocks which are between player and player target block, then loop through the block list, and check if any of those block locations have a player nearby (or at exact same location).

    Try to do it on your own, if you can't figure it out, tag me, and I'll show you some example code.
     
  5. public static Player getTargetPlayer( Player p )
    {
    Player target = null;
    for(Entity ent : player.getNearbyEntities(5,5,5) ) // 5 = player reach(?)
    {
    if( ent instanceof Player ){
    if( p.hasLineOfSight(ent) && (target == null || p.getLocation().distance(target.getLocation()) > p.getLocation().distance(ent.getLocation()) )
    {
    target = (Player) ent;
    }
    }
    }
    return target;
    }
    Edit: This code is untested and not guaranteed to work!
     
  6. PeterK and Assist thx guys - i was just wondering if there was a command

    cheers
     
Thread Status:
Not open for further replies.

Share This Page