[CODING] [HELP] Online Time Plugin

Discussion in 'Spigot Plugin Development' started by WailTosti, Jun 20, 2016.

  1. Hello people,

    I will code this

    First i will thank you for watch this thread i maked this thread because,
    I don't know how i can make this:

    - /time command and then you can see how long you are on the server played or online
    Anyways i can make the command but i don't know how i can add that (The online time from a player)

    Please help.
     
    • Informative Informative x 1
  2. What did you try? We're not going to spoonfeed a solution
     
    • Agree Agree x 1
  3. So first you need a file to store the time( you could use the config) after I guess you could have a hashmap with player and time. Each time a player join add him to the map and have a timer that increments the time by one each 1 second and when the player quits, write the time in the file.. That's all xD.
     
  4. Oke, Can this code in a CMD_Class because i make a plugin with more classes
     
  5. There's no reason that there would be a problem with puttin it in another class.
     
  6. I don't understand :)
     
  7. Okay so first you have to sync to an NTP server
     
  8. Yeah I meant hés message t not how to do it xD
     
  9. You can get the time a player has played in ticks using the bukkit api and then convert it.
    Code (Text):
    int ticksPlayed = player.getStatistic(Statistic.PLAY_ONE_TICK);
     
    • Like Like x 1
  10. You can call getFirstPlayed on the player, which will return a long at the time the first joined the server.
     
    • Like Like x 1
  11. You can't get the time the player spent online from that.
    Doing System.currentTimeMillis() - player.getFirstPlayed() you get the time passed between the two dates and it doesn't mean that the player has always been online in this long period of time.
     
  12. Thanks Grimerlin i will try this
     
  13. MiniDigger

    Supporter

    don't use that, use the solution he provided above:
    Code (Text):
    int ticksPlayed = player.getStatistic(Statistic.PLAY_ONE_TICK);
     
  14. I just recently found out about the Statistic methods. When were these added? 1.9?
     
  15. Choco

    Moderator

    Probably when statistics were added :D Who woulda thunk? Isn't that strange
     
  16. Statistics were always there in game. I don't recall seeing the Statistic api for spigot until 1.9 came out ._.
     
  17. I think the Statistic api has always existed. I just checked the oldest spigot.jar (1.7) that I have and it has it.
     
  18. MiniDigger

    Supporter