How To Check If A Player Is Moving In Bukkit

Discussion in 'Plugin Development' started by Bench3, Nov 9, 2012.

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

    Bench3

    Hi guys,
    I was wondering if anyone knows how to check every half a second or so if a player is moving and then put them into a map (which I can do!).

    Thanks in advance,
    Ben :D
     
  2. Offline

    Retherz_

    one sec

    Bench3
    onPlayerMoveEvent

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

    Bench3

    Yeah i understand that, but how would I work out wether he is just walking and then when he stops he gets removed from a map.
     
  4. Offline

    Retherz_

    Im new to java but maybe onPlayerMoveEvent cancel > ur code
     
  5. Offline

    APlusMalware

    If you wanted to check every half second, you would set up a repeating task with the scheduler, and have it loop through every player and check if "player.getVelocity().length() == 0", I believe.
     
  6. Offline

    cman1885

    What are you trying to do? There's probably a better way.
     
  7. Offline

    Slipswhitley

    Well have you ever seen a Event Listener like
    Code:
    public void onDoingNothing(PlayerDoingShitallEvent Event)
    I believe he is right when he says add a repeating task.
    Implement this method into your plugin and then add "startTimer();" to your onEnable method.

    Code:
    public void startTimer() {
            getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
     
                  public void run() {
                      for(Player player : getServer().getOnlinePlayers()) {
                          if(player.getVelocity().length() == 0) {
                              if(yourMap.containsKey(player)) {
                                  yourMap.remove(player);
                              }
                          }
                      }
                   
                  }
                }, 10L, 10L);
        }
    Also because PlayerMoveEvent picks up all Movement including mouse movement you will need to check that the players velocity isn't equal to 0 before you add them to the hashmap.
     
  8. Offline

    Hoolean

    Heyyy.... XD
     
  9. Offline

    cman1885

    I meant what is the goal...
     
Thread Status:
Not open for further replies.

Share This Page