Solved PlayerMoveEvent that requires player to press movement keys

Discussion in 'Spigot Plugin Development' started by Nemo_64, Jun 30, 2021.

  1. I wanto to know what players are afk. To do this I listen to several events, AsyncPlayerChatEvent, PlayerInteractEvent and PlayerMoveEvent and save the time when the event fires in a hashmap. The problem is that PlayerMoveEvent also fires when the player is moved by watter. Is there any other event that requeres the player to press a key to move?
    Thanks for the help
     
  2. The key cannot be checked.
     
  3. Unfortunately (you have no idea how sad developers are about this...) you can't check for key presses at all, only get the events that fire from them (if there are any).
     
  4. i know how sad it is, it's not the first time this gives me issues.
    I could listen for the serverbound movement packets but it seems like they are sent even if the player is still,
    (Link to the quote)
    So how could I know if the player is moving or it the player is sending them periodically? Check if the coords are the same as the last packet?
     
  5. no? PlayerMoveEvent fires whenever you move. just your coding mistake
     
  6. I don't understand you. PlayerMoveEvent also fires when the player is pushed (watter for example). Players can make an antiafk machine and bypass my afk detection system. Thats why I need to know how the player moved
     
  7. Being pushed is of course normal if you recognize it. Because this is also judged by movement.
     
  8. As @chochoco4777 said, there's no way to check if player presses a key. The thing is that all the movement, even knockback and water pushing, is handled client-side. Therefore, you can't distinguish key press from "natural" movement - those are the same packets.
     
  9. They're right - sry, but this is unfortunately a losing battle...
    That's eventually one of the main goals for AntiCheat plugins, but for now there's no way to know...
     
  10. When being pushed by water a player's head doesn't move, how about you check for yaw/pitch instead if xyz position?
     
  11. I thought that for a moment but didn't want it to be true. Guess I'll just use PlayerMoveEvent
    I could store in a list and every x ticks the position of the player and if it starts to repear a pattern then assume he is afk but seems to complex

    Its true that anti afk machines can't change a players rotation. But what if the player is just walking in a straight line? Mining for example. The amount of checks sems too much for an event that runs as much as the PlayerMoveEvent
     
  12. What you're talking about is one of the hardest problems AntiCheat plugins face - be VERY careful with that.
    Recognizing patterns isn't as easy as you think...
    Our brains can do it because they run a few million times faster than a computer and billions of years of evolution along with multiple sensory systems working together to achieve that - computers need to learn this from 0.
    It will be unbelievably difficult - good luck.
     
  13. What about checking if either of player-occupied blocks (blocks at player's [X, Y, Z] and [X, Y+1, Z]) are a running water blocks? To prevent things like long boat travelling, just check whether the player is passenger of anything.
     
  14. And what about pistons? And cacti? And lava? And block creation? And player bumping?
    It's not that easy... There are too many variables to consider, and even if there aren't each variable can have millions (if not billions) of scenarios.

    If you want to do it go ahead - all the more power to you!
     
  15. I know, guess I'll just go with player move event