Util Simple cooldown manager!

Discussion in 'Resources' started by joao_maxinho, Jan 24, 2016.

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



    public class Cooldown {
        public Cooldown(int seconds) {
            this.seconds = seconds;
        private int seconds = 0;
        private HashMap<UUID, Long> hashmap = new HashMap();
        public void putInCooldown(Player player) {
            hashmap.put(player.getUniqueId(), System.currentTimeMillis() + (seconds * 1000L);
        public boolean isOnCooldown(Player player) {
            UUID uuid = player.getUniqueId();
            return (hashmap.get(uuid) != null && hashmap.get(uuid) > System.currentTimeMillis())
        public int getCooldownSeconds(Player player) {
            UUID uuid = player.getUniqueId();
            return (int)  ((hashmap.get(uuid) - System.currentTimeMillis()) / 1000L)

    putInCooldown(player); // put the player in cooldown
    isOnCooldown(player); // return if player is on cooldown
    getCooldownSeconds(player); // return player reaming cooldown in seconds

    Cooldown cd = new Cooldown(30);
    if the code has a error, tell me, because a maked it on notepad!
  2. Offline


    Interesting util. I know a few people that may use this. It works, but please consider applying the following changes.
    1. We should not have to import all these objects when the copy and paste this into our plugins. Post the imports as well.
    2. Don't you want to document your code? You don't want to put any markers saying that you are the creator of this resource? It up to you, but I image you want some form of credit.
    3. Why would you create a single amount of time to be put into the cooldown? Why can't we control how long we want the cooldown to last when we actually put them into the hashmap?
      Please use hashmap.contains(Object) instead.
    4. You never remove the player's uuid from the hashmap. This will take up more memory.
    5. Please do not be lazy and add the parameters for the hashmap.
    6. There is no need to create the "uuid" instance for all the methods. If it's only going to be used once, then you should not have to create the variable.
  3. Offline


    You don't want that double get right there, using a local variable can remove the other get entirely.
  4. Offline


    People talk a lot in this forum by unnecessary things, this is my last topic here.
  5. Offline


    We are trying to tell you about how you can improve your code. How is that unnecessary?
    Mrs. bwfctower likes this.
  6. Offline

    Mrs. bwfctower

    @joao_maxinho Just about every other post here has posts making suggestions, and saying what could be better about their class/api/whatever. If you don't want to have people say what you could do to make your code better, then don't post it here.

    Also, on another note, there's already so many, very similar, cooldown managers out there.

    Just on the first page when you search "cooldown".
    cococow123 and teej107 like this.
  7. Offline


    If you confuse suggestions with "unnecessary things" you might as well tell us how to improve our suggestions so that you would understand them better.
    WolfMage1 likes this.
  8. Offline


    I agree. We suggest things to make your code better. I personally think this utility is a lot better than some of the ones I've seen lately. A few of the cooldown managers you listed are absolutely terrible either in code or the tutorial.
Thread Status:
Not open for further replies.

Share This Page