Calling a method when a Player approaches a certain Entity

Discussion in 'Plugin Development' started by dibujaron, Mar 5, 2013.

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

    dibujaron

    Just what the title says- I need a way to detect when a Player gets within a certain radius of another Entity. The Entity does not target the player- it is nonliving. I am not sure how I should go about doing this, can anyone advise? Every way that I could think of would be extremely resource-intensive.

    Thanks!
     
  2. Offline

    Lolmewn

    First thought was PlayerMove + Distance checking - extremely resource-intensive.
    Second thought: Scheduler which checks distance every now and again.
     
  3. Offline

    willeb96

    Sorry, this is a bit off topic... But is there an event that only fires when a player actually moves and not when just looking around, or event better, when the player moves to a different block?
     
  4. Offline

    ZeusAllMighty11

    willeb96

    Just don't track the player's yaw or pitch, by simpling doing

    if(player.getFrom().getX() != player.getTo().getX()) same with y and z if necessary
     
  5. What I've done in my EnterSightBehavior, and was mentioned by Lolmewn , is using the scheduler. I don't really see a better method of doing that. Sure, it might happen that players will be able to get in and out of the range before the scheduler notices it (even though it is pretty unlikely) but it is far better than checking every player's position and comparing it the entity's.
     
  6. Offline

    willeb96

    I already do that, but isn't resource intense to do that ifstatement on every move?
     
Thread Status:
Not open for further replies.

Share This Page