Discussion in 'Plugin Development' started by Pigi0204, Jul 29, 2017.
How do I do that a player can run a command only once every 24h???
Store the time, in milliseconds, when the code be triggered. Figure this out using 1000*seconds+60,000*minutes+360,000*hours.
Create a new BukkitRunnable. Run this every minute (20*60 ticks)
Inside the runnable, see if the current time%86400000 (i.e, one day) is within 1 minute of the time from #1. If so, run the command.
uhm.. ok have you got a guide for this because my java is really bad? Thanks for reply
You might use file instead, the server can reboot.
You can use 'system.CurrentTimeMillis() / 1000' for get the actual second.
When the player perform the command, load the file and check if he's in. And if yes, substract the actual time by the time stored, and see if it's over 24H.
Once you're done, add him back to the file with the new time.
You can set the player uuid as key with the time as value.
uhm.. ok thanks try this
You shouldn't constantly read/write to the file, it'll eventually get heavy. Store cache in memory and save/load when neccecary.
Separate names with a comma.