Determine what caused PlayerMoveEvent

Discussion in 'Spigot Plugin Development' started by CraigParton, Aug 7, 2018.

  1. Hello all. I have implemented an AFK feature in my block protection plugin. It sets a player as AFK if they have not moved or run a command for five minutes. There is a chat notification and their color dims in the tab list. It also sets them as sleep ignored, meaning they don't need to be in a bed for the server to advance to day, as long as everyone else is sleeping. Everything is working fine, but there's something I want to eliminate and I can't figure out how.

    Being bumped by an entity triggers PlayerMoveEvent, which causes the player exit AFK mode. Normally I wouldn't care, but now that I've added the sleeping exemption it becomes annoying if someone AFKs in an entity heavy area. I only want AFK mode to exit if the player actually does something. I guess what I'm looking for is a MoveCause, similar to TeleportCause in the EntityTeleport event. But no such thing exists. There are vehicle collision events, but no entity collision events. I've looked through all the events in the online javadoc and I don't see anything that might tell me what I need to know. Anyone have any ideas? Thanks in advance.
     
  2. If I remember right within the event system there is nothing you can use to detect this, however there is a packet sent when the player tries to move by their own.
     
  3. Per default, the server more or less trusts the client to not lie about movement. Movement is processed on the client, then the result (ie the position) is send to the server. So you can't know what caused movement. It might also be that the client should have moved but didn't (ie walking against flowing water with a perfectly matched walking speed). So, it's complicated.
     
  4. One thing I saw on an anti afk plugin was to detect if they haven't moved their mouse. That way any pushing / afk machines, don't affect the result. While it could put people as afk when they aren't, it still seems like a good choice.

    Simply just check if the yaw/pitch changed and if it hasn't, they are probably afk.

    Also the above posts are correct in the fact of the client not sending much about movement.
     
    • Like Like x 2
  5. Thank you everyone, excellent info. I wasn't aware of the fact that the client did all the movement processing, so it makes sense the server doesn't know WHY the client moved, only where they moved. Given the suggestions I think the easiest one is just checking the yaw/pitch. Even though someone might move around with WASD and not trigger the AFK detection, why would they? They can't really do anything useful without moving the mouse. Thanks again!