Ticks to Hour

Discussion in 'Plugin Development' started by DogeDebugger, Mar 26, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    DogeDebugger

    I'm trying to make a loan plugin where you pay someone and they have a settable amount of time to pay it back, anyone know how many ticks are in an hour? A day?
     
  2. Offline

    westjet

    72,000 ticks in one IRL hour.
    1,728,000 ticks in one IRL day.

    I think you might want to use the console day and time system instead of ticks.
     
  3. Offline

    DogeDebugger

    whats console time?
     
  4. Offline

    SuchSwegMuchWow

  5. Offline

    Gamecube762

    Here's a little tip:
    20 ticks are in 1 second;
    60 seconds are in a minute;
    60 minutes are in an hour.

    If we times 20 * 60, we get a minute.
    If we multiply by another 60, we get an hour.


    Getting the system time and adding an hour would be more accurate as the server is not always running at 20TPS. Ticks can run slow due to bigger calculations.

    We can get the system's time, add an hour to it, store that number, and later check if the systems current time is >= to the stored time.
    Code:
    //1 hour = 3600000 miliseconds
    waitHour =  System.currentTimeMillis() + 3600000
    
    //later:
    if System.currentTimeMillis() >= waitHour then sendMessage("Your hour is up!")
     
    DogeDebugger likes this.
  6. Offline

    westjet

    You could have a bukkit scheduler that runs every 1 or 5 or 10 seconds (up to you) that checks if the stored time in milliseconds is >= current time. The only thing I'm unsure of is how that will handle midnight.
     
  7. Offline

    Konato_K

    @westjet If you have a scheduled task, then why don't schedule it every hour instead and ignore the time entirely?
     
  8. Offline

    TehHypnoz

    Because this is way more accurate.
     
  9. Offline

    Konato_K

    @TehHypnoz And more resource consuming, but let's be honest, it's rare some needs really exact accuracy in bukkit, besides, considering he was asking first for ticks I'd say scheduling a task every hour (in ticks equivalent) will do for his needs.

    Running a task every 5 seconds just to check if it's been an hour already it's not the solution.
     
  10. Offline

    TehHypnoz


    It kinda depends on the situation, if you just want to check how much time the player has left when he executes a command for example you won't have to run a task every x seconds.
     
  11. Offline

    DogeDebugger

    I'm dealing hours/days here, so accuracy by a few ticks isn't really a worry.
     
Thread Status:
Not open for further replies.

Share This Page