1.14.4 How to make a Playtime Plugin

Discussion in 'Spigot Plugin Development' started by Th3Wh1teG0d, Jan 16, 2020.

  1. Exists a tutorial that shows me how to make a playtime plugin?
     
  2. What is a
    ?

    Do you want to track the time a player has played on your server?
     
  3. Yes, and i dont know how to make this.
     
  4. I mean.. this is not that hard. There are 5 steps:
    1. When a player logs in, store the current time in a suitable manner
    2. When the player logs out, compute the difference and you have the time the player was online
    3. To get the total amount, you can save the time in a file (probably JSON or a Database or something like that) and you just have to add up the times (taking into account what happens when the player has never played or stuff like that)
    4. ?
    5. profit!
     
  5. You forgot the spoonfeed part
     
    • Funny Funny x 7
  6. my bad should have attached .jar...
     
    • Funny Funny x 7
    • Agree Agree x 1
  7. Exist a tutorial for this? because i dont know what a "suitable manner" is :/
     
  8. There is no tutorial for everything, you have to learn Java and figure it out yourself, this one is pretty simple. (or you can hire a dev)
     
  9. "Suitable manner" for storing the timings: probably something like a Map<UUID, Long> (use UUID's, not players so that people smiling 7 times can be happy)
    "Suitable manner" for storing the persistent data: probably something like JSON
     
    • Funny Funny x 1
  10. But, if you want a timer that is updated every second, so the player can see the time in-game updating.
    Create a timer, that's run ever 1 second. and then for every player, add a second to their in-game timer.
    the in-game timer could be a config file.
     
  11. For what should i hire a developer? I dont run a Server.

    And Tutorials are a good method to learn java... or have you another method to learn java... just clap with your hands or what?...
     
    • Funny Funny x 1
  12. Tutorials just give you the complete code, and don't let you think. And even if the do explain, most people just skip to the end to copy the code
     
  13. Yeah.. i watch tutorials to learn...

    Because this i ask again.. Exist a tutorial for this?
     
    • Informative Informative x 1
  14. If you have looked on google, youtube etc and found nothing then your answer is probably no.
     
  15. Im not good at find things on google, but i hope that anyone here knows a tutorial..
     
  16. Ah, no. Yes, that would work, but it's so much easier

    We just gave you a tutorial... We need people to stop coming here asking for spoon feed code.
    Code (Text):
    1. Find out when a player joins
    2. Use System.currentTimeMillis() to find the current time
    3. Find out when a player quits/server stops/player crashes/server crashes
    4. Use System.currentTimeMillis() to find the current time
    Once you've done the following, add debug statements to see what the times are. If need be, you should come back for more help
     
    • Like Like x 1
    • Agree Agree x 1
  17. map with player key and long value

    on join: insert system#currenttime into map with player key

    on quit: get time from map and subtract it from current time. this is how long they were on for. add this time to the players time saved in a config. done by using yamlconfiguration and using the players uuid as a key and long as the value, continuously adding up.

    on some event or command: to display the data, get the saved data from the yamlconfiguration and the time in the map if needed and add it, divide by 1000 and thats how many seconds theyve played
     
    • Agree Agree x 1
  18. Ok. So you don't really need anything of that because i believe that the server tracks the time played as a statistic. No?
    Btw if you want to learn Java and Spigot step by step i maybe got something: :unsure:
    1) Go here https://www.youtube.com/channel/UCNXt2MrZaqfIBknamqwzeXA/playlists
    2) Watch everything in 'Java Programming Tutorial'
    3) Watch everything in 'Bukkit Coding Tutorial 1.13' or 'Bukkit Coding Tutorial' if you live in 2014
    4) Watch at least 2-3 Vids from 'Advanced Bukkit Coding'
     
    • Agree Agree x 3
    • Winner Winner x 1
  19. Strahan

    Benefactor

    ^^ What he said. No need to reinvent the wheel when the server tracks it for you via statistics.

    Code (Text):
    int secondsPlayed = (Player Object).getStatistic(Statistic.PLAY_ONE_MINUTE) / 20;
     
    • Like Like x 3
    • Agree Agree x 1
    • Funny Funny x 3
    • Optimistic Optimistic x 1