Skip to content

Commit

Permalink
Block based on time more accurately
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Sep 30, 2024
1 parent d190730 commit 6bb5d81
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions server/src/main/java/com/soulfiremc/server/util/TimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ public boolean isReleasable() {
}

public boolean block() throws InterruptedException {
Thread.sleep(1);
return System.nanoTime() >= endTime;
var remainingTime = endTime - System.nanoTime();
if (remainingTime > 0) {
Thread.sleep(remainingTime / NANOSECONDS_PER_MILLISECOND, (int) (remainingTime % NANOSECONDS_PER_MILLISECOND));
}

return true;
}
});
} catch (InterruptedException e) {
Expand Down

0 comments on commit 6bb5d81

Please sign in to comment.