Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. public class CooldownManager {
  2.  
  3. public Map<UUID, Long> cooldowns;
  4.  
  5. public CooldownManager() {
  6. this.cooldowns = new HashMap<UUID, Long>();
  7. }
  8.  
  9. public void addCooldown(final Player player) {
  10. final long time = System.currentTimeMillis();
  11. this.cooldowns.put(player.getUniqueId(), time);
  12. }
  13.  
  14. public void removeCooldown(final Player player) {
  15. this.cooldowns.remove(player.getUniqueId());
  16. }
  17.  
  18. public boolean hasCooldown(final Player player, final int timer) {
  19. if (!this.cooldowns.containsKey(player.getUniqueId())) {
  20. return false;
  21. }
  22. final long now = System.currentTimeMillis();
  23. final long time = this.cooldowns.get(player.getUniqueId());
  24. if (now - time >= timer) {
  25. this.cooldowns.remove(player.getUniqueId());
  26. return false;
  27. }
  28. return true;
  29. }
  30. }
  31.  
  32. public CooldownManager getCooldownManager() {
  33. return this.cooldownManager;
  34. }
  35.  
  36. public void onLoad() {
  37. this.cooldownManager = new CooldownManager();
  38. }
  39.  
  40. public CooldownManager cooldownManager;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement