aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2023-02-13 14:03:22 +0100
committerGitHub <noreply@github.com>2023-02-13 14:03:22 +0100
commit3d9a03ff4f1e542339950be6a77cb4c59a46ab77 (patch)
tree30b12a35fbac1a07b57e35ba7ecf7c5d7c6a4500 /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java
parente87331858675faed39a090cfdd6f6c7ce3b3f0d0 (diff)
downloadnotenoughupdates-3d9a03ff4f1e542339950be6a77cb4c59a46ab77.tar.gz
notenoughupdates-3d9a03ff4f1e542339950be6a77cb4c59a46ab77.tar.bz2
notenoughupdates-3d9a03ff4f1e542339950be6a77cb4c59a46ab77.zip
Fix Muscle Memory (#581)
* Added old SkyBlock Menu. * Execution! * Add cache. * Bingo has already enough to do. * Typo. * Revert "Typo." This reverts commit b4a1c385e0c410b1e111797b8d39e7ff64b09ef5. * Revert "Bingo has already enough to do." This reverts commit 6e004d2d65dff47ea3bee5c5789cb725724df6ed. * I am lazy. * The map is lazy too. * Hypixel moving features behind paywall. * Add red text to the setting too. * SEALED * Fixed Booster Cookie checks. Reworked CookieWarning, kept same logic but accidentally added profile switch support. * /trades does not require booster cookie. * Allowing middle clicks (and any other mouse click combination) --------- Co-authored-by: hannibal2 <24389977+hannibal00212@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.java211
1 files changed, 127 insertions, 84 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 80751371..f130a993 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java
@@ -31,9 +31,13 @@ public class CookieWarning {
private static boolean hasNotified;
private static boolean hasErrorMessage;
+ private static long cookieEndTime = 0;
+ private static boolean hasCookie = true;
+ private static long lastChecked = 0;
public static void resetNotification() {
hasNotified = false;
+ hasCookie = true;
NotificationHandler.cancelNotification();
}
@@ -41,96 +45,135 @@ public class CookieWarning {
* Checks the tab list for a cookie timer, and sends a notification if the timer is within the tolerance
*/
public static void checkCookie() {
- if (NotEnoughUpdates.INSTANCE.config.notifications.doBoosterNotif &&
- NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) {
- String[] lines;
- try {
- lines = ((AccessorGuiPlayerTabOverlay) Minecraft.getMinecraft().ingameGUI.getTabList())
- .getFooter()
- .getUnformattedText()
- .split("\n");
- } catch (NullPointerException e) {
- return; // if the footer is null or somehow doesn't exist, stop
+ if (!NotEnoughUpdates.INSTANCE.config.notifications.doBoosterNotif ||
+ !NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) {
+ return;
+ }
+ String timeLine = getTimeLine();
+ if (!hasCookie) {
+ if (!hasNotified) {
+ NotificationHandler.displayNotification(Lists.newArrayList(
+ "§cBooster Cookie Ran Out!",
+ "§7Your Booster Cookie expired!",
+ "§7",
+ "§7Press X on your keyboard to close this notification"
+ ), true, true);
+ hasNotified = true;
}
- boolean hasCookie = true;
- 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
- }
- if (lines[i].startsWith("Not active! Obtain booster cookies from the")) {
- hasCookie = false;
- }
+ return;
+ }
+ if (timeLine == null) return;
+
+ int minutes = getMinutesRemaining(timeLine);
+ if (minutes < NotEnoughUpdates.INSTANCE.config.notifications.boosterCookieWarningMins && !hasNotified) {
+ NotificationHandler.displayNotification(Lists.newArrayList(
+ "§cBooster Cookie Running Low!",
+ "§7Your Booster Cookie will expire in " + timeLine,
+ "§7",
+ "§7Press X on your keyboard to close this notification"
+ ), true, true);
+ hasNotified = true;
+ }
+ }
+
+ private static int getMinutesRemaining(String timeLine) {
+ String clean = timeLine.replaceAll("(§.)", "");
+ clean = clean.replaceAll("(\\d)([smhdy])", "$1 $2");
+ String[] digits = clean.split(" ");
+ int minutes = 0;
+ try {
+ 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
}
- if (!hasCookie) {
- if (!hasNotified) {
- NotificationHandler.displayNotification(Lists.newArrayList(
- "\u00a7cBooster Cookie Ran Out!",
- "\u00a77Your Booster Cookie expired!",
- "\u00a77",
- "\u00a77Press X on your keyboard to close this notification"
- ), true, true);
- hasNotified = true;
- }
- return;
+ } catch (NumberFormatException e) {
+ if (!hasErrorMessage) {
+ e.printStackTrace();
+ Utils.addChatMessage(EnumChatFormatting.RED +
+ "NEU ran into an issue when retrieving the Booster Cookie Timer. Check the logs for details.");
+ hasErrorMessage = true;
}
- if (timeLine != null) {
- String clean = timeLine.replaceAll("(\u00a7.)", "");
- clean = clean.replaceAll("(\\d)([smhdy])", "$1 $2");
- String[] digits = clean.split(" ");
- int minutes = 0;
- try {
- for (int i = 0; i < digits.length; i++) {
- if (i % 2 == 1) continue;
+ hasNotified = true;
+ }
+ return minutes;
+ }
- 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) {
- if (!hasErrorMessage) {
- e.printStackTrace();
- Utils.addChatMessage(EnumChatFormatting.RED +
- "NEU ran into an issue when retrieving the Booster Cookie Timer. Check the logs for details.");
- hasErrorMessage = true;
- }
- hasNotified = true;
- }
- if (minutes < NotEnoughUpdates.INSTANCE.config.notifications.boosterCookieWarningMins && !hasNotified) {
- NotificationHandler.displayNotification(Lists.newArrayList(
- "\u00a7cBooster Cookie Running Low!",
- "\u00a77Your Booster Cookie will expire in " + timeLine,
- "\u00a77",
- "\u00a77Press X on your keyboard to close this notification"
- ), true, true);
- hasNotified = true;
- }
+ private static String getTimeLine() {
+ String[] lines;
+ try {
+ lines = ((AccessorGuiPlayerTabOverlay) Minecraft.getMinecraft().ingameGUI.getTabList())
+ .getFooter()
+ .getUnformattedText()
+ .split("\n");
+ } catch (NullPointerException ignored) {
+ return null;
+ }
+ 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
+ }
+ if (lines[i].startsWith("Not active! Obtain booster cookies from the")) {
+ hasCookie = false;
}
}
+ return timeLine;
+ }
+
+ public static boolean hasActiveBoosterCookie() {
+ long cookieEndTime = getCookieEndTime();
+ return cookieEndTime > System.currentTimeMillis();
+ }
+
+ private static long getCookieEndTime() {
+ // Only updating every 10 seconds
+// if (System.currentTimeMillis() > lastChecked + 10_000) return cookieEndTime;
+ if (lastChecked + 3_000 > System.currentTimeMillis()) return cookieEndTime;
+
+ String timeLine = getTimeLine();
+ if (hasCookie && timeLine != null) {
+ int minutes = getMinutesRemaining(timeLine);
+ cookieEndTime = System.currentTimeMillis() + (long) minutes * 60 * 1000;
+ } else {
+ cookieEndTime = 0;
+ }
+
+ lastChecked = System.currentTimeMillis();
+ return cookieEndTime;
+ }
+ public static void onProfileSwitch() {
+ resetNotification();
+ hasErrorMessage = false;
+ cookieEndTime = 0;
+ hasCookie = true;
+ lastChecked = 0;
}
}