Cooldown for command

Discussion in 'Plugin Development' started by rob1998@, Jun 22, 2013.

Thread Status:
Not open for further replies.
  1. How can I create a cooldown for a command?
    Can you give me an example for the command /kit ?
     
  2. Offline

    Alex5657

    Create a hashmap to store players as keys and java.util.Timer as values. Once the command is called, start the timer for the player and when he calls the command next time, check the time on it. Tell me if you need code examples
     
  3. Offline

    TomFromCollege

    Ok, Here's my method: It's completely untested, but I think it's a viable method...
    Code:java
    1. HashMap<String, Integer> intList = new HashMap<>();
    2.  
    3. if (!intList.containsKey(p.getName())) {
    4. // Add your code here
    5. intList.put(p.getName(), core.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    6. @Override
    7. public void run() {
    8. if (p != null) {
    9. intList.remove(p.getName());
    10. }
    11. }
    12. }, 20L)); //20L is the timer on the cooldown
    13. }
    14.  


    You'll have to change core. to your own plugin :)
     
  4. Doesn't work...



    I would like some examples...

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
Thread Status:
Not open for further replies.

Share This Page