Skip to content

Instantly share code, notes, and snippets.

@Bimmr
Created October 6, 2014 20:02
Show Gist options
  • Save Bimmr/14128f72298f209f1865 to your computer and use it in GitHub Desktop.
Save Bimmr/14128f72298f209f1865 to your computer and use it in GitHub Desktop.
Easy way to manage Cooldowns
import java.util.HashMap;
/**
*
* @author Randy
*
*/
public class Cooldown {
private static HashMap<String, Long> cooldowns = new HashMap<String, Long>();
// Change time to how ever long you want
private static long time = 3;
public static void addToCooldown(String player) {
cooldowns.put(player, System.currentTimeMillis());
}
public static long getTimeRemaining(String player) {
return time - ((System.currentTimeMillis() - cooldowns.get(player)) / 1000);
}
public static boolean isCooledDown(String player) {
if (!cooldowns.containsKey(player) || (((System.currentTimeMillis() - cooldowns.get(player)) / 1000) >= time))
return true;
else
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment