Solved Milliseconds time problems

Discussion in 'Plugin Development' started by FreakyPear5, Mar 21, 2020.

  1. Offline

    FreakyPear5

    hi,

    I’m making a basic ban system for my server and I’m trying to make temp bans.

    The best way (I think) to do this is when the player is banned isget the current time in milliseconds and then add on the time arg from the command (which was converted to milliseconds) and then saved to the confit. However, even though I am adding them together in my code and then saving and reloading the config, while it does type into the config it doesn’t add the two numbers together and instead puts the argument’s translated time.

    How do I make them add together? I can’t find anything on the Internet after a few google searches.

    Thanks,
    Lawrence H.
     
  2. Offline

    timtower Moderator Moderator

  3. Offline

    FreakyPear5

    List<String> tempbans = Main.getPlugin(Main.class).getConfig().getStringList("tempbans");
    tempbans.remove(str);
    TimeUnit timeunit = TimeUnit.valueOf(args[2].toUpperCase());
    long currentTime = System.currentTimeMillis();
    long toMillis = timeunit.toMillis(Long.parseLong(args[1]));
    long time = currentTime + toMillis;
    tempbans.add(target.getUniqueId().toString()+":"+time);
    Main.getPlugin(Main.class).getConfig().set("tempbans", tempbans);
    Main.getPlugin(Main.class).saveConfig();
    Main.getPlugin(Main.class).reloadConfig();

    I don't know how to format it to display code better
     
  4. Offline

    timtower Moderator Moderator

    @FreakyPear5 And what do you see if you print both values?
    And the combined one of course.
     
  5. Offline

    FreakyPear5

    Sorry, it turns out I was tired and was looking in the wrong place. I was setting the config continuously in a loop but then changing it back afterwards. I've removed that from the for loop and fixed the last line and now it works.
    Sorry for bothering you!
     
    timtower likes this.

Share This Page