Detect Player stops moving

Discussion in 'Plugin Development' started by javaguy78, Sep 26, 2012.

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


    I am trying to detect player movement. I am capturing PlayerMoveEvent to tell if the player is moving, but I can't find an event that fires when the player stops moving. The event does stop firing, but how do I detect that it stops firing? I was thinking of using the difference between xy and z coordinates in getTo() and getFrom(), but if the player stops moving, the event isn't fired, so the numbers aren't identical until the player looks around.

    Is there a way to detect the player has stopped moving before they start moving their head?

    for example, if a player is running and opens their inventory mid stride, the PlayerMoveEvent doesn't fire, so the to and from coordinates are still different. am I making any sense?
  2. Offline


    Instead of using player move event, schedule a task to check a player's location
  3. Offline


    Keep an updated Map of <playerName, location> and every X seconds check if the location has changed.
  4. Offline


    I was gonna say something clever, but then thought "Oh sh*t this won't work, silly me!"
    Some great ideas are above.
    adde likes this.
  5. Offline


    I tried this. I had two schedules running, the first checked the player's position and stored it. The second took the position again and compared it to the first. I don't know how the schedulers work in the code, but it seemed that these schedules got loaded into two different threads and slowly lined up, so I was getting exceptions when both schedules tried to write to the var I setup to track location at the same time. So, I tried to think of a way to do it without schedules.
  6. Offline


    Put the thingy in the same schedule should work.
    Basically, it'd look like this:
    check the locations against each other
    add the location to the map.
  7. Offline


    Did this. I use the previous location to do my calculations and then store the new location after doing calculations! Thanks

    I'll remember this for next time I need two schedules to be dependent on each other. Thank you.
  8. javaguy78 This is not only for two Runnables depending on each other, this is about thread safety in general (so either minecrafts main thread vs. your async task or one async task vs. another async task or both or more...). Please read what I linked.
  9. Offline


    V10lator I totally understand what you mean. The the schedules that need to be Sync are and I still have a few that are ASync because they're threadsafe
Thread Status:
Not open for further replies.

Share This Page