Better way of doing cooldowns for kit abilities?

Discussion in 'Plugin Development' started by Fhbgsdhkfbl, May 26, 2016.

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

    Fhbgsdhkfbl

    I was wondering, if there is possibly another way of doing cooldowns on kitpvp kit abilities? Mine is a little "messy" as you fellas would say, if someone could give me an example with this code of a better way, I'd really appreciate it

    Code:

    Code:
        public List<String> thorcooldown = new ArrayList<String>();
    
    Code:
    @EventHandler(priority = EventPriority.NORMAL)
        // Thor event
        public void onPlayerThor(PlayerInteractEvent e) {
            final Player p = e.getPlayer();
            if (plugin.currentKit.containsKey(p.getName())) {
                if (!(plugin.currentKit.get(p.getName()).equals(PlayerKits.Thor))) {
                    return;
                }
                if (plugin.currentKit.get(p.getName()).equals(PlayerKits.Thor)
                        && (e.getAction() == Action.RIGHT_CLICK_AIR)
                        || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                    {
                        ItemStack hand = p.getItemInHand();
    
                        if ((hand.getType() == Material.IRON_AXE)) {
                            if (plugin.thorcooldown.contains(p.getName())) {
                                p.sendMessage(ChatColor.GRAY
                                        + "You can not use this yet!");
                            } else {
                                Location loc = p.getTargetBlock((Set<Material>) null, 20).getLocation();
                                p.addPotionEffect(new PotionEffect(
                                        PotionEffectType.DAMAGE_RESISTANCE, 20, 50));
                                p.getWorld().strikeLightning(loc);
                                plugin.thorcooldown.add(p.getName());
                                plugin.getServer()
                                .getScheduler()
                                .scheduleSyncDelayedTask(plugin,
                                        new Runnable() {
                                    public void run() {
                                        plugin.thorcooldown
                                        .remove(p.getName());
                                    }
                                }, 6 * 20);
                            }
                        }
                    }
                }
            }
        }
     
  2. Offline

    Zombie_Striker

  3. Offline

    N00BHUN73R

    @Fhbgsdhkfbl
    Take a look at using System.currentTimeMillis();
    Log the time they use it and keep comparing it inside a loop and if the time is up, remove em from the map
     
Thread Status:
Not open for further replies.

Share This Page