diff options
Diffstat (limited to 'src/main/java')
5 files changed, 133 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index d08968c3..0de3fffe 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -14,6 +14,7 @@ import io.github.moulberry.notenoughupdates.listener.ItemTooltipListener; import io.github.moulberry.notenoughupdates.listener.NEUEventListener; import io.github.moulberry.notenoughupdates.listener.OldAnimationChecker; import io.github.moulberry.notenoughupdates.listener.RenderListener; +import io.github.moulberry.notenoughupdates.miscfeatures.CookieWarning; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalWishingCompassSolver; import io.github.moulberry.notenoughupdates.miscfeatures.CustomItemEffects; @@ -241,6 +242,7 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(new ItemTooltipListener(this)); MinecraftForge.EVENT_BUS.register(new RenderListener(this)); MinecraftForge.EVENT_BUS.register(new OldAnimationChecker()); + MinecraftForge.EVENT_BUS.register(new CookieWarning()); MinecraftForge.EVENT_BUS.register(navigation); if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java index 060dcb80..6a5164a2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java @@ -2,6 +2,7 @@ package io.github.moulberry.notenoughupdates.listener; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.dungeons.DungeonWin; +import io.github.moulberry.notenoughupdates.miscfeatures.CookieWarning; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalMetalDetectorSolver; import io.github.moulberry.notenoughupdates.miscfeatures.StreamerMode; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; @@ -186,6 +187,8 @@ public class ChatListener { "Your Slayer Quest has been cancelled!"))) { SlayerOverlay.slayerQuest = false; SlayerOverlay.unloadOverlayTimer = System.currentTimeMillis(); + } else if (unformatted.startsWith("You consumed a Booster Cookie!")) { + CookieWarning.resetNotification(); } if (e.message.getFormattedText().contains( EnumChatFormatting.YELLOW + "Visit the Auction House to collect your item!")) { 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; + } + } + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/AccessorGuiPlayerTabOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/AccessorGuiPlayerTabOverlay.java new file mode 100644 index 00000000..530e3013 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/AccessorGuiPlayerTabOverlay.java @@ -0,0 +1,12 @@ +package io.github.moulberry.notenoughupdates.mixins; + +import net.minecraft.client.gui.GuiPlayerTabOverlay; +import net.minecraft.util.IChatComponent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(GuiPlayerTabOverlay.class) +public interface AccessorGuiPlayerTabOverlay { + @Accessor("footer") + IChatComponent getFooter(); +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Notifications.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Notifications.java index fd934330..9007db88 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Notifications.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Notifications.java @@ -2,6 +2,7 @@ package io.github.moulberry.notenoughupdates.options.seperateSections; import com.google.gson.annotations.Expose; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorSlider; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; public class Notifications { @@ -29,4 +30,24 @@ public class Notifications { ) @ConfigEditorBoolean public boolean doOamNotif = true; + + @Expose + @ConfigOption( + name = "Booster Cookie Warning", + desc = "Warning when a booster cookie is about to expire" + ) + @ConfigEditorBoolean + public boolean doBoosterNotif = false; + + @Expose + @ConfigOption( + name = "Booster Cookie Warning Minutes", + desc = "Change the minimum time required for the Booster Cookie warning to activate" + ) + @ConfigEditorSlider( + minValue = 10, + maxValue = 5760, + minStep = 25 + ) + public int boosterCookieWarningMins = 1440; } |