aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java
diff options
context:
space:
mode:
authorefefury <69400149+efefury@users.noreply.github.com>2022-11-25 09:52:10 +0000
committerGitHub <noreply@github.com>2022-11-25 20:52:10 +1100
commitc2ec12edd5d8e32665edd620ffa2267c5a0a56aa (patch)
treefc824092bdccb1ad3b15fb6cc5045bb7ba73d273 /src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java
parenta17412e1f1c829dd6d085b4849dae4ca571fd16b (diff)
downloadnotenoughupdates-c2ec12edd5d8e32665edd620ffa2267c5a0a56aa.tar.gz
notenoughupdates-c2ec12edd5d8e32665edd620ffa2267c5a0a56aa.tar.bz2
notenoughupdates-c2ec12edd5d8e32665edd620ffa2267c5a0a56aa.zip
fix star cult (#445)
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.java27
1 files changed, 23 insertions, 4 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 61aae416..02ec5ad3 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java
@@ -51,13 +51,17 @@ public class StarCultCalculator {
return (int) (currentYear + 1);
}
- public static long getNextStarCult() {
+ private static boolean active = false;
+ private static long activeTill = 0;
+
+ public static String getNextStarCult() {
Instant instantNow = Instant.now();
long nowEpoch = instantNow.toEpochMilli();
long currentOffset = (nowEpoch - YEAR_0) % YEAR_MS;
int currentMonth = (int) Math.floorDiv(currentOffset, MONTH_MS);
int currentDay = (int) Math.floorDiv((currentOffset - (long) currentMonth * MONTH_MS) % MONTH_MS, DAY_MS) + 1;
+
int out = 7;
if (currentDay > 21) {
out = 28;
@@ -66,9 +70,8 @@ public class StarCultCalculator {
} else if (currentDay > 7) {
out = 14;
}
- out--;
Instant cultStart = Instant.ofEpochMilli(
- YEAR_0 + (getSkyblockYear() - 1) * YEAR_MS + currentMonth * MONTH_MS + out * DAY_MS);
+ YEAR_0 + (getSkyblockYear() - 1) * YEAR_MS + currentMonth * MONTH_MS + (out - 1) * DAY_MS);
if (cultStart.isBefore(instantNow)) {
int curYearCult = getSkyblockYear() - 1;
if (out == 28) {
@@ -82,10 +85,26 @@ public class StarCultCalculator {
} else {
out += 7;
}
+ out--;
cultStart = Instant.ofEpochMilli(YEAR_0 + (curYearCult) * YEAR_MS + currentMonth * MONTH_MS + out * DAY_MS);
}
- return cultStart.toEpochMilli();
+ 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!";
+ }
+
+ return Utils.prettyTime(cultStart.toEpochMilli() - l);
}
}