Solved Help with subtraction

Discussion in 'Plugin Development' started by bubblefat_, Jun 17, 2015.

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

    bubblefat_

    I'm making something to save in-game time. They way I'm doing it is saving the System.currentTimeMillis() in a config under the players name, then when they leave its supposed to subtract the current System.currentTimeMillis() although it isn't working.

    Code:
            Long leave_timestamp = System.currentTimeMillis();
            Long join_timestamp = Main.config.getLong(Main.config.getString(player.getName() + ".JoinTime"));
            Long time_played = leave_timestamp - join_timestamp;
                
            Main.config.set(player.getName() + ".Time", Main.config.getLong(player.getName() + ".Time") + time_played);
            Main.saveFile();
     
  2. Offline

    teej107

    What isn't working about it? Could I make a guess and say that it has something to do about your two different config paths you are using?
     
  3. Offline

    bubblefat_

    @teej107
    When the player joins it adds the currentTimeMillis to the config under the players name as "JoinTime". Then when they leave its supposed to get the currentTimeMillis of the time when the player leaves then subtract time they left from the time they joined and add it to the config under the players name as "Time". When it doesn't subtract time they left from the time they joined.
     
  4. Offline

    caderape

    @bubblefat_ do the substraction outside of the set method.
    I know a list can't be modified in the config file. You have to get back the list, do changement, and set again.
    It might be the same for this.
     
  5. Offline

    bubblefat_

    @caderape I found the problem. I was doing
    Main.config.getLong(Main.config.getString(player.getName() + ".JoinTime")); and I should have been doing
    Long joinTimestamp = Main.config.getLong(player.getName() + ".JoinTime");
     
Thread Status:
Not open for further replies.

Share This Page