Advertisement
Douglas_AMV

CoolDownAPI

Feb 1st, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. package com.duexgames.kitpvp.utils;
  2.  
  3. import java.util.HashMap;
  4. import java.util.UUID;
  5.  
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.event.EventHandler;
  8. import org.bukkit.event.player.PlayerJoinEvent;
  9. import org.bukkit.event.player.PlayerRespawnEvent;
  10.  
  11. public class CoolDownAPI {
  12.    
  13.      private static HashMap<UUID, Long> cooldown = new HashMap<UUID, Long>();
  14.      
  15.      @EventHandler
  16.      public void join(PlayerJoinEvent e) {
  17.          removeCooldown(e.getPlayer());
  18.      }
  19.      
  20.      @EventHandler
  21.      public void respawn(PlayerRespawnEvent e) {
  22.          removeCooldown(e.getPlayer());
  23.      }
  24.      
  25.      public static void putCooldown(Player p, int Seconds) {
  26.          cooldown.put(p.getUniqueId(), System.currentTimeMillis() + (Seconds * 1000L));
  27.      }
  28.      
  29.      
  30.      public static int getCooldown(Player p) {
  31.          if (cooldown.containsKey(p.getUniqueId())) {
  32.              return Long.valueOf(((System.currentTimeMillis() - cooldown.get(p.getUniqueId())) / 1000)).intValue();
  33.          }
  34.          else {
  35.              return 0;
  36.          }
  37.      }
  38.      
  39.      public static boolean isOnCooldown(Player p) {
  40.          if (cooldown.containsKey(p.getUniqueId()) && cooldown.get(p.getUniqueId()) > System.currentTimeMillis()) {
  41.              return true;
  42.          }
  43.          else {
  44.              return false;
  45.          }
  46.      }
  47.      
  48.      public static void removeCooldown(Player p) {
  49.          if (cooldown.containsKey(p.getUniqueId())) {
  50.              cooldown.remove(p.getUniqueId());
  51.          }
  52.      }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement