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; } }
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.
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