[LIB] TimerLib - Easily create delays / cooldowns!

Discussion in 'Resources' started by Milkywayz, Aug 10, 2012.


Do you think this is a useful library?

  1. Yes

  2. Somewhat

  3. No

  4. Derp...

Multiple votes are allowed.
Thread Status:
Not open for further replies.
  1. Offline


    How can I make it do something after the cooldown's over?
  2. Offline


    How i would do it is, check if they are cooling down, if they are then whatever they are trying todo should be cancelled, if they aren't cooling down then you should let them do what they are trying todo and also schedule a new timer so that its blocked for another x amount of time. Like this:
    if(PlayerTimer.isCoolingDown(params)) {
    } else {
    Excuse any errors as I just typed that on the fly
  3. Is it a possibility to add another parameter which calls another method?

    So like: (PlayerTimer.isCoolingDown(params, methodname())

    If not I understand but that'd be awesome. Awesome library btw :p
  4. Offline


    I believe its possible, ill try and implement that. Thanks for making a suggestion. What would the method name be used for though?
  5. my intention for it would likely be to run something after the player has cooled and whilst they are cooling :)
  6. Offline


    Oh i understand, it would like call another method. I can easily make it so you can call another classes constructer. Hopefully I can do the same for methods in the same class. :D
  7. And this would work for when the timer finishes? If so then "epic" :D
  8. Offline


    Yeah I can do that, ill get working on it :D

    After a little bit of coding, this is what i came up with:
        public static void whileCooling(String player, Time time, String methodname, Object obj, Object[] args) {
            Method method = null;
            do {
                try {
                    method = obj.getClass().getMethod(methodname);
                } catch (SecurityException e) {
                } catch (NoSuchMethodException e) {
                } finally {
                    try {
                        method.invoke(obj, args);
                    } catch (IllegalArgumentException e) {
                        // TODO Auto-generated catch block
                    } catch (IllegalAccessException e) {
                        // TODO Auto-generated catch block
                    } catch (InvocationTargetException e) {
                        // TODO Auto-generated catch block
            } while(isCoolingDown(player, time));
    Havent tested it yet however.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 27, 2016
  9. Offline


    Anyone make anything cool with this library? :3
  10. Offline


    I copied the whole code to my IDE, does that count? :D
  11. Offline


    I guess lol, at least someone uses it... :'(
    WarmakerT likes this.
  12. Offline


    This library is actually really useful, thank you for it, I just don't have any use for it for now D=
    But again, thank you :)
  13. Offline


    :D It's good to hear someone likes it, it's definitely motivation to improve it. Im probably going to try to make it more light weight soon. :D
    WarmakerT likes this.
  14. Offline


    Using it for a cool-down for a command in one of my custom plugins, working great, very easy to implement to! :D
    WarmakerT likes this.
  15. Offline


    After reaching a dead end (or so I thought) with developing my plugin because I was stumped with timers and cooldowns, this looks promising. About to try it out now!

    I'm a fairly new to programming, and can't get it to work with a command. I'm trying this:
    if (GeneralTimer.isCoolingDown(Time.MAIN)) {
            Bukkit.broadcastMessage(ChatColor.RED + "Wait for cooldown!");
        } else {
    But I of course need to declare e, but I don't know how exactly? Could you offer a solution? :)

    EDIT: I should also mention that the above code is wrapped in the usual correct command if statement.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 27, 2016
  16. Offline


    That's using General timers which don't check for players. If your using commands it's recommended to use Per Player cool downs using PlayerTimer. However that code looks like it should work as long as 'this' is your main class.
  17. Offline



    It's been ages since I last worked on my plugin. Heres my code for a basic command cooldown. :)

    1. if(cmd.getName().equalsIgnoreCase("rep")){
    3. if (PlayerTimer.isCoolingDown(e.getPlayer().getName(), Time.EXONE)) {
    4. Bukkit.broadcastMessage(ChatColor.RED + "Wait for cooldown!");
    5. } else {
    6. sender.sendMessage(ChatColor.RED + "Running Reputation " + ChatColor.GREEN + "b0.8" + ChatColor.RED + " by " + ChatColor.GREEN + "Scullyking");
    7. Scheduler.schedulePlayerCooldown(Scheduler.schedule(this, Time.EXONE));
    8. }
    9. returntrue; }

    However I still need to declare e for the main if statement. How or where do I declare e? Thanks :) Again, I am really new to this :S
  18. Offline


    Well, considering this is a command we are talking about, you could simply use the CommandSender argument...
  19. Offline


  20. Offline



    I don't get any code errors. When I run the command for the first time, its fine. But every time after that the cooldown is still in place.
    2. if(cmd.getName().equalsIgnoreCase("rep")){
    4. if (PlayerTimer.isCoolingDown(sender.getName(), Time.EXTWO)) {
    5. sender.sendMessage(ChatColor.RED + "Please wait for cooldown!");
    6. } else {
    7. sender.sendMessage(ChatColor.RED + "Running Reputation " + ChatColor.GREEN + "b0.8" + ChatColor.RED + " by " + ChatColor.GREEN + "Scullyking");
    8. Scheduler.schedulePlayerCooldown(Scheduler.schedule(this, sender.getName(), Time.EXTWO)); }
    10. returntrue; }
  21. Offline


    Thanks for this library. I used a slightly modified version to add cooldowns and warmups to MyWarp.
  22. Offline


    Awesome glad you like it, and actually modifying the library is encouraged as it's basically impossible to create a "One size fits all" without having an overly bloated library.
  23. Offline


    Is this timer dead? I really want to use it but the link is down :(
    Milkywayz likes this.
  24. Offline


    Thanks for the notice! My dropbox was wiped on accident :( I'll update the link in a minute

    Thread updated with working download and a small usage block of text for a small guideline

    • Fixed the library completely
    • Rewrote the PlayerTimer (GeneralTimer still broken, fix coming soon)
    • Must use for loops instead of while + iterator, for works, latter doesn't.
    • Updated link to the new dl file.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 27, 2016
  25. Offline


    Quick question, can this get the remaining time if i have multiple delays running?

    For instance, if i make a plugin that delays commands. I want to get their remaining time, but they're are like 10+ delays constantly running.

    Edit: NVM! It does! How cool is that!
  26. Offline


    This library was designed for that, the 'delays' or cooldowns are dependent on the player, so they are unique.

    Getting the remaining time is built in aswell.
  27. Offline


    Yup, just figured that out lol. You respond to fast xD
  28. Offline


    Since im following this thread, I get an email whenever someone posts here.
  29. Offline


    Quick question, what do these enums mean?


    Is that just how much it counts by.. oorr?
  30. Offline


    They are an example of how you set the delays.

    The Enum converts a double into minecraft longs, it's primarily for ease of use. Those example enums aren't needed.
Thread Status:
Not open for further replies.

Share This Page