From e222ef31708a0bef2bfb645255cf41d462b3da11 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Mon, 15 Jul 2024 05:08:46 +1000 Subject: Fix cookie with months or less than a hour (#1244) --- .../notenoughupdates/miscfeatures/CookieWarning.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 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 50259538..6de6b365 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java @@ -79,8 +79,11 @@ public class CookieWarning { } private static long getMillisecondsRemaining(String timeLine) { + if ("Less than an hour".equals(timeLine)) { + return 10 * 60 * 1000; //Return 10 minutes, they need more cookie! + } String clean = timeLine.replaceAll("(ยง.)", ""); - clean = clean.replaceAll("(\\d)([smhdy])", "$1 $2"); + clean = clean.replaceAll("(\\d)([smhdMy])", "$1 $2"); String[] digits = clean.split(" "); long ms = 0; try { @@ -92,7 +95,7 @@ public class CookieWarning { long val = Integer.parseInt(number); ms += (getEffectRemainingInMilliseconds(unit, val)); } - } catch (NumberFormatException e) { + } catch (Exception e) { if (!hasErrorMessage) { e.printStackTrace(); Utils.addChatMessage(EnumChatFormatting.RED + @@ -165,6 +168,13 @@ public class CookieWarning { } public static long getEffectRemainingInMilliseconds(String remainingTimeType, long remainingTime) { + switch (remainingTimeType.replace(",", "")) { + case "months": + case "month": + case "mo": + case "M": + return remainingTime * 24 * 60 * 60 * 1000 * 30; + } switch (remainingTimeType.toLowerCase(Locale.ROOT).replace(",", "")) { case "years": case "year": -- cgit