Need help adding cooldown on a kit abbilitie

Discussion in 'Plugin Development' started by Nonliker1000, Nov 12, 2014.

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

    Nonliker1000

    Hey guys,
    I am trying to add a 3 second cooldown on my kit abbilitie, but i dont know how to add one.
    Anyways heres the code: http://pastebin.com/R75vhP96
    Thanks for the help in advance :)
     
  2. Offline

    Skionz

    HashMaps and System.currentTimeMillis
     
  3. Offline

    jensdeboom

    Nonliker1000 If you want to be able to display the amount of time left (like when he tries to ctivate his ability again) you'd have to go with Skionz way. If you don't need to display the cooldown, store the playername in an arraylist, start a delayed task at 60 ticks and remove them from the arraylist when the cooldown is over.
     
  4. Offline

    Cyber_Pigeon

    Create a arraylist, and check if they are in it when the event is fired, and if they are, it will tell them they are on cooldown.

    Code:java
    1. ArrayList<String> cooldown = new ArrayList<String>
    2.  
    3. @EventHandler
    4. public void onTest(PlayerInteractEvent e){
    5. final Player p = e.getPlayer();
    6. //e.getAction crap here
    7.  
    8. if(cooldown.contains(p.getName()){
    9. p.sendMessage("You are on cooldown!");
    10. } else{
    11. p.sendMessage("You used your ability!");
    12. cooldown.add(p.getName());
    13. Bukkit.getScheduler().runTaskLater(this, new Runnable() {
    14.  
    15. public void run(){
    16. cooldown.remove(p.getName);
    17. p.sendMessage("You are no longer on cooldown!");
    18. }, 100); //This is 5 seconds.
    19.  
    20. }
    21. }


    Like this ^^
     
Thread Status:
Not open for further replies.

Share This Page