Solved Command cooldown

Discussion in 'Plugin Development' started by Spark61, Oct 17, 2018.

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

    timtower Administrator Administrator Moderator

    @Spark61 That format is readable, but not very easy to compare.
     
  2. Offline

    Spark61

    Okay, how else can I do better?
     
  3. Online

    timtower Administrator Administrator Moderator

  4. Offline

    Spark61

    I'd rather do it like I do in my config. Since then you can also read off the date
     
  5. Online

    timtower Administrator Administrator Moderator

    Then you need to parse it somehow and compare it to the current date.
     
  6. Offline

    Spark61

  7. Online

    timtower Administrator Administrator Moderator

    Don't know, I use milliseconds for things like this because I don't mind how it looks in the config.
     
  8. Offline

    Spark61

    well then I do it with milliseconds that would be so right?
    Code:
                      long now = System.currentTimeMillis();
                        long config = Kopf.getInstance().getConfig().getLong("head." + p.getName());
                       
                        if(now > config) {
                        }
    
     
  9. Online

    timtower Administrator Administrator Moderator

  10. Offline

    Spark61

    Can I somehow make days out of the Millis again? If, in fact, the cooldown has not expired then the number of days you have to wait is there
     
  11. Online

    timtower Administrator Administrator Moderator

  12. Offline

    Spark61

  13. Online

    timtower Administrator Administrator Moderator

    It was not in English
     
  14. Offline

    Spark61

    Oh sry

    2592000000L are 30 days. but I am always indicated that I only have to wait 24 days

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 25, 2018
  15. Online

    timtower Administrator Administrator Moderator

  16. Offline

    Spark61

    Code:
                    if(p.hasPermission("head")) {
    
                        long now = System.currentTimeMillis();
                        long config = Kopf.getInstance().getConfig().getLong("head." + p.getName());
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTimeInMillis(config);
    
                        int day = calendar.get(Calendar.DAY_OF_MONTH);
                        int hour = calendar.get(Calendar.HOUR_OF_DAY);
                        int minute = calendar.get(Calendar.MINUTE);
                        int second = calendar.get(Calendar.SECOND);
                      
                        if(now > config) {
                            if(args.length == 1) {
    
                                  KopfManager.playerSkullForName(args[0]);
                                      p.sendMessage(Utils.prefix + "§aYou have received the head of §e" + KopfManager.getName(args[0]));
                                  Kopf.getInstance().getConfig().set("head." + p.getName(), now + 2592000000L);
                                  Kopf.getInstance().saveConfig();
                            
                          }
                        } else {
                              p.sendMessage(Utils.prefix + "You still have to wait for "+ day +" days "+ hour +" Sunden "+ minute +" minutes "+ second +" seconds§a");
                          }
                
                    } else
                        p.hasPermission(Utils.perms);
     
  17. Online

    timtower Administrator Administrator Moderator

    @Spark61 You never calculate the difference though.
    And when you do that then I would use math to calculate the times.
     
  18. Offline

    Spark61

    do you have an idea why this is not possible and I could do it with math but eigenltich it is so synonymous and this is easier
     
  19. Online

    timtower Administrator Administrator Moderator

    @Spark61 Because you never calculate the time that the user still has to wait.
     
  20. Offline

    Spark61

    Okay

    how can I calculate that?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 25, 2018
  21. Online

    timtower Administrator Administrator Moderator

    @Spark61 Current time (now) minus the saved time (config)
     
  22. Offline

    Spark61

    How can I calculate exactly how many days, hours, minutes and seconds you have to wait?
     
  23. Online

    timtower Administrator Administrator Moderator

  24. Offline

    Spark61

    I have it like the link but it is wrong
    Code:
    if(p.hasPermission("head.user")) {
    
                        long now = System.currentTimeMillis();
                        long config = Kopf.getInstance().getConfig().getLong("head." + p.getName());
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTimeInMillis(config);
    
    
                        long second = now - config / 1000;
                        long minute = second / 60;
                        long hour = minute / 60;
                        long day = hour / 24;
                        String time = day + ":" + hour % 24 + ":" + minute % 60 + ":" + second % 60;
                       
                        if(now > config) {
    
                            if(args.length == 1) {
    
                                  KopfManager.playerSkullForName(args[0]);
                                  p.sendMessage(Utils.prefix + "§aYou have received the head of §e" + KopfManager.getName(args[0]));
                                  Kopf.getInstance().getConfig().set("head." + p.getName(), now + 2592000000L);
                                  Kopf.getInstance().saveConfig();
                             
                          }
                        } else {
                              p.sendMessage(Utils.prefix + "You have to wait §e" + time );
                          }
                 
                    } else
                        p.hasPermission(Utils.perms);
    upload_2018-10-26_16-59-40.png

    I've changed the message and noticed that time is getting more and less instead of less
    @timtower
    upload_2018-10-26_17-17-26.png
     
    Last edited by a moderator: Oct 26, 2018
  25. Online

    timtower Administrator Administrator Moderator

    @Spark61 That is a math thing:
    now-config/1000 runs as now-(config/1000)
    You need
    (config-now)/1000
     
  26. Offline

    Spark61

    thank you verry much
     
Thread Status:
Not open for further replies.

Share This Page