Best way to add a cool-down time?

Discussion in 'Plugin Development' started by captainawesome7, Jul 30, 2011.

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

    captainawesome7

    So if I want to add a cool-down time to /derp for a player, what is the best way to do that? I currently have it working using a Timer and TimerTasks, but it isn't efficient at all and I'm pretty sure there is a better way to do it.
     
  2. Offline

    Acrobot

    Why not use a HashMap<Player, Long> and save System.currentTimeMilis() in it every time the command is executed??
    Then just check if(!hashMap.containsKey(player) || ((System.currentTimeMilis() - hashMap.get(player)) >= INTERVAL))

    INTERVAL is number of miliseconds (1/1000th of second)
    If not, give them error message.
     
  3. Offline

    obnoxint

    I'm using the same method to prevent that a block of code is executed during an event too often.
    It turned out to be the most reliable one.
     
  4. Offline

    DrBowe

    What @Acrobot suggested is what I use most often, though you can also apply the same concept with the Scheduler. (I'm really not sure which is better, but I use both just to dabble in each area)
     
Thread Status:
Not open for further replies.

Share This Page