diff options
Diffstat (limited to 'src')
-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; } } |