Discussion in 'Spigot Plugin Development' started by NaJated, May 8, 2015.

Thread Status:
Not open for further replies.
  1. If this gives me minutes:Main.getPlugin().getConfig().getInt("countdown") - System.currentTimeMillis()/60000 + start;

    How would I get seconds?
  2. May want to look at this package in Java:
  3. How do I use that?
  4. gigosaurus



    If [ start - System.currentTimeMillis() ] gives you the time since start in milliseconds (assuming start is a value in milliseconds), and
    If [ start - System.currentTimeMillis()/60000 ] gives you the time in minutes (assuming start is a value in minutes)

    What would you need to do to get a value in seconds?
  5. Would it be

    System.currentTimeMillis()/60000 - start / 60?

    Sorry, It's been a hard day :eek: :(
  6. gigosaurus


    Edited my post, I made a stupid mistake.

    Nope. Maybe it'll be clearer if I show the same calculations again, but assuming that start is in milliseconds in both cases.

    start - System.currentTimeMillis() = time since start in milliseconds.
    (start - System.currentTimeMillis()) / 60000 = time since start in minutes.

    Now if I were to assume start is a time in minutes, the calculations would be this:

    (start * 60000) - System.currentTimeMillis() = time since start in milliseconds.
    start - (System.currentTimeMillis() / 60000) = time since start in minutes.

    Can you see how you would go about calculating seconds now?

    Remember that 60000 = 1000 * 60.
  7. Not really, Code.

    When the plugin / server starts, it sets 'start' to the system get current milis. then every 5 seconds it checks and compares the system.getCurrentMillis of when the server started and system.getCurrentMillis NOW. I don't quite know but I got the 60 seconds working on the scoreboard but it just stays like that. I think that's because of it only changes every minute but now it's to seconds idk what i have done :/.
  8. gigosaurus


    Ok, I have absolutely no idea what you have done, and that code is just a complete mess. This is a really simple concept so I am going to explain it as if you have done no work towards it so far.

    To create a countdown, you will need to know how long the countdown is going to last (I'll call this x), and what time the countdown started (I'll call this start).

    Lets assume x is a value in milliseconds for now (so we want the countdown to last x amount of milliseconds).

    When the countdown is started, we set start to System.currentTimeMillis().
    At intervals of our choosing, to calculate how long is left of the countdown, we simply need to work out how much time has elapsed since the countdown has started, and minus that from the countdown length.

    So at any point in time, x - (start - System.currentTimeMillis()) is the amount of time left in the countdown. If the value is negative, the countdown ended [0 - value] amount of milliseconds ago.

    From this concept, it should be fairly obvious to see how you can adapt it so that you calculate how long is left in seconds, even if x is a value in seconds or minutes rather than milliseconds.
    #8 gigosaurus, May 8, 2015
    Last edited: May 8, 2015
    • Like Like x 1
  9. TimeUnit.[WHAT YOU HAVE].to[WHAT YOU WANT]( [WHAT YOU HAVE value] )
  10. gigosaurus


    That doesn't solve the problem in hand.
    • Optimistic Optimistic x 1
    • Agree Agree x 1
  12. gigosaurus


    Still doesn't solve the original problem. I wasn't questioning why you posted it, just pointing out that fact.
    • Funny Funny x 1
Thread Status:
Not open for further replies.