Kit Cooldowns

Discussion in 'Spigot Plugin Development' started by pas5w0rd, May 4, 2017.

  1. Hello there!

    I am currently working on a custom kit plugin. However, I am not sure how I could do a custom kit cooldown. Like, what if it was a week? How would I automatically change it after a week or a different time for multiple kits.

    Thanks!
    :D
     
  2. The way I'd do it is by simply creating a player data yml file, and then save how long until they can use their kit again in it. Maybe in minutes? Just so it's very accurate, and schedule a delayed task that runs every minute to count the number down to 0.
     
  3. Wouldn't that be quite server-intensive?
     
  4. Then use a HashMap with the saved time, and when the server shutsdown/the plugin is disabled, write the saved integer to the file.
     
  5. What about counting down? The other method, would be laggy, ey?
     
  6. How would reducing a number in a hashmap be laggy?
     
  7. True. I suppose it depends how many would be running- like one for every player's every kit?
     
  8. Yea it would depend probably
     
  9. Do you want the player to be notified when the kit is no longer on cooldown? If you don't care, you can just store a Long that corresponds to when the kit cooldown would be done. This long would be the currentTimeMillis plus however many milliseconds would pass when the kit's cooldown is done. When the player tries to get the kit, subtract the currentTimeMillis and check if the difference is greater than or equal to 0. If it is, the kit's cooldown is done.
     
  10. Get the date/time and store it alongside the players name. Have a runnable that checks it every minute/day/hour (depends how accurate you want to be) and if they're the same, delete it allowing the player to use the kit again.