diff options
| author | Linnea Gräf <roman.graef@gmail.com> | 2023-08-30 13:09:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-30 21:09:51 +1000 |
| commit | 25440fae997ec65ac8aef795d746b91a9466c462 (patch) | |
| tree | 6b28ecfc3d81a73cf9cba52e7f43e1168bcb9020 /src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java | |
| parent | 94a5760c419628f7b5a07c284880569e4149cd12 (diff) | |
| download | notenoughupdates-25440fae997ec65ac8aef795d746b91a9466c462.tar.gz notenoughupdates-25440fae997ec65ac8aef795d746b91a9466c462.tar.bz2 notenoughupdates-25440fae997ec65ac8aef795d746b91a9466c462.zip | |
Add star cult to neucalendar (#806)
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java b/src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java index 4c4fe02d..fadfef40 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java @@ -55,8 +55,32 @@ public class StarCultCalculator { private static long activeTill = 0; public static String getNextStarCult() { - Instant instantNow = Instant.now(); - long nowEpoch = instantNow.toEpochMilli(); + Instant cultStart = getNextStarCultTime(); + + long l = System.currentTimeMillis(); + if (cultStart.toEpochMilli() - l <= 1000) { + active = true; + activeTill = l + 300000; + } + + if (l > activeTill) { + active = false; + activeTill = 0; + } + + if (active && activeTill != 0) { + return "Active! (" + Utils.prettyTime(activeTill - System.currentTimeMillis()) + ")"; + } + + return Utils.prettyTime(cultStart.toEpochMilli() - l); + } + + public static Instant getNextStarCultTime() { + return getNextStarCultTime(Instant.now()); + } + + public static Instant getNextStarCultTime(Instant after) { + long nowEpoch = after.toEpochMilli(); long currentOffset = (nowEpoch - YEAR_0) % YEAR_MS; int currentMonth = (int) Math.floorDiv(currentOffset, MONTH_MS); @@ -72,7 +96,7 @@ public class StarCultCalculator { } Instant cultStart = Instant.ofEpochMilli( YEAR_0 + (getSkyblockYear() - 1) * YEAR_MS + currentMonth * MONTH_MS + (out - 1) * DAY_MS); - if (cultStart.isBefore(instantNow)) { + if (cultStart.isBefore(after)) { int curYearCult = getSkyblockYear() - 1; if (out == 28) { out = 7; @@ -88,23 +112,7 @@ public class StarCultCalculator { out--; cultStart = Instant.ofEpochMilli(YEAR_0 + (curYearCult) * YEAR_MS + currentMonth * MONTH_MS + out * DAY_MS); } - - long l = System.currentTimeMillis(); - if (cultStart.toEpochMilli() - l <= 1000) { - active = true; - activeTill = l + 300000; - } - - if (l > activeTill) { - active = false; - activeTill = 0; - } - - if (active && activeTill != 0) { - return "Active! (" + Utils.prettyTime(activeTill - System.currentTimeMillis()) + ")"; - } - - return Utils.prettyTime(cultStart.toEpochMilli() - l); + return cultStart; } } |
