Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by Th3Wh1teG0d, Jan 16, 2020.
Exists a tutorial that shows me how to make a playtime plugin?
What is a
Do you want to track the time a player has played on your server?
Yes, and i dont know how to make this.
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)
You forgot the spoonfeed part
my bad should have attached .jar...
Exist a tutorial for this? because i dont know what a "suitable manner" is :/
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)
"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
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.
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?...
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
Yeah.. i watch tutorials to learn...
Because this i ask again.. Exist a tutorial for this?
If you have looked on google, youtube etc and found nothing then your answer is probably no.
Im not good at find things on google, but i hope that anyone here knows a tutorial..
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.
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
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
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:
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'
^^ What he said. No need to reinvent the wheel when the server tracks it for you via statistics.
int secondsPlayed = (Player Object).getStatistic(Statistic.PLAY_ONE_MINUTE) / 20;
Anything German ? That would make it very easy