Created
October 6, 2014 20:02
-
-
Save Bimmr/14128f72298f209f1865 to your computer and use it in GitHub Desktop.
Easy way to manage Cooldowns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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