How to add a cooldown?

Discussion in 'Plugin Development' started by william9518, Jan 23, 2013.

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

    william9518

    I would like to add a cooldown to my plugin that enables flying. Ik the basics like the hashmaps and stuff but how do I get the cooldown to work? Do I schedule a sync delayed task? Will that die if multiple people use it at the same time?
     
  2. Offline

    gomeow

    Store timestamps instead
     
  3. Offline

    joehot2000

    If I was you I would just add some random useless potion effect, and then not allow it if they have the effect

    edit: I think night vision would be a good one, but I don't have the list of potions in front of my eyes, so you choose
     
  4. Offline

    gomeow

    Then they drink milk, and your plan fails
     
  5. Offline

    joehot2000

    he could always make it so they cant interact with milk in their hand while they have the effect
     
  6. Offline

    gomeow

    Well that would be overkill
     
  7. Offline

    joehot2000

    What does overkill mean?
     
  8. Offline

    gomeow

    Basically that would be way too much code than what is needed
     
  9. Offline

    joehot2000

    True, but its better than a scheduled task.

    stupidly, I just reialised I forgot how to do a delayed task.

    So,

    what about an ArrayList, and a delayed task?
    like,
    I get an arraylist, add him (so he is in cooldown) and then do a delayed task to remove him from the array?
     
  10. Offline

    william9518

    thats wut im doin...
     
  11. Offline

    joehot2000

    Then..
    whats the problem?
     
  12. Offline

    gomeow

    The most efficient way to do this is to use timestamps.
    Tasks were not made to do that, use timestamps, which are good for weeks if need be
     
  13. Offline

    william9518

    kk
     
  14. Offline

    bob7

    I would just get current system mil's, then convert it to seconds, then add on the time.
     
  15. Offline

    gomeow

    Subtract*
     
  16. Offline

    bob7

    No... That's how you retrieve the time left

    long sec = (int)(System.currentTimeMillis() / 1000L); <-- Here we convert it to second
    int test = 1*60*60*24*1+ sec; <-- Now we multiply a second, this would equal 1 day


    Now lets get the time:

    long remain = test - sec;
    int seconds = (int)remain;

    You have: + seconds + left!


    You don't have to convert it into seconds, but it's a lot better then keeping it to mills.
     
Thread Status:
Not open for further replies.

Share This Page