Hi i have this code for cooldwon: Code:java public HashMap<String, Long> cooldowns = new HashMap<String, Long>(); int cooldownTime = 86400; if(cooldowns.containsKey(p.getName())) { long remeaningseconds = ((cooldowns.get(sender.getName()) / 1000) + cooldownTime) - (System.currentTimeMillis() / 1000); if(segundosrestabtes > 0){ int days= (int)(((double)segundosrestabtes / 5184000D - (double)(segundosrestabtes / 518400L)) * 60D); int houre= (int)(((double)segundosrestabtes / 216000D - (double)(segundosrestabtes / 216000L)) * 60D); int minutes = (int)(((double)segundosrestabtes / 3600D - (double)(segundosrestabtes / 3600L)) * 60D); int seconds = (int)(((double)segundosrestabtes / 60D - (double)(segundosrestabtes / 60L)) * 60D); if(remeaningseconds - 216000L > 0L){ // do somethings return true; } else if(remeaningseconds - 3600L > 0L){ // do somethings return true; } else if(remeaningseconds - 60L > 0){ // do somethings return true; } else { // do somethings return true; } } } cooldowns.put(p.getName(), System.currentTimeMillis()); //Command her! But when i restart server the cooldown restart to 0 seconds? Why can i solve this ??
peti446 The reason why it clears it when the server restarts/reloads is that all hashmaps, lists, etc are cleared when it restarts/reloads. To make it continue through a restart you have to save the remaining time of the cooldown somewhere, say, a database or a file. To learn how to save hashmaps to a file there are tons of threads already about that, just use the search bar.
create a ArrayList<String> are storge the player name, then check if he's on the ArrayList if he's this means he on cooldown, if he not do what you want and add him to the ArrayList^^ then use DelayedTask and choose time and then remove him from the list
1Achmed1 The guy in the video use an AsyncRepeatingTask and then he calls Bukkit methodes. That´s not a good model.
Code:java getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {public void run() {//code}}, <ticks delay>L, <ticks repeat>L);