diff options
| author | NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> | 2024-07-07 23:08:13 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-07 15:08:13 +0200 |
| commit | 8f43c38d5b17fc48f4c4af483eebb8fccfead04c (patch) | |
| tree | 361874962d90fc2bb95ee8926d8badfeb8be2b75 | |
| parent | dc4cd12f82440345f2adb0d280e57ef42f60c5ae (diff) | |
| download | notenoughupdates-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>
4 files changed, 111 insertions, 75 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; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java index 975e42ad..9eede66d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java @@ -22,6 +22,8 @@ package io.github.moulberry.notenoughupdates.overlays; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.events.SlotClickEvent; +import io.github.moulberry.notenoughupdates.miscfeatures.CookieWarning; +import io.github.moulberry.notenoughupdates.miscfeatures.tablisttutorial.TablistAPI; import io.github.moulberry.notenoughupdates.miscgui.customtodos.CustomTodoHud; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery; @@ -69,7 +71,7 @@ public class TimersOverlay extends TextTabOverlay { } private static final Pattern PATTERN_ACTIVE_EFFECTS = Pattern.compile( - "\u00a7r\u00a7r\u00a77You have a \u00a7r\u00a7cGod Potion \u00a7r\u00a77active! \u00a7r\u00a7d([1-5][0-9]|[0-9])[\\s|^\\S]?(Seconds|Second|Minutes|Minute|Hours|Hour|Day|Days|h|m|s) ?([1-5][0-9]|[0-9])?([ms])?\u00a7r"); + " You have a God Potion active! ([1-5][0-9]|[0-9])[\\s|^\\S]?(Seconds|Second|Minutes|Minute|Hours|Hour|Day|Days|h|m|s) ?([1-5][0-9]|[0-9])?([ms])?"); private static final Pattern CAKE_PATTERN = Pattern.compile( "§r§d§l(?:Big )?Yum! §r§eYou (?:refresh|gain) §r§.+ §r§efor §r§a48 §r§ehours!§r"); private static final Pattern PUZZLER_PATTERN = @@ -84,6 +86,7 @@ public class TimersOverlay extends TextTabOverlay { "\u00a7r\u00a79\u1805 \u00a7r\u00a7fYou've earned \u00a7r\u00a7d.+ Gemstone Powder \u00a7r\u00a7ffrom mining your first Gemstone of the day!\u00a7r"); private static final Pattern DAILY_SHOP_LIMIT = Pattern.compile( "\u00a7r\u00a7cYou may only buy up to 6,?400? of this item each day!\u00a7r"); + private static final Pattern GOD_POTION_TIME = Pattern.compile(" God Potion: ([1-5][0-9]|[0-9])([dhms])"); @SubscribeEvent public void onClickItem(SlotClickEvent event) { @@ -470,44 +473,27 @@ public class TimersOverlay extends TextTabOverlay { boolean foundEffectsText = false; if (SBInfo.getInstance().getLocation() != null && !SBInfo.getInstance().getLocation().equals("dungeon") && SBInfo.getInstance().footer != null) { - String formatted = SBInfo.getInstance().footer.getFormattedText(); - for (String line : formatted.split("\n")) { + List<String> effectsLine = TablistAPI.getOptionalWidgetLines(TablistAPI.WidgetNames.ACTIVE_EFFECTS); + for (String line : effectsLine) { + line = Utils.cleanColour(line); if (line.contains("Active Effects")) { foundEffectsText = true; } Matcher activeEffectsMatcher = PATTERN_ACTIVE_EFFECTS.matcher(line); + Matcher godPotionMatcher = GOD_POTION_TIME.matcher(line); + String godpotRemainingTimeType = null; + long godpotRemainingTime = 0; + long godPotDuration = 0; + if (activeEffectsMatcher.matches()) { foundGodPotText = true; - long godPotDuration = 0; try { - long godpotRemainingTime; for (int i = 1; i < activeEffectsMatcher.groupCount(); i += 2) { if (activeEffectsMatcher.group(i) == null) { continue; } godpotRemainingTime = Integer.parseInt(activeEffectsMatcher.group(i)); - String godpotRemainingTimeType = activeEffectsMatcher.group(i + 1); - switch (godpotRemainingTimeType) { - case "Days": - case "Day": - godPotDuration += godpotRemainingTime * 24 * 60 * 60 * 1000; - break; - case "Hours": - case "Hour": - case "h": - godPotDuration += godpotRemainingTime * 60 * 60 * 1000; - break; - case "Minutes": - case "Minute": - case "m": - godPotDuration += godpotRemainingTime * 60 * 1000; - break; - case "Seconds": - case "Second": - case "s": - godPotDuration += godpotRemainingTime * 1000; - break; - } + godpotRemainingTimeType = activeEffectsMatcher.group(i + 1); } } catch (Exception e) { if (!hasErrorMessage) { @@ -517,9 +503,15 @@ public class TimersOverlay extends TextTabOverlay { } break; } - + } else if (godPotionMatcher.matches()) { + foundGodPotText = true; + godpotRemainingTime = Integer.parseInt(godPotionMatcher.group(1)); + godpotRemainingTimeType = godPotionMatcher.group(2); + } + if (godpotRemainingTimeType != null) { + godPotDuration += + CookieWarning.getCookieTimeRemainingInMilliseconds(godpotRemainingTimeType, godpotRemainingTime); hidden.godPotionDuration = godPotDuration; - } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java index f7357343..a002729b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java @@ -23,6 +23,7 @@ import com.google.common.collect.ComparisonChain; import com.google.common.collect.Ordering; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; import io.github.moulberry.notenoughupdates.events.TabListChangeEvent; +import io.github.moulberry.notenoughupdates.mixins.AccessorGuiPlayerTabOverlay; import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.scoreboard.ScorePlayerTeam; @@ -87,6 +88,32 @@ public class TabListUtils { String name = Minecraft.getMinecraft().ingameGUI.getTabList().getPlayerName(info); result.add(name); } + + ArrayList<String> lines = null; + try { + String[] footer = ((AccessorGuiPlayerTabOverlay) Minecraft.getMinecraft().ingameGUI.getTabList()) + .getFooter().getFormattedText() + .split("\n"); + lines = new ArrayList<>(); + boolean seenBlank = false; + for (String line : footer) { + if (line.equals("§r§r§r§r§s§r") || line.equals("§r")) { + seenBlank = true; //This is to emulate the space every other widget has for its lines + continue; + } + if (seenBlank) { + lines.add(line); + seenBlank = false; + } else { + lines.add(" " + line); + } + } + } catch (NullPointerException ignored) { + } + + if (lines != null) { + result.addAll(lines); + } return result; } } diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/tablisttutorial/TablistAPI.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/tablisttutorial/TablistAPI.kt index c9f1c60e..756412a8 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/tablisttutorial/TablistAPI.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/tablisttutorial/TablistAPI.kt @@ -145,7 +145,9 @@ object TablistAPI { TRAPPER(null), FORGE(Regex("Forges:( \\(\\d/\\d\\))?")), POWDER(Regex.fromLiteral("Powders:")), - PROFILE(Regex("Profile: ([A-Za-z]+)( .*)?")) + PROFILE(Regex("Profile: ([A-Za-z]+)( .*)?")), + ACTIVE_EFFECTS(Regex("Active Effects(: \\(\\d+\\))?")), + COOKIE_BUFF(Regex("Cookie Buff")), ; override fun toString(): String { |
