Is it possible to get a players play time?

Discussion in 'Spigot Plugin Development' started by Inkzzz, May 2, 2015.

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

    Resource Staff

    Is it possible to get a players online time?

    • Creative Creative x 1
  2. Yes. Count the time they are online.
    • Funny Funny x 2
    • Like Like x 1
  3. Inkzzz

    Resource Staff

    I know this way, I was wondering if there was a quicker way.
  4. I'm probably gonna add a feature to my plugin playtimerewards where other plugins can get players' playtimes so you could use that soon. The rest of the plugin can be disabled by not putting any commands in the or enabling perms and not giving any1 perms
  5. store their login time, check it against the current system time?
  6. That is the only way...
  7. The way is easy and quick
  8. gigosaurus


    There is a scoreboard objective you might be able to utilise (stat.playOneMinute), but I haven't looked at how you would go about implementing it through the bukkit API.
    • Like Like x 1
    • Useful Useful x 1
  9. I can post the code used to track it in ptr when I'm on my laptop if you like (doesn't require the plugin to be installed unlike my old suggestion)
    • Like Like x 1
  10. Store a value in YML or a database of some sort for each player. When they join, store their join time in a variable. Then, when they leave or the server stops, elapse the time they had during that play session and add that to their existing value.
    • Like Like x 1
  11. gigosaurus


  12. It's the same thing, mine is the programmatic approach of yours :p (the playOneMinute statistic in NMS is the PLAY_ONE_TICK statistic in Bukkit)
  13. gigosaurus


    Ohhhh! Well I did say I hadn't looked at how to implement it in bukkit :p Now I'm wondering why the different rate.
  14. Cldfire

    Cldfire Retired Moderator

    If you're meaning a players total play time, there are are plugins that track this and make it easy to check.
  15. If you're going to do that, you're going to have some serious lag issues. :p

    The proper way to do this would be to do this:
    On player join, check if the database already has their play time logged, otherwise, add it to the database and set it to 0. Now create a HashMap, and add the player/their UUID for the key, and set the object for that key to System.currentTimeMillis()/1000. That will create a timestamp. When a player logs out, you need to do System.currentTimeMillis() minus somehashmap.get(keyfortheplayer). Then get the amount of time the player had played in total previously, and add those two together. That will give you the amount of time the player has played the game, in seconds.

    Your welcome :)
  16. gigosaurus


    What, reading the value of an objective in a scoreboard is going to create lag issues?
  17. I demand proof. All you are doing is fetching an int field from a Map that has already been loaded with the player data (so no extra loading is required).
    You are storing redundant data and require asynchronous execution to even be able to fetch it.

    That versus a simple Map fetch; good luck, have fun.
    • Agree Agree x 2
Thread Status:
Not open for further replies.