Big Cooldown Problem

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

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


    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.
    1. FlansPPG.respawners.add(p);
    2. // NOW WAIT 3 SECONDS
    3. FlansPPG.respawners.remove(p);

    I hope for an answer.
  2. Offline


    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.
    1. //Things to do before timer
    3. scheduler.scheduleSyncDelayedTask(class that extends JavaPlugin, new Runnable() {
    5. @Override
    6. public void run() {
    8. //Stuff to do after timer
    10. }
    11. }, 0L, 60L);

    You can read more about it here
  3. Offline


    Not a repeating task, Scheduler#scheduleDelayedTask
  4. Offline


  5. Offline



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


    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



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


    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