Cooldowns

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

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

    C0lA_K1nG

    I need to know how to make a cooldown so players cannot keep doing the command repeatedly. The cooldown should last an hour

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase(getConfig().getString("Command"))){
                if(sender.hasPermission("iNeed.Ask")){
                    if(args.length == 0){
                        String Message = getConfig().getString("Message").replace("{name}", sender.getName());
                        sender.sendMessage(getConfig().getString("Prefix") + " " + Message);
                    }
                }
            }
            return false;
        }
    }
     
  2. Offline

    AtomSponge

    C0lA_K1nG Declare a Map<String, Date>, where String is the player name and Date the current date. When a player runs that command, check if the map contains their name, compare the date from the map with the current date and if the difference equals or is greater than 1 hour, remove them from your map and run your stuff. If they didn't run it before, add them to the map.
     
  3. Offline

    Barnyard_Owl

    You can create an arraylist of the names of players on cooldown. (ArrayList<String>)
    Whenever someone runs the command, check if they are on the cooldown list. If not, then run the command, put them on the list, and schedule a BukkitRunnable to remove them from the arraylist.
    You can set the runnable to run in an hour with runTaskLater().

    Edit: Ninja'd
     
Thread Status:
Not open for further replies.

Share This Page