Big Cooldown Problem

Discussion in 'Plugin Development' started by Flexion, Dec 1, 2014.

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

    Flexion

    Hello, I made a plugin, but I want a cooldown, i tried some cooldowns, the official Cooldown on the wiki, but I didn't work. I want to wait 60 ticks (3 Seconds) and then do the next task.
    Code:java
    1. FlansPPG.respawners.add(p);
    2. // NOW WAIT 3 SECONDS
    3. FlansPPG.respawners.remove(p);

    I hope for an answer.
     
  2. Offline

    SyTeck

    No, that will force the Bukkit thread to freeze for 3 seconds.

    You should use a Bukkit scheduler, and it should look something like this.
    Code:java
    1. //Things to do before timer
    2.  
    3. scheduler.scheduleSyncDelayedTask(class that extends JavaPlugin, new Runnable() {
    4.  
    5. @Override
    6. public void run() {
    7.  
    8. //Stuff to do after timer
    9.  
    10. }
    11. }, 0L, 60L);


    You can read more about it here http://wiki.bukkit.org/Scheduler_Programming
     
  3. Offline

    [b]Blake[/b]

    Not a repeating task, Scheduler#scheduleDelayedTask
     
  4. Offline

    xTrollxDudex

  5. Offline

    Dragonphase

    Flexion

    I sure hope you know how you're accessing those fields in a static context.
     
  6. Offline

    SyTeck

    Yeah, ofc. Sorry, copied from another page and got the wrong code.. :p Yet another example why copying is bad.

    @xTrollxDudex In some cases you have to. Using that technique will not execute after a set amount of time, but can be stored and used whenever another action is performed. So if you were to for example send a message to a player after 3 seconds, schedulers would be the way to go.
     
  7. Offline

    mythbusterma

    SyTeck

    But that isn't a cooldown, that is a delayed task, which is what this is meant for.
     
  8. Offline

    SyTeck


    Well, makes sense I guess. Twist it as much as you want, in some situations you'll have to use schedulers, but if you don't need to you shouldn't.
     
Thread Status:
Not open for further replies.

Share This Page