Advertisement
TriiNoxYs

Simple Cooldown

Jul 9th, 2015
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. public class CooldownExample{
  2.     public HashMap<String, Long> cooldowns = new HashMap<String, Long>();
  3.  
  4.     @Override
  5.     public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  6.         int cooldownTime = 60; //le temps de cooldown en seconde
  7.         if(cooldowns.containsKey(sender.getName())) {
  8.             long secondsLeft = ((cooldowns.get(sender.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
  9.             if(secondsLeft>0) {
  10.                 // Cooldown pas fini
  11.                 sender.sendMessage("Vous devez attendre "+ secondsLeft +" secondes !");
  12.                 return true;
  13.             }
  14.         }
  15.  
  16.         cooldowns.put(sender.getName(), System.currentTimeMillis());
  17.         //reste du code ici
  18.         return true;
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement