Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by RedNinjaPlaysMC, May 29, 2017.
What's the best method for a 30 day cooldown? Will System.currentTimeMilis() still be fine?
Yes, but you'll have to be able to write out that timestamp
and load it back in as it is unlikely that a server will go
without a restart over a 30 day period.
How would you do a cool down with Dates?
The easiest solution is to save the timestap (System.currentTimeMilis()), since therefore you don't have to worry about how many days a month has, etc. It's pretty easy to use as well, I don't think there's a point to use dates.
don't use milliseconds, you can avoid the math to calculate stuff like that if you uses javas high level date and time api.
you can get a period between two localdates (now and a saved one) and check how many days lay in between (or even months and it does all the calc needed for the georgian calendar)
I wanted to use Dates because it would be more precise, but maybe I'll just use the first method I suggested xD
Why do you think Dates are more precise than milliseconds? I'm pretty sure they are based on milliseconds as well...
If the server is offline, the time doesn't increase.
Format is not important.
If you want to have a cooldown that is 30 days out,
take the milli time now and add 2.592 billion to it. ( 30 days )
When you server restarts, write that value out, then read it
Don't check the timestamp constantly, only check it
when the operation that is "cooling down" is being
System.currenttimemillis() is always going m8
Because it is not based on a timer, or
the requirement of needing a server to
It's simply based on the distance between now
and January 1st, 1970.
Oh, I did not know that. Thanks for the information!
Sure, No Problem!