Can I make the constant #currentTimeMillis constant? when is the value added to it?

So, I'm trying to do System.currentTimeMillis (); constant. It is hard to explain. What the code should do is add a value to System.currentTimeMillis (); which it does and wait for the code to return true and then execute the action. So basically I'm trying to create a temp-ban system. Since System.currentTimeMillis is not a constant value, of course, this will return false. I am wondering what would I do to make this code true?

long timeleft = StaticMaps.muteMap.get(uuid).getTime() * 1000; //seconds to miliseconds
if (System.currentTimeMillis() >= timeleft + System.currentTimeMillis()) {
    plugin.mutemanager.destructPlayerMute(uuid, "Expired", "Removed by Console, Expired!");

} else {
    KTools.notify("debug");
    e.setCancelled(true);
}

Solution I used Save the value as "Long" inside the map using System.currentTimeMillis (); So what would you do this.

Map<UUID, Long> temp = new HashMap<>();
Long time = 3 * 1000; //3 * 1000 = 3 Seconds    
temp.put(Identifier, System.currentTimeMillis() + timetoadd)

timetoadd should be long.

, System.currentTimeMillis() >= hashmap.

  long HOUR = 3600000;
  long DAY = 86400000;
  long dayformula = Long.parseLong(parts[0]) * DAY;
  long hourformula = Long.parseLong(parts[1]) * HOUR;
  long totalmiliseconds = dayformula + hourformula;
+4
2

. .

:

long timeleft = StaticMaps.muteMap.get(uuid).getTime() * 1000; //seconds to miliseconds
long lastCheckedTime = System.currentTimeMillis();
if (System.currentTimeMillis() >= timeleft + lastCheckedTime) {
    plugin.mutemanager.destructPlayerMute(uuid, "Expired", "Removed by Console, Expired!");

} else {
    KTools.notify("debug");
    e.setCancelled(true);
}

... , , false, timeLeft .

+2

System.currentTimeMillis(); (var/value), var/value, , .


, timestamps ( ), / , map, schedule / , System.currentTimeMillis();, (), // (, ), ( ).


, schedule ( ) ...

, , :

    //How to "schedule" the lift...
    public /*static ?*/ void mutePlayer(??? uuid, long muteTime){
    StaticMaps.muteMap.put(uuid, System.currentTimeMillis()+muteTime); //I'm assuming how the syntax is...Adapt as needed.
     }

    //Somewhere else, inside a loop that runs periodically...
    for(Entry<uuid, long> scheduled : Staticamaps.muteMap.entrySet()){
    if (System.currentTimeMillis() >= scheduled.value() /*lift timestamp*/)) {
    plugin.mutemanager.destructPlayerMute(scheduled.key() /*uuid*/, "Expired", "Mute has expired!");
    } else {
    KTools.notify("debug");
    e.setCancelled(true);
    }
    }

, , , muteMap, , , pseudo-code.

+1

Source: https://habr.com/ru/post/1621660/


All Articles