[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

    70.8%
  2. Somewhat

    15.4%
  3. No

    6.2%
  4. Derp...

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

    bob7

    One last question, how do i set the timers time? For example, i want a timer to run for exactly 23 seconds. The only args it allows in schedulePlayerCooldown is Timer, rather then int? So how would i make a custom countdown? Edit the lib it's self?
     
  2. Offline

    Milkywayz

    Code:
    new Time(23.0); 
    That should do it.
     
  3. Offline

    bob7

    I lied about that being the last question, would i still use:
    PlayerTimer.getRemainingTime(e.getPlayer().getName(), Time.EXTWO)

    To get the remaining time?
     
  4. Offline

    Milkywayz

    Im not looking at the code in eclipse right now, but that looks like it should work. Trial and error would be best ;)
     
  5. Offline

    bob7

    No luck, it seems it cannot check if a player is cooling down when using the new timer type:

    Code:
              if (!(PlayerTimer.isCoolingDown(player.getName(), Time.EXONE))) {
                  Scheduler.schedulePlayerCooldown(Scheduler.schedule(plugin, player.getName(), new Time(10.0)));
              } else {
                  player.sendMessage(ChatColor.RED + "You must wait" + ChatColor.GREEN + PlayerTimer.getRemainingTime(player.getName(), Time.EXONE) + ChatColor.RED + "before using this command again!");
              }
    Nvm, I just changed public final static Time EXONE = new Time(5.0);

    lot of errors from time to time.

    2012-12-29 16:27:49 [WARNING] [PLUUGGIN ] Task #12 for PLUUGGIN v1.0 generated an exception
    java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
    at java.util.HashMap$KeyIterator.next(Unknown Source)
    at net.milkycraft.Scheduler.PlayerTimer.update(PlayerTimer.java:73)
    at net.milkycraft.Scheduler.PlayerTimer.run(PlayerTimer.java:88)
    at org.bukkit.craftbukkit.v1_4_6.scheduler.CraftTask.run(CraftTask.java:53)
    at org.bukkit.craftbukkit.v1_4_6.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    at net.minecraft.server.v1_4_6.MinecraftServer.r(MinecraftServer.java:530)
    at net.minecraft.server.v1_4_6.DedicatedServer.r(DedicatedServer.java:224)
    at net.minecraft.server.v1_4_6.MinecraftServer.q(MinecraftServer.java:494)
    at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:427)
    at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:849)

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

    DjMacmo

    Can you make an example how i can create a timer?
     
  7. Offline

    Frazz86

    What are the advantages of this over bukkit schedulers?
     
  8. Offline

    Milkywayz

    Built in method to find how much time is left in a 'cool down/ delay' is handy.

    It's helpful if you need to create many delays, as it's organized rather well.
     
  9. Offline

    Frazz86

    Any where i could look for a quick bit of sample code? If so in future ill be using this xD. I hate doing methods to find out time left :p
     
  10. Offline

    Milkywayz

    The download comes with a sample plugin using the library.

    PHP:
    // TODO: Auto-generated Javadoc
    /*    Copyright (c) 2012, Nick Porillo [email protected]
    *
    *    Permission to use, copy, modify, and/or distribute this software for any purpose
    *  with or without fee is hereby granted, provided that the above copyright notice
    *  and this permission notice appear in all copies.
    *
    *    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
    *    INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
    *  FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
    *    OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
    *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    */
     
    public class SamplePlugin extends JavaPlugin implements Listener {
     
        
    /*
        * This is just a sample plugin to get you familar with the methods
        * Permissions, and most other stuff is just for example.
        */
     
        /*
        * (non-Javadoc)
        *
        * @see org.bukkit.plugin.java.JavaPlugin#onEnable()
        */
        
    @Override
        
    public void onEnable() {
            
    getServer().getPluginManager().registerEvents(thisthis);
        }
     
        
    /*
        * (non-Javadoc)
        *
        * @see org.bukkit.plugin.java.JavaPlugin#onDisable()
        */
        
    @Override
        
    public void onDisable() {
     
        }
     
        
    /**
        * Format loc.
        *
        * @param loc
        *            the loc
        * @return the string
        */
        
    public String formatLoc(Location loc) {
            return 
    loc.getBlockX() + ", " loc.getBlockY() + ", "
                    
    loc.getBlockZ();
        }
     
        
    /*
        * The time the player has to wait to say ass
        */
        /**
        * On chat.
        *
        * @param e
        *            the e
        */
        
    @EventHandler
        
    public void onChat(AsyncPlayerChatEvent e) {
            if (
    e.getMessage().equals("test")) {
                if (
    PlayerTimer.isCoolingDown(e.getPlayer().getName(), Time.EXTWO)) {
                    
    e.setCancelled(true);
                    
    e.getPlayer().sendMessage(
                            
    ChatColor.RED
                                    
    "You need to wait "
                                    
    ChatColor.YELLOW
                                    
    PlayerTimer.getRemainingTime(e.getPlayer()
                                            .
    getName(), Time.EXTWO) + ChatColor.RED
                                    
    " seconds to say that!");
                } else {
                    
    Schedule s Scheduler.s(thise.getPlayer().getName(),
                            
    Time.EXTWO);
                    
    Scheduler.schedulePlayerCooldown(s);
                }
            }
        }
     
        
    /**
        * On place.
        *
        * @param e
        *            the e
        */
        
    @EventHandler(priority EventPriority.HIGHignoreCancelled true)
        public 
    void onPlace(BlockPlaceEvent e) {
            if (
    e.getBlock().getType() == Material.STONE) {
                if (
    PlayerTimer.isCoolingDown(e.getPlayer().getName(), Time.EXONE)) {
                    
    e.setCancelled(true);
                    
    e.getPlayer().sendMessage(
                            
    ChatColor.RED
                                    
    "You need to wait "
                                    
    ChatColor.YELLOW
                                    
    PlayerTimer.getRemainingTime(e.getPlayer()
                                            .
    getName(), Time.EXONE) + ChatColor.RED
                                    
    " seconds to place that stone");
                } else {
                    
    Scheduler.schedulePlayerCooldown(Scheduler.s(thise
                            
    .getPlayer().getName(), Time.EXONE));
                }
            } else if (
    e.getBlock().getType() == Material.GLASS) {
                if (
    PlayerTimer.isCoolingDown(e.getPlayer().getName(), Time.EXTWO)) {
                    
    e.setCancelled(true);
                    
    e.getPlayer().sendMessage(
                            
    ChatColor.RED
                                    
    "You need to wait "
                                    
    ChatColor.YELLOW
                                    
    PlayerTimer.getRemainingTime(e.getPlayer()
                                            .
    getName(), Time.EXTWO) + ChatColor.RED
                                    
    " seconds to place that glass");
                } else {
                    
    Scheduler.schedulePlayerCooldown(Scheduler.s(thise
                            
    .getPlayer().getName(), Time.EXTWO));
                }
            } else {
                if (
    PlayerTimer
                        
    .isCoolingDown(e.getPlayer().getName(), Time.EXTHREE)) {
                    
    e.setCancelled(true);
                    
    e.getPlayer().sendMessage(
                            
    ChatColor.RED
                                    
    "You need to wait "
                                    
    ChatColor.YELLOW
                                    
    PlayerTimer.getRemainingTime(e.getPlayer()
                                            .
    getName(), Time.EXTHREE)
                                    + 
    ChatColor.RED " seconds to place that");
                } else {
                    
    Scheduler.schedulePlayerCooldown(Scheduler.s(thise
                            
    .getPlayer().getName(), Time.EXTHREE));
                }
            }
        }
     
        @
    EventHandler
        
    public void onTimerStart(TimerStartEvent e) {
            
    e.setCancelled(true);
            
    this.getLogger().info(
                    
    e.getPlayer().getName() + " " e.getLength().getInt()
                            + 
    " seconds");
        }
     
        @
    EventHandler
        
    public void onTimerEnd(TimerEndEvent e) {
            
    this.getLogger().info(
                    
    e.getPlayer().getName() + " " e.getLength().getInt()
                            + 
    " seconds end:" e.getEndTime());
        }
    }
     
  11. Offline

    Frazz86

    Time.EXTHREE, etc, i assume are what stores the variable?
     
  12. Offline

    Tirelessly

    I find that you have made this a lot more complicated to use than it needs to be and if I see it right you used bukkit's scheduler.. Poor form.
     
    chasechocolate likes this.
  13. Offline

    chasechocolate

  14. Offline

    Tirelessly

    Or just use hashmaps and system time. I'll see if I can come up with a much simpler class for this.
     
  15. Offline

    Milkywayz

    Sorry you didn't like my method, I appreciate the efforts to improve this system. I know it's not a good method but it works, I haven't worked on it in a while which doesn't explain the crappy concept, just why it's sloppy..
     
  16. Offline

    DjMacmo

    Hey, I need help. I will make a general Countdown, but how? I have tryied and tryied but not works... have you any examples for me? :)
     
  17. Offline

    TomShar

    How would I go about making a warm up timer which can be stopped by other events. (teleport warm up)
     
  18. Offline

    masacrewayne

    Is there a way to end a cooldown early, say if an admin uses a command? If there isn't it would be awesome if you could add a method to do just that, and if there is, could you give an example of how to use it as I can't find it myself.
     
  19. Offline

    Hobbit9797

    This is awesome!
    I think about using it for a skill system...
     
  20. Offline

    nxtguy

    Milkywayz
    Looks like you posted this a long time ago. Does it still work with current bukkit releases? Also, the download link is broken. :(
     
  21. Offline

    Milkywayz

    Theres much better methods then what I provided nxtguy , I'd highly suggest you check them out. Tirelessly can you link him to it?
     
  22. Offline

    nxtguy

  23. Offline

    Tirelessly

  24. Offline

    Milkywayz

    I feel that your method along with Comphenix's method are so much better then my method, I'm still glad I kinda started the idea of these libs as they are helpful to many. Thanks for carrying on the idea, I was unable to provide proper support for this, let alone re-think the entire idea like Comphenix did (his code is so unique haha).
     
  25. Offline

    nxtguy

    Tirelessly Milkywayz
    What I'm actually in need of is a count down system for a game. Can EasyCooldown do this?
     
Thread Status:
Not open for further replies.

Share This Page