Cooldown help with showing time left!

Discussion in 'Spigot Discussion' started by MaxNatural, May 15, 2016.

Thread Status:
Not open for further replies.
  1. Hello all! I am trying to make a cool down and I have this code so far for the cool down class.

    Code (Text):
    public class Cooldown extends BukkitRunnable {

        public static Map<String, Long> cooldown = new HashMap<String, Long>();
     
        public Cooldown(Hub hub) {
            // TODO Auto-generated constructor stub
        }

        @Override
        public void run() {
            Iterator<Entry<String, Long>> it = cooldown.entrySet().iterator();
            while(it.hasNext()) {
                Entry<String, Long> pair = it.next();
                if(System.currentTimeMillis() - pair.getValue() >= (3 * 1000)) {
                    it.remove();
                }
            }
        }
     
        public static boolean isOnCD(String p) {
            return cooldown.containsKey(p);
        }
     
        public static void add(String p) {
            cooldown.put(p, System.currentTimeMillis());
        }
     
        public static void showSec(Player p) {
            cooldown.get(p).toString();
         
        }
     
    }
     
    Then this is the actually item

    Code (Text):
        @EventHandler
        public void onPlayerIntreact(PlayerInteractEvent e) {
            Player p = e.getPlayer();
                if ((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                    if (e.getItem().getType() == Material.BLAZE_ROD) {
                        if (Cooldown.isOnCD(e.getPlayer().getName())) {
                            e.getPlayer().sendMessage(Hub.prefix + "This is still on cooldown!");
                            e.setCancelled(true);
                        } else {
                         
                            Location start = p.getLocation();
                            start.add(0, 1.4, 0);
                            Vector increase = start.getDirection();
                            for (int counter = 0; counter < 100; counter++) {
                                Location point = start.add(increase);
                                ParticleEffect.FIREWORKS_SPARK.display(0F, 0F, 0F, 0F, 50, point, 100D);
                                ParticleEffect.HEART.display(0.5F, 0.5F, 0.5F, 0.5F, 1, point, 100D);
                                ParticleEffect.SMOKE_LARGE.display(0.2F, 0.2F, 0.2F, 0.2F, 1, point, 100D);
                                ParticleEffect.LAVA.display(0.2F, 0.2F, 0.2F, 0.2F, 1, point, 100D);
                                ParticleEffect.CLOUD.display(0.2F, 0.2F, 0.2F, 0.2F, 1, point, 100D);
                                p.playSound(p.getLocation(), Sound.ENTITY_CHICKEN_EGG, 0.1f, 0);
                             
                                Cooldown.add(e.getPlayer().getName());
    Thank you!!! :D
     
    #1 MaxNatural, May 15, 2016
    Last edited: May 15, 2016
Thread Status:
Not open for further replies.