aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures
diff options
context:
space:
mode:
author2stinkysocks <54291521+2stinkysocks@users.noreply.github.com>2022-05-07 07:29:16 -0700
committerGitHub <noreply@github.com>2022-05-07 16:29:16 +0200
commit470db06d91e1d90466e5fa1064eae4bb7318c5ad (patch)
tree92c7cc21ae8d80adc060047582d9d4842c29f6bb /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures
parent7e3b1ede9fac5964cba900f889594af5ba235393 (diff)
downloadnotenoughupdates-470db06d91e1d90466e5fa1064eae4bb7318c5ad.tar.gz
notenoughupdates-470db06d91e1d90466e5fa1064eae4bb7318c5ad.tar.bz2
notenoughupdates-470db06d91e1d90466e5fa1064eae4bb7318c5ad.zip
Booster Cookie Warning (#128)
* add booster cookie warning * requested changes * i forgot to check if the feature is enabled
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java95
1 files changed, 95 insertions, 0 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
new file mode 100644
index 00000000..41c2219a
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java
@@ -0,0 +1,95 @@
+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.util.NotificationHandler;
+import net.minecraft.client.Minecraft;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraftforge.event.entity.EntityJoinWorldEvent;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+
+public class CookieWarning {
+
+ private static boolean hasNotified;
+
+ public CookieWarning() {
+ hasNotified = false;
+ }
+
+ @SubscribeEvent
+ public void onJoinWorld(EntityJoinWorldEvent e) {
+ if(e.entity == Minecraft.getMinecraft().thePlayer) {
+ this.checkCookie();
+ }
+ }
+
+ public static void resetNotification() {
+ hasNotified = false;
+ }
+
+ /**
+ * Checks the tab list for a cookie timer, and sends a chat message if the timer is within the tolerance
+ */
+ private void checkCookie() {
+ if(!hasNotified && NotEnoughUpdates.INSTANCE.config.notifications.doBoosterNotif) {
+ String[] lines = ((AccessorGuiPlayerTabOverlay) Minecraft.getMinecraft().ingameGUI.getTabList()).getFooter().getUnformattedText().split("\n");
+ 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;
+ }
+ }
+ if(!hasCookie) {
+ 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;
+ }
+ if(timeLine != null) {
+ String[] digits = timeLine.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);
+ } // ignore seconds
+ }
+ } catch (NumberFormatException e) {
+ e.printStackTrace();
+ Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(
+ EnumChatFormatting.RED +
+ "NEU ran into an issue when retrieving the Booster Cookie Timer. Check the logs for details."));
+ }
+ if(minutes < NotEnoughUpdates.INSTANCE.config.notifications.boosterCookieWarningMins) {
+ 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;
+ }
+ }
+ }
+ }
+}