How Do I Create A Cooldown For A Command?

Discussion in 'Plugin Development' started by mkezar, Apr 22, 2014.

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

    mkezar

    Hi. Im making a plugin that kills everybody. I type the command and it works. I want a cooldown for 5 minutes so people dont spam the command because its really OP. Here is my plugin:
    Code:java
    1. package plugins.mkezar;
    2.  
    3. import java.util.List;
    4.  
    5. import org.bukkit.plugin.java.JavaPlugin;
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Sound;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Damageable;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.entity.Entity;
    14. public class Fusrodahs extends JavaPlugin {
    15. @SuppressWarnings("deprecation")
    16. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    17. final Player player = (Player)sender;
    18.  
    19.  
    20. if(commandLabel.equalsIgnoreCase("fusrohdah")) {
    21. //onCommand stuff
    22.  
    23. if(sender instanceof Player){
    24. Player player1 = (Player) sender;
    25. player.sendMessage(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + "FUS-ROH-DAH!");
    26. player1.playSound(player1.getLocation(),Sound.ENDERDRAGON_DEATH,1,1);
    27. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    28. public void run() {
    29.  
    30. }
    31. }, 6000L);
    32. List <Entity> entities = player1.getNearbyEntities(20,20,20);
    33. for(Entity e : entities){
    34. Damageable d = (Damageable) e;
    35. d.setHealth(0);
    36.  
    37.  
    38.  
    39. }
    40. }
    41. }
    42. return false;
    43.  
    44. }
    45. }
    46.  

    Thank you!!! :D
    -mkezar
     
  2. Offline

    webbhead

    Use an ArrayList.
     
  3. Offline

    mkezar

    webbhead This is good...... Could u send me a link to a tutorial or a desc about an ArrayList?
     
  4. Offline

    webbhead

  5. Offline

    mkezar

    webbhead This Is Not What I wanted :p I want a CoolDown not a freeze plugin. :p
     
  6. Offline

    Gater12

  7. Offline

    Adriani6

    mkezar

    You can still use an array, put player name in as index and time as value, when player chats, check when he last spoke (array value (time) - current time) if it's more than (>) 5 minutes remove player from array and send the command or else, cancel the event. When player quits make sure to remove him from array as well.

    Might be long and painful but that's just my idea lol.
     
Thread Status:
Not open for further replies.

Share This Page