Best method for long-term cooldowns.

Discussion in 'Spigot Plugin Development' started by RedNinjaPlaysMC, May 29, 2017.

  1. What's the best method for a 30 day cooldown? Will System.currentTimeMilis() still be fine?
     
  2. 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.
     
  3. How would you do a cool down with Dates?
     
  4. 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.
     
    #4 Trigary, May 29, 2017
    Last edited: May 29, 2017
  5. MiniDigger

    Supporter

    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)
     
    • Like Like x 1
  6. I wanted to use Dates because it would be more precise, but maybe I'll just use the first method I suggested xD
     
  7. Why do you think Dates are more precise than milliseconds? I'm pretty sure they are based on milliseconds as well...
     
  8. If the server is offline, the time doesn't increase.
     
  9. 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
    back in.

    Don't check the timestamp constantly, only check it
    when the operation that is "cooling down" is being
    attempted.
     
  10. System.currenttimemillis() is always going m8

    Because it is not based on a timer, or
    the requirement of needing a server to
    run.

    It's simply based on the distance between now
    and January 1st, 1970.
     
  11. Oh, I did not know that. Thanks for the information!
     
    • Like Like x 1
  12. Sure, No Problem!