diff options
author | NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> | 2022-11-26 07:57:35 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-25 21:57:35 +0100 |
commit | 7db5251c1cf9558b6d310b39a596d94850738c82 (patch) | |
tree | 159931bb08a60a041f588da11ea3ee4f92bb0633 /src/main | |
parent | 72904df8c50260e76a784457a5e78a20e4a80b65 (diff) | |
download | NotEnoughUpdates-7db5251c1cf9558b6d310b39a596d94850738c82.tar.gz NotEnoughUpdates-7db5251c1cf9558b6d310b39a596d94850738c82.tar.bz2 NotEnoughUpdates-7db5251c1cf9558b6d310b39a596d94850738c82.zip |
Fix todo overlay (#432)
Co-authored-by: nopo <nopotheemail@gmail.com>
Co-authored-by: heyngra <heyngra.wspolpraca@gmail.com>
Co-authored-by: jani270 <jani270@gmx.de>
Co-authored-by: Taoshi <nicolaikh@live.dk>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java | 44 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java | 142 |
2 files changed, 112 insertions, 74 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 fede9bdf..ab8c5e57 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java @@ -74,22 +74,38 @@ public class CookieWarning { return; } if (timeLine != null) { - String[] digits = timeLine.split(" "); + String[] digits = timeLine.replaceAll("(\u00a7.)", "").split(" "); int minutes = 0; try { - for (String digit : digits) { - if (digit.endsWith("y")) { - digit = digit.substring(0, digit.length() - 1); - minutes += Integer.parseInt(digit) * 525600; - } else if (digit.endsWith("d")) { - digit = digit.substring(0, digit.length() - 1); - minutes += Integer.parseInt(digit) * 1440; - } else if (digit.endsWith("h")) { - digit = digit.substring(0, digit.length() - 1); - minutes += Integer.parseInt(digit) * 60; - } else if (digit.endsWith("m")) { - digit = digit.substring(0, digit.length() - 1); - minutes += Integer.parseInt(digit); + for (int i = 0; i < digits.length; i++) { + if (i % 2 == 1) continue; + + String number = digits[i]; + String unit = digits[i + 1]; + long val = Integer.parseInt(number); + switch (unit) { + 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 } } catch (NumberFormatException e) { 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 730cb17f..a276f207 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java @@ -53,7 +53,7 @@ import static net.minecraft.util.EnumChatFormatting.DARK_AQUA; 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([0-9]*?:?[0-9]*?:?[0-9]*)\u00a7r"); + "\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])?(m|s)?\u00a7r"); public TimersOverlay( Position position, @@ -231,6 +231,8 @@ public class TimersOverlay extends TextTabOverlay { super.renderLine(line, position, dummy); } + boolean hasErrorMessage = false; + @Override public void update() { @@ -307,28 +309,44 @@ public class TimersOverlay extends TextTabOverlay { Matcher activeEffectsMatcher = PATTERN_ACTIVE_EFFECTS.matcher(line); if (activeEffectsMatcher.matches()) { foundGodPotText = true; - String[] godpotRemaingTimeUnformatted = activeEffectsMatcher.group(1).split(":"); long godPotDuration = 0; try { - int i = 0; - if (godpotRemaingTimeUnformatted.length == 4) { - godPotDuration = - godPotDuration + (long) Integer.parseInt(godpotRemaingTimeUnformatted[i]) * 24 * 60 * 60 * 1000; - i++; - } - if (godpotRemaingTimeUnformatted.length >= 3) { - godPotDuration = - godPotDuration + (long) Integer.parseInt(godpotRemaingTimeUnformatted[i]) * 60 * 60 * 1000; - i++; - } - if (godpotRemaingTimeUnformatted.length >= 2) { - godPotDuration = godPotDuration + (long) Integer.parseInt(godpotRemaingTimeUnformatted[i]) * 60 * 1000; - i++; + 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; + } } - if (godpotRemaingTimeUnformatted.length >= 1) { - godPotDuration = godPotDuration + (long) Integer.parseInt(godpotRemaingTimeUnformatted[i]) * 1000; + } catch (Exception e) { + e.printStackTrace(); + if (!hasErrorMessage) { + Utils.addChatMessage(EnumChatFormatting.YELLOW + "[NEU] Unable to work out your god pot timer"); + hasErrorMessage = true; } - } catch (Exception ignored) { + break; } hidden.godPotionDuration = godPotDuration; @@ -336,50 +354,54 @@ public class TimersOverlay extends TextTabOverlay { } else if (line.contains("\u00a7d\u00a7lCookie Buff")) { foundCookieBuffText = true; } else if (foundCookieBuffText) { - String cleanNoSpace = line.replaceAll("(\u00a7.| )", ""); - + String clean = line.replaceAll("(\u00a7.)", ""); + String[] cleanSplit = clean.split(" "); hidden.cookieBuffRemaining = 0; - StringBuilder number = new StringBuilder(); - for (int i = 0; i < cleanNoSpace.length(); i++) { - char c = cleanNoSpace.charAt(i); - - if (c >= '0' && c <= '9') { - number.append(c); - } else { - if (number.length() == 0) { - hidden.cookieBuffRemaining = 0; - break; - } - if ("ydhms".contains("" + c)) { - try { - long val = Integer.parseInt(number.toString()); - switch (c) { - case 'y': - hidden.cookieBuffRemaining += val * 365 * 24 * 60 * 60 * 1000; - break; - case 'd': - hidden.cookieBuffRemaining += val * 24 * 60 * 60 * 1000; - break; - case 'h': - hidden.cookieBuffRemaining += val * 60 * 60 * 1000; - break; - case 'm': - hidden.cookieBuffRemaining += val * 60 * 1000; - break; - case 's': - hidden.cookieBuffRemaining += val * 1000; - break; - } - } catch (NumberFormatException e) { - hidden.cookieBuffRemaining = 0; - break; - } - number = new StringBuilder(); - } else { - hidden.cookieBuffRemaining = 0; - break; + for (int i = 0; i < cleanSplit.length; i++) { + if (i % 2 == 1) continue; + + String number = cleanSplit[i]; + String unit = cleanSplit[i + 1]; + try { + long val = Integer.parseInt(number); + switch (unit) { + case "Years": + case "Year": + hidden.cookieBuffRemaining += val * 365 * 24 * 60 * 60 * 1000; + break; + case "Months": + case "Month": + hidden.cookieBuffRemaining += val * 30 * 24 * 60 * 60 * 1000; + break; + case "Days": + case "Day": + hidden.cookieBuffRemaining += val * 24 * 60 * 60 * 1000; + break; + case "Hours": + case "Hour": + case "h": + hidden.cookieBuffRemaining += val * 60 * 60 * 1000; + break; + case "Minutes": + case "Minute": + case "m": + hidden.cookieBuffRemaining += val * 60 * 1000; + break; + case "Seconds": + case "Second": + case "s": + hidden.cookieBuffRemaining += val * 1000; + break; + } + } catch (NumberFormatException e) { + e.printStackTrace(); + hidden.cookieBuffRemaining = 0; + if (!hasErrorMessage) { + Utils.addChatMessage(EnumChatFormatting.YELLOW + "[NEU] Unable to work out your cookie buff timer"); + hasErrorMessage = true; } + break; } } |