Solved Countdown in seconds with HashMap

Discussion in 'Spigot Plugin Development' started by Sean0402, May 26, 2018.

Thread Status:
Not open for further replies.
  1. Hello, I am trying to add a cooldown to a doublejump plugin.

    I have it to it checks the config for the seconds, but how do I make it countdown? I'm quite confused on this.

    Main:
    Code (Text):
    public HashMap<UUID, Long> cooldown = new HashMap<UUID, Long>();
    int cooldowntime = 30;
    Code (Text):
    if(plugin.cooldown.containsKey(p.getUniqueId())) {
                    long secondsleft = (plugin.getConfig().getInt("Cooldown"));
                 
                    if(secondsleft >0){
                        p.sendMessage(ChatColor.RED + "You cannot do this for " + secondsleft + "seconds");
                    }
                    e.setCancelled(true);
                } else {
                    p.sendMessage(ChatColor.GREEN + "You cannot doublejump for another " + plugin.cooldowntime + " seoncds");
                    plugin.cooldown.put(p.getUniqueId(), System.currentTimeMillis());
                }
            } else {
                long secondsleft = ((plugin.getConfig().getInt("Cooldown")) - (System.currentTimeMillis() / 1000));
             
                if(secondsleft >0){
                    p.sendMessage(ChatColor.RED + "You cannot do this for " + secondsleft + " seconds");
            }
    Config:
    Code (Text):
    #Cooldown for jump
    Cooldown: 30
    It will just print the int next to it, I'm unsure how to make it countdown
     
  2. Use a bukkit runnable to repeat every tick / second to increase or decrease it till it reaches your point. Then remove the player from the hashmap. And re add when you need to countdown again.
     
  3. I will give this a go.
     
    • Like Like x 1
  4. After some experimenting, I managed to get this working perfectly. Just got to add a configuration. Thanks so much :)
     
    • Winner Winner x 1
Thread Status:
Not open for further replies.