How do I make a cooldown? And if the player tries to do the command it says how long more until you can do the command. I am making a kitpvp plugin with eclipse.
david123718 When the player issues the command you want to add a cooldown for, store the command, the current time (System.currentTimeMillis()) and the length of the cooldown: Code:java Map<String, CommandCooldown> cooldowns; CommandCooldown is an arbitrary class name where you can retrieve the time you issued the command (getIssueTime()) and the length of the cooldown (getCooldown()). An example usage for adding a new cooldown to the map: Code:java CommandCooldown cooldown = new CommandCooldown();cooldown.setIssueTime(System.currentTimeMillis());cooldown.setCooldown(3600000); //1 hour = 3600000 milliseconds. cooldowns.put(commandName, cooldown); When you want to check to see if the cooldown has passed, you would do something along the lines of this: Code:java boolean cooldownPassed = System.currentTimeMillis() - cooldowns.get(commandName).getIssueTime() >= cooldowns.get(commandName).getCooldown(); If you want to retrieve the remaining length of the cooldown, you would do: Code:java long remainingTime = cooldowns.get(commandName).getCooldown() - (System.currentTimeMillis() - cooldowns.get(commandName).getIssueTime());
Sorry Im confused can you give me a example please? Bump EDIT by Moderator: merged posts, please use the edit button instead of double posting.
david123718 I won't get any alerts if you don't Tahg me or reply to me, be sure to do that when replying.