Lagless countdown for 7 days.

Discussion in 'Spigot Plugin Development' started by Vylerion, Apr 29, 2017.

  1. Hello folks,

    I want to run an countdown for 7 days long without overloading the server. I'm talking about a countdown for crates. (Crate you can use every 7 day). How could i do this because i need to get every single player that has an countdown and run it which might be laggy.
  2. Tux


    Record the time when the player opens a crate, then see if it's been more than seven days when a user has tried to open a crate. No countdown required.
    • Agree Agree x 2
  3. Nice idea! I could actually run an scheduler every hour to check it .Which shall be less laggy. Thanks.
  4. No scheduler is required at all, just check the saved time when the crate is opened..
  5. You could do it like this:

    Code (Text):
    Date currentDate = new Date(System.currentTimeMillis());
    Date newDate = new Date(currentDate.getTime() + (your time to add here));
    Save a String of newDate in a file or database and every time a player tries to open a crate, check if the current time >= to the saved time. If it is, allow them to open and store the updated date in the file, otherwise refuse to open a crate.

    I didn't try this but I believe it could work :)
  6. you could also do some math with the date /timestamp to tell them how long it would be until they could open the crate again. No timers needed just some math / use of the library.
  7. System.currentMillis and then add the milisecond for 7 days. Then save somewhere the time from the current milis + the milis of 7 days and ill check every hour if it is time yet.
  8. 7 days to milliseconds is:
    (7 * 60 * 60 * 24) * 1000

    7 x 60 seconds x 60 mins x 24 hours = number of seconds in 7 days x 1000 = ms

    Sent from my iPhone using Tapatalk
    • Agree Agree x 1
  9. you could actually just check if it 'is time yet' when they try to use the crate again

    Code (Text):

    if time-is-less-than-7-days
         deny crate, output how much longer

    if time-is-greater-than-or-equal-to-7-days
         allow crate
         recalculate next time until crate is available
    • Agree Agree x 1
  10. If you're ok with Java 8, the new java.time library is far superior and easier to use than the old java.util.Date library.
  11. His idea went completely over your head, didn't it?
  12. Like everyone here is saying, you only need to check the time when the player tries to open the crate, there is no timer needed.
  13. WAS


    You can also just add 7 days to directly (no math in script) to currentTimeMillis() and refer to it?

    Code (Java):
    long sevenDays = System.currentTimeMillis() + 604800000; // Timestamp exactly one week in future
  14. Yea right, it's the same as I tried to point out!
  15. WAS


    With bloat though? There is no need for the date class.
  16. thats exactly what i was saying..
  17. WAS


    Your point? You provided no example and the discussion continued like it was so hard to grasp.
  18. Would be annoying if you'd reload / restart your network causing the schedulers to stop. Means your countings will be f*cked up as it may cause that I will get a crate in 10 minutes but because you are checking each hour I'll get it 50 minutes to late ^^