How to set a cooldown using a Config?

Discussion in 'Plugin Development' started by elementalgodz11, Apr 9, 2014.

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

    elementalgodz11

    So I am trying to set a cooldown for a command, but instead of using a regular HashMap I need to use the config, so the cooldown still remains upon reloads.

    I have tried checking if a cooldown is existant and then sending a player a message with the remaining cooldown time, but the time left goes up by 1 every second instead of going down and is negative instead of positive: Example: http://prntscr.com/38gks4


    Snippet of code:
    Code:java
    1. if (plugin.getConfig().getString("Cooldowns.PvPKit." + p.getName()) != null) {
    2.  
    3. long s = plugin.getConfig().getLong("Cooldowns.PvPKit." + p.getName());
    4. long secondsLeft = s / 1000L + 3600 - System.currentTimeMillis() / 1000L;
    5.  
    6. if (s < (System.currentTimeMillis() - 3600L * 1000)) {
    7.  
    8. if (secondsLeft == 3600L) {
    9.  
    10. p.sendMessage(ChatColor.AQUA + "You cannot use the pvp kit for an hour!");
    11.  
    12. } else {
    13.  
    14. p.sendMessage(ChatColor.AQUA + "You cannot use the " + ChatColor.YELLOW + "PvP" + ChatColor.AQUA + " kit for another " +
    15. ChatColor.YELLOW + plugin.methods.millisToReadable(p, secondsLeft, (int)s) +
    16. ChatColor.AQUA + ".");
    17.  
    18. }
    19.  
    20. }
    21.  
    22. }


    Any help is appreciated. Thanks.

    Didn't want to double post and break formatting, but here's how I am setting the cooldown:
    Code:
    plugin.getConfig().set("Cooldowns.PvPKit." + p.getName(), Long.valueOf(System.currentTimeMillis()));
    plugin.saveConfig();
    N3rdFall
    This plugin was intended to spawn a Kit, that can only be used every hour. Therefore if the plugin is disabled the kit will be accessibly again.

    I also need to understand how this will work so I can use it for a custom tempbanning system.

    N3rdFall Thanks but I'm already aware on how to use setters and getters in Configuration files.

    What I'm trying to do is compare a long value to the Systems current time milliseconds (effectively a cooldown)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page