Cooldowns?

Discussion in 'Plugin Development' started by Calebizzthaman, Sep 26, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Calebizzthaman

    Can someone please explain to me how to add a cooldown to this

    Code:
     @EventHandler
      public void onPlayerRightClickStrength(PlayerInteractEvent event)
      {
    
        Player player = event.getPlayer();
    
        if (player.hasPermission("specialabilities.superstrength"))
        {
          if (event.getAction() == Action.RIGHT_CLICK_AIR)
          {
            player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 200, 1));
          }
        }
        return;
    
    I tried this and go nothing

    Code:
    public void OnRightClickStength(PlayerInteractEvent event) {
          HashMap<String, Long> cooldowns = new HashMap<String, Long>();
        Player player = event.getPlayer();
       if(cooldowns.containsKey(event.getPlayer())){
           long secondsLeft = ((cooldowns.get(event.getPlayer())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
           if(secondsLeft>0){
               //still cooling down
               player.sendMessage("You can't use that ability for another " + secondsLeft + " seconds!");
        if (player.hasPermission("specialabilities.superstrength"))
        {
          if (event.getAction() == Action.RIGHT_CLICK_AIR)
          {
            player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 200, 1));
          }
        }
        return;
      }
      }
      }
     
  2. Code:
        private ArrayList<String> cooldown = new ArrayList<String>();
      
        @EventHandler
        public void onPlayerRightClickStrength(PlayerInteractEvent event) {
            final Player player = event.getPlayer();
          
            if(player.hasPermission("specialabilities.superstrength")) {
                if(event.getAction() == Action.RIGHT_CLICK_AIR) {
                    if(!cooldown.contains(player.getUniqueId().toString())) {
                        cooldown.add(player.getUniqueId().toString());
                        player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 200, 1));
                      
                        new BukkitRunnable() {
    
                            @Override
                            public void run() {
                                cooldown.remove(player.getUniqueId().toString());
                            }
                          
                        }.runTaskLater(plugin, 20L*seconds);
                    } else {
                        player.sendMessage("Cooldown!");
                    }
                }
            }
        }
    - ArrayList
    - Checking if ArrayList doesn't contain player UUID -> adding Cooldown, removing after some seconds (with BukkitRunnable)
     
  3. Offline

    boomboompower

  4. Sorry, sorry. He asked for a cooldown and I'm not the best explainer, eeehh.
     
  5. Offline

    Gonmarte

Thread Status:
Not open for further replies.

Share This Page