Cooldown

Discussion in 'Plugin Development' started by C0lA_K1nG, Mar 15, 2014.

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

    C0lA_K1nG

  2. Offline

    Amgis

    C0lA_K1nG
    What do you mean by cooldown? Cooldown what, exactly?
     
  3. Offline

    jeussa

    You can simply create a cooldown using the following:

    1. We need a list of players which are on the cooldown (I always store the name of the player because when storing the player itself in a hashmap or arraylist, it sometimes glitches)
    Code:java
    1. public static ArrayList<String> playersOnCooldown = new ArrayList<String>();


    2. Add this on top of your plugin:
    Code:java
    1. public effect plugin;
    2.  
    3. public void onLoad(){
    4. plugin = this;
    5. }


    3. We need to check if the player isn't on a cooldown (place this inside your method) If they are not on a cooldown, we put them on a cooldown
    Code:java
    1. if(playersOnCooldown.contains(p.getName()){
    2. p.sendMessage("You are on a cooldown!");
    3. }else{
    4. playersOnCooldown.add(p.getName());
    5. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
    6. public void run(){
    7. playersOnCooldown.remove(p.getName());
    8. }
    9. }, 20*5); //Means 5 seconds (20 ticks = 1 second. 20 * 5 ticks = 5 seconds)
    10. //Perform your actions here
    11. }


    4. Also make sure you player 'final' in front of player p:
    Code:java
    1. final Player p = e.getPlayer();
     
Thread Status:
Not open for further replies.

Share This Page