Need help with Kit Cooldown event! HELP!

Discussion in 'Plugin Development' started by mrgreen33gamer, Feb 12, 2014.

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

    mrgreen33gamer

    Hello, this has been bugging me for a while, I have been searching on the internet for the codes for a cooldown, i have the cooldown correct, i just need to fit it in the right place so it works

    Here is the eventclass:

    Code:
     
    @EventHandler
    public void onUseFeather(PlayerInteractEvent e){
    Action action = e.getAction();
    Player player = e.getPlayer();
     
    if (Main.swifty.contains(player.getName())) {
    if(e.getAction() == Action.RIGHT_CLICK_AIR && e.getItem().getType()==Material.FEATHER){
                 
    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 300, 3));
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 300, 3));
     
    }
            }
    }
     
    
    When i put this code in:
    Code:
    if (Main.swifty.contains(player.getName())) {
    }
    the cooldown doesn't work, i even have a post with a simple cooldown that doesn't even work on any of my kits, I really need a cooldown code to fit in here, if you have a code that I can use to fit into this, or you can just edit the code, please comment below

    :3

    ~mrgreen33gamer
     
  2. Offline

    Malatak1

    mrgreen33gamer What is swifty exactly? A HashSet/HashMap as a field of your main class?

    Not sure what your code is doing exactly right now in terms of cooldowns. Do you ever add the player to the swifty object?
     
  3. Offline

    mrgreen33gamer

    I am trying to add a cooldown, whenever a player uses the feather, they have like a 5 second cooldown to reuse the feather, i already know this:
    Code:
    ArrayList<String> cooldown= new ArrayList<String>();
     
  4. Offline

    Harmings

    mrgreen33gamer
    It isn't going to work if you don't add the player to that list
     
  5. Offline

    Wizehh

    Loll..
    Add them to array list, and schedule a delayed task to remove them from the list.
     
  6. Offline

    jthort

  7. Offline

    Malatak1

    mrgreen33gamer
    You could use a hashmap to store players names and then have the time in miliseconds they last used the ability as the value of the key/pair. Then whenever they try to use the ability, check if the current system time in miliseconds minus the last time they used it is greater than or less than the cooldown. Use logic based on that to determine if they are able to use the ability.

    The arraylist (or a hashset, which might work as well) method is great and all, but the method described above will allow you to provide players with feedback such as how much time is left until the cooldown is over - something that becomes much harder to do once you implement a system that doesn't store the times.

    That's just my take of course. Do as you please.
     
Thread Status:
Not open for further replies.

Share This Page