Best way to get player's playing time

Discussion in 'Plugin Development' started by Jozeth, Jul 17, 2014.

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

    Jozeth

    Is there an easy way to receive the player's playing time or will I have to create my own timers, etc?

    The most obvious way would be to count up in seconds (or minutes) and stop it when the player logs off, but surely there's a better way?
     
  2. Offline

    Gater12

    Jozeth
    Save current millis when the player joins.
    Get current millis when the player leaves.
    Compare the two.
    ???

    $PROFIT$
     
    Jozeth likes this.
  3. Offline

    Flamedek

    Jozeth You could use that System.currentTime-something method when they log in to mark their starttime.
    Then compare that to the time when they logout or when the information is called and calculate the time inbetween.
     
    Jozeth likes this.
  4. Offline

    pluginsbyjason

    By default, make each user's play-time 0.

    When a user logs in, save their start time using System.currentTimeMillis() and when the user logs off, save their end time with System.currentTimeMillis(). Subtract end from start time and add it to their total play-time.
     
    Jozeth likes this.
  5. Offline

    _LB

    Or you could just use the playtime statistic that the server tracks for you...
     
  6. Offline

    Jozeth

    Guessing the "PLAY_ONE_TICK" is it?
     
  7. Offline

    _LB

    Yes, that's exactly it. Just divide it to your preferred unit of measurement and you're good to go.
     
    Jozeth likes this.
Thread Status:
Not open for further replies.

Share This Page