Advertisement
Guest User

Untitled

a guest
May 1st, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. public class Cooldowns {
  2.     private static Table<String, String, Long> cooldowns = HashBasedTable.create();
  3.    
  4.     public static long getCooldown(Player player, String key) {
  5.         return calculateRemainder(cooldowns.get(player.getName(), key));
  6.     }
  7.    
  8.     public static long setCooldown(Player player, String key, long delay) {
  9.         return calculateRemainder(
  10.                 cooldowns.put(player.getName(), key, System.currentTimeMillis() + delay));
  11.     }
  12.    
  13.     public static boolean tryCooldown(Player player, String key, long delay) {
  14.         if (getCooldown(player, key) <= 0) {
  15.             setCooldown(player, key, delay);
  16.             return true;
  17.         }
  18.         return false;
  19.     }
  20.    
  21.     private static long calculateRemainder(Long expireTime) {
  22.         return expireTime != null ? expireTime - System.currentTimeMillis() : Long.MIN_VALUE;
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement