Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by Inkzzz, May 2, 2015.
Is it possible to get a players online time?
Yes. Count the time they are online.
I know this way, I was wondering if there was a quicker way.
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
store their login time, check it against the current system time?
That is the only way...
The way is easy and quick
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.
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)
@Inkzzzmc @Skionz @superpeanut911 @nfell2009 @gigosaurus Statistic.PLAY_ONE_TICK, anyone? Updated by Minecraft every tick a player lives.
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.
I suggested the minute one because I doubt he needs it as accurate as each tick.
It's the same thing, mine is the programmatic approach of yours (the playOneMinute statistic in NMS is the PLAY_ONE_TICK statistic in Bukkit)
Ohhhh! Well I did say I hadn't looked at how to implement it in bukkit Now I'm wondering why the different rate.
If you're meaning a players total play time, there are are plugins that track this and make it easy to check.
If you're going to do that, you're going to have some serious lag issues.
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.
What, reading the value of an objective in a scoreboard is going to create lag issues?
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.