aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java
diff options
context:
space:
mode:
authorNopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com>2024-07-07 23:08:13 +1000
committerGitHub <noreply@github.com>2024-07-07 15:08:13 +0200
commit8f43c38d5b17fc48f4c4af483eebb8fccfead04c (patch)
tree361874962d90fc2bb95ee8926d8badfeb8be2b75 /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java
parentdc4cd12f82440345f2adb0d280e57ef42f60c5ae (diff)
downloadnotenoughupdates-8f43c38d5b17fc48f4c4af483eebb8fccfead04c.tar.gz
notenoughupdates-8f43c38d5b17fc48f4c4af483eebb8fccfead04c.tar.bz2
notenoughupdates-8f43c38d5b17fc48f4c4af483eebb8fccfead04c.zip
Fix Issues with Effects Tablist Widget (#1201)
Co-authored-by: jani270 <69345714+jani270@users.noreply.github.com>
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java105
1 files changed, 60 insertions, 45 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java
index 80fd4515..1691fff2 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java
@@ -21,12 +21,12 @@ package io.github.moulberry.notenoughupdates.miscfeatures;
import com.google.common.collect.Lists;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
-import io.github.moulberry.notenoughupdates.mixins.AccessorGuiPlayerTabOverlay;
+import io.github.moulberry.notenoughupdates.miscfeatures.tablisttutorial.TablistAPI;
import io.github.moulberry.notenoughupdates.util.NotificationHandler;
import io.github.moulberry.notenoughupdates.util.Utils;
-import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
+import java.util.List;
import java.util.Locale;
public class CookieWarning {
@@ -66,7 +66,7 @@ public class CookieWarning {
}
if (timeLine == null) return;
- int minutes = getMinutesRemaining(timeLine);
+ int minutes = (int) getMillisecondsRemaining(timeLine) / 60 / 1000;
if (minutes < NotEnoughUpdates.INSTANCE.config.notifications.boosterCookieWarningMins && !hasNotified) {
NotificationHandler.displayNotification(Lists.newArrayList(
"§cBooster Cookie Running Low!",
@@ -78,11 +78,11 @@ public class CookieWarning {
}
}
- private static int getMinutesRemaining(String timeLine) {
+ private static long getMillisecondsRemaining(String timeLine) {
String clean = timeLine.replaceAll("(§.)", "");
clean = clean.replaceAll("(\\d)([smhdy])", "$1 $2");
String[] digits = clean.split(" ");
- int minutes = 0;
+ long ms = 0;
try {
for (int i = 0; i < digits.length; i++) {
if (i % 2 == 1) continue;
@@ -90,30 +90,7 @@ public class CookieWarning {
String number = digits[i];
String unit = digits[i + 1];
long val = Integer.parseInt(number);
- switch (unit.toLowerCase(Locale.ROOT)) {
- case "years":
- case "year":
- minutes += val * 525600;
- break;
- case "months":
- case "month":
- minutes += val * 43200;
- break;
- case "days":
- case "day":
- minutes += val * 1440;
- break;
- case "hours":
- case "hour":
- case "h":
- minutes += val * 60;
- break;
- case "minutes":
- case "minute":
- case "m":
- minutes += val;
- break;
- } // ignore seconds
+ ms += (getCookieTimeRemainingInMilliseconds(unit, val));
}
} catch (NumberFormatException e) {
if (!hasErrorMessage) {
@@ -124,26 +101,34 @@ public class CookieWarning {
}
hasNotified = true;
}
- return minutes;
+ return ms;
}
private static String getTimeLine() {
- String[] lines;
- try {
- lines = ((AccessorGuiPlayerTabOverlay) Minecraft.getMinecraft().ingameGUI.getTabList())
- .getFooter()
- .getUnformattedText()
- .split("\n");
- } catch (NullPointerException ignored) {
- return null;
- }
+ List<String> lines = TablistAPI.getOptionalWidgetLines(TablistAPI.WidgetNames.ACTIVE_EFFECTS);
+ List<String> lines2 = TablistAPI.getOptionalWidgetLines(TablistAPI.WidgetNames.COOKIE_BUFF);
+ lines.addAll(lines2);
String timeLine = null; // the line that contains the cookie timer
- for (int i = 0; i < lines.length; i++) {
- if (lines[i].startsWith("Cookie Buff")) {
- timeLine = lines[i + 1]; // the line after the "Cookie Buff" line
+
+ for (int i = 0; i < lines.size(); i++) {
+ String line = lines.get(i);
+ line = Utils.cleanColour(line).trim();
+
+ if (line.startsWith("Cookie Buff:")) {
+ timeLine = line.replace("Cookie Buff: ", "");
+ if (timeLine.contains("INACTIVE")) {
+ hasCookie = false;
+ return null;
+ }
+ } else if (line.startsWith("Cookie Buff")) {
+ timeLine = lines.get(i + 1); // the line after the "Cookie Buff" line
+ timeLine = Utils.cleanColour(timeLine).trim();
}
- if (lines[i].startsWith("Not active! Obtain booster cookies from the")) {
+
+
+ if (line.startsWith("Not active! Obtain booster cookies from the")) {
hasCookie = false;
+ return null;
}
}
return timeLine;
@@ -161,8 +146,8 @@ public class CookieWarning {
String timeLine = getTimeLine();
if (hasCookie && timeLine != null) {
- int minutes = getMinutesRemaining(timeLine);
- cookieEndTime = System.currentTimeMillis() + (long) minutes * 60 * 1000;
+ long ms = getMillisecondsRemaining(timeLine);
+ cookieEndTime = System.currentTimeMillis() + ms;
} else {
cookieEndTime = 0;
}
@@ -178,4 +163,34 @@ public class CookieWarning {
hasCookie = true;
lastChecked = 0;
}
+
+ public static long getCookieTimeRemainingInMilliseconds(String godpotRemainingTimeType, long godpotRemainingTime) {
+ switch (godpotRemainingTimeType.toLowerCase(Locale.ROOT).replace(",", "")) {
+ case "years":
+ case "year":
+ case "y":
+ return godpotRemainingTime * 24 * 60 * 60 * 1000 * 30 * 12;
+ case "months":
+ case "month":
+ case "mo":
+ return godpotRemainingTime * 24 * 60 * 60 * 1000 * 30;
+ case "days":
+ case "day":
+ case "d":
+ return godpotRemainingTime * 24 * 60 * 60 * 1000;
+ case "hours":
+ case "hour":
+ case "h":
+ return godpotRemainingTime * 60 * 60 * 1000;
+ case "minutes":
+ case "minute":
+ case "m":
+ return godpotRemainingTime * 60 * 1000;
+ case "seconds":
+ case "second":
+ case "s":
+ return godpotRemainingTime * 1000;
+ }
+ return godpotRemainingTime;
+ }
}