How would I implement double coins for a certain period of time?

Discussion in 'Spigot Plugin Development' started by DotRar, May 26, 2016.

  1. I am able to implement doubling the coins easily. But how would I implement double coins enabling at Friday at midnight and expiring at 11:59 on Sunday? I would need this to be synced across all servers and I have access to MySQL.Also, how would I enable it for exactly 1 hour but carry across the time if the dedicated server restarts?
  2. use
    System.currentTimeMillis() and convert it into date and time.
    • Winner Winner x 1
  3. Can you explain a bit more please?
  4. You can convert currentTimeMillis to get the current system time in milliseonds and you can check if the date is on a sunday do the thing untill 1 hour later in milliseconds.
    • Winner Winner x 1
  5. new Date() will give the current date, then just check it.

    or use new Date(long l)
  6. Good point about checking the day, I will use that for double coins weekend. However, if a player buys a 1 hour booster, I want that to sync across all servers and the timer to pause when the server shuts down (Therefore I can't just check if it is 1 hour later since we may have had an hour of downtime)
  7. ru
    n a task to every 1 second update a value in a sql or every 10 seconds possibly more opr somthing like that, not sure how efficient it would be but it would work.
    • Winner Winner x 1
  8. That was my initial thought but would that create a lot of lag? The database will be on the same machine.
  9. if its on the same machine i dont think it would because its only small bytes of data with pretty much no latency issues because its the same network. If not what you could do is every minute update in a map how long they have left and use a timer to remove a second and every lets say 10min update that to the database.
    • Winner Winner x 1
  10. Do it every minute or two minutes surely that won't cause lag. Plus it won't be on the main thread.
    • Winner Winner x 1
  11. Yeah, I all my interactions with databases are async. I will probably update the database every ~30 seconds unless I implement a timer in the future (No need for it unless the players want it imo)
  12. It will be fine then, you could even do the timer in minute intervals if you wanted so it would warn the players that the double xp is going to end.
    • Winner Winner x 1
  13. Good idea!