Advertisement
Charther

Untitled

Mar 23rd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. package net.silexpvp.ffa.util.cooldowns;
  2.  
  3. import java.util.HashMap;
  4. import java.util.UUID;
  5. import org.bukkit.entity.Player;
  6.  
  7. public class CooldownUtils
  8. {
  9. private static HashMap<String, HashMap<UUID, Long>> cooldown = new HashMap();
  10.  
  11. public static void clearCooldowns()
  12. {
  13. cooldown.clear();
  14. }
  15.  
  16. public static void createCooldown(String k)
  17. {
  18. if (cooldown.containsKey(k)) {
  19. throw new IllegalArgumentException("Ce cooldown existe d?j?");
  20. }
  21. cooldown.put(k, new HashMap());
  22. }
  23.  
  24. public static HashMap<UUID, Long> getCooldownMap(String k)
  25. {
  26. if (cooldown.containsKey(k)) {
  27. return (HashMap)cooldown.get(k);
  28. }
  29. return null;
  30. }
  31.  
  32. public static void addCooldown(String k, Player p, int seconds)
  33. {
  34. if (!cooldown.containsKey(k)) {
  35. throw new IllegalArgumentException(String.valueOf(k) + " n'existe pas");
  36. }
  37. long next = System.currentTimeMillis() + seconds * 1000L;
  38. ((HashMap)cooldown.get(k)).put(p.getUniqueId(), Long.valueOf(next));
  39. }
  40.  
  41. public static boolean isOnCooldown(String k, Player p)
  42. {
  43. return (cooldown.containsKey(k)) && (((HashMap)cooldown.get(k)).containsKey(p.getUniqueId())) && (System.currentTimeMillis() <= ((Long)((HashMap)cooldown.get(k)).get(p.getUniqueId())).longValue());
  44. }
  45.  
  46. public static int getCooldownForPlayerInt(String k, Player p)
  47. {
  48. return (int)((((Long)((HashMap)cooldown.get(k)).get(p.getUniqueId())).longValue() - System.currentTimeMillis()) / 1000L);
  49. }
  50.  
  51. public static long getCooldownForPlayerLong(String k, Player p)
  52. {
  53. return ((Long)((HashMap)cooldown.get(k)).get(p.getUniqueId())).longValue() - System.currentTimeMillis();
  54. }
  55.  
  56. public static void removeCooldown(String k, Player p)
  57. {
  58. if (!cooldown.containsKey(k)) {
  59. throw new IllegalArgumentException(String.valueOf(k) + " n'existe pas");
  60. }
  61. ((HashMap)cooldown.get(k)).remove(p.getUniqueId());
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement