Cooldown

Discussion in 'Plugin Development' started by desup, Mar 26, 2012.

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

    desup

    Hi, I am working on plugin and I need to use some sort of cooldown for command, for example, 30 seconds.
    Can you give me an example what to use?
    I was thinking about delayed tasks, maybe?
     
  2. Offline

    anerach

    Perhaps use a HashMap<String, long> in which the String represents a players name and the long a time value in milliseconds (System.currentTimeMillis())
     
    desup likes this.
  3. Offline

    desup

    Using HashMap, that was my first idea, but I did't know how to put it together.
    Btw. I love your plugin BlockLog ;)
     
  4. Offline

    anerach

    Thanks and its quite easy.
    HashMap itself
    Code:java
    1. HashMap<String, Long> hashmap = new HashMap<String, Long>();

    Check if player has a cooldown
    Code:java
    1. hashmap.containsKey(player.getName());

    Give a player a cooldown
    Code:java
    1. hashmap.put(player.getName(), System.currentTimeMillis());

    Get a player's cooldown
    Code:java
    1. Long time = hashmap.get(player.getName());

    Remove a player's cooldown
    Code:java
    1. hashmap.remove(player.getName());
     
Thread Status:
Not open for further replies.

Share This Page