how to make a afk kicker??

Discussion in 'Spigot Plugin Development' started by Aurorion, Jun 1, 2015.

  1. Hi!
    So I was wondering how to make it so when players are afk for lets say 5 minutes they get kicked.
    I looked on google but couldn't find usefull code or threads.
    If someone could help me in the right direction then that would be great:D

    Have a nice day:)
  2. Inkzzz

    Resource Staff

    When the player moves save the player and location, in 5 minutes, check the location of the player, if it's equal to the "afk" location, kick them.

    You want to use HashMaps
  3. A pretty bad way but a way after all is:
    save the position on playermoveevent chatevent and any other events that could indicate a player is not afk anymore and the timestamp.
    Then maybe with a runnable or something just check if someone has not been active for the last 5 minutes.
  4. @SubSide 's Idea isn't so bad. I will try to explain it.

    For each events you think is indicating a player isn't afk, save the position and the timestamp.
    You can save it in a HashMap which would look alike this: HashMap<UUID, HashMap<Location, Long>>
    Or if you are a little bit more advanced in java, try to create an object which contains the following informations: UUID, last Location, Timestamp

    You can get the timstamp like this:
    Code (Text):
    This isn't a linux timestamp but it is similar.
    This timestamp indicates the milli-seconds which has passed since midnight, January 1, 1970 UTC.

    Then you will have a reapeating task, which checks all players every 10 seconds (f.e.) .
    If the current timstamp is greater than the old timestamp + 5 minutes (300000 millis), the player is afk and you can kick him.

    If you have other questions , just ask me here or per pm.
  5. I never liked the playerMoveEvent, bad experience with it ;D

    You don't need the location though.
    HashMap<UUID, Long> would do the trick.
    • Agree Agree x 1
  6. I neither like this event, but it's useful and it isn't so buggy in the latest spigot versions.

    You are right with the location :D You don't even need it.
    • Like Like x 1
  7. Thank you for the replies, I am starting to learn Java (mostly bukkit/spigot) bit by bit and have to google some stuff you guys told me but I am sure I will figure something out.
    Will reply as soon as possible if I need help
  8. use essentials AFK kicker?
  9. I'm not using essentials
  10. Use the built in inactivity kicker? player-idle-timeout in

    Not like any custom ones are hard to bypass either, so why waste the time when there's something built in?

    • Agree Agree x 1