Counting per user

Discussion in 'Plugin Development' started by Unlucky4ever, Jan 27, 2013.

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

    Unlucky4ever

    I'm trying to make a plugin that does something after a user has been online for a certain period of time, but I'm kind of stuck on how to make it count for each individual user to a certain point.

    Like say user 1 logs in, it starts counting up, then user 2 logs in a little bit later, it still counts for user 1, but also starts another counter for user 2.

    When user 1 reaches, say 5 minutes, it does something for them. Same with user 2, but it pretty much keeps counting, so after 5 minutes, it resets, and starts to count again, and I want it to start counting when they log in, and stop when they log out (completely wipe it so that when they log in again, it's back to 0)

    I have an idea as to how this would work, but I don't know if it's correct, or really how to set it up, so can someone please help me out?
     
  2. Offline

    chaseoes

    If you're trying to track time online this is not the way to do it and will likely result in a large memory leak with large amounts of players.
     
  3. Offline

    Unlucky4ever

    It's not for tracking time online, I'm trying to have it so that when a user logs in, after 5 minutes of staying logged in, something happens, then the counter resets again, but I also want it to be user-based, so each user has their own timer.
     
  4. Offline

    _Waffles_

    You should make a hash map, with the player as the key and the time the player joined as the value. Then to check how long the player has been online do currenttime - logintime =< something ect. Hint: I use System.currentTimeMillis() and also remove the player from the list when they log out ;3
     
  5. Offline

    Unlucky4ever

    Hmm that sounds a lot better than my idea, I'll try that out :)

    Thanks :D

    EDIT: Was able to get it working perfectly, thanks again for your help :)
     
Thread Status:
Not open for further replies.

Share This Page