diff options
author | bowser0000 <bowser0000@gmail.com> | 2022-04-16 20:22:32 -0400 |
---|---|---|
committer | bowser0000 <bowser0000@gmail.com> | 2022-04-16 20:22:32 -0400 |
commit | 7af45a9bee936d6da43e8b9ee6473a8ecbcb3d7f (patch) | |
tree | 557f30d16b028c550c7bbd9ee28e4892f161fe0a | |
parent | 1e2036e6ca3b10595ba27691ab4ee0a87d31f052 (diff) | |
download | SkyblockMod-7af45a9bee936d6da43e8b9ee6473a8ecbcb3d7f.tar.gz SkyblockMod-7af45a9bee936d6da43e8b9ee6473a8ecbcb3d7f.tar.bz2 SkyblockMod-7af45a9bee936d6da43e8b9ee6473a8ecbcb3d7f.zip |
Add location and desktop notification for alerts
Options of everywhere, in skyblock and in dungeons
-rw-r--r-- | src/main/java/me/Danker/features/Alerts.java | 42 | ||||
-rw-r--r-- | src/main/java/me/Danker/gui/alerts/AlertActionGui.java | 8 | ||||
-rw-r--r-- | src/main/java/me/Danker/gui/alerts/AlertAddGui.java | 45 |
3 files changed, 83 insertions, 12 deletions
diff --git a/src/main/java/me/Danker/features/Alerts.java b/src/main/java/me/Danker/features/Alerts.java index 2a00fef..aab99b3 100644 --- a/src/main/java/me/Danker/features/Alerts.java +++ b/src/main/java/me/Danker/features/Alerts.java @@ -8,6 +8,7 @@ import net.minecraft.util.StringUtils; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import java.awt.*; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; @@ -20,13 +21,26 @@ public class Alerts { @SubscribeEvent public void onChat(ClientChatReceivedEvent event) { - if (!ToggleCommand.alerts || !Utils.inSkyblock || event.type == 2) return; + if (!ToggleCommand.alerts || event.type == 2) return; String message = StringUtils.stripControlCodes(event.message.getUnformattedText()); for (Alert alert : alerts) { if (!alert.toggled) continue; + boolean location; + switch (alert.location) { + case "Skyblock": + location = Utils.inSkyblock; + break; + case "Dungeons": + location = Utils.inDungeons; + break; + default: + location = true; + } + if (!location) continue; + boolean trigger; switch (alert.mode) { case "Starts With": @@ -44,6 +58,22 @@ public class Alerts { if (trigger) { Utils.createTitle(EnumChatFormatting.RED + alert.alert.replace("&", "ยง"), 2); + + if (alert.desktop) { + try { + final SystemTray tray = SystemTray.getSystemTray(); + final Image image = Toolkit.getDefaultToolkit().createImage("icon.png"); + final TrayIcon trayIcon = new TrayIcon(image, "Alert"); + trayIcon.setImageAutoSize(true); + trayIcon.setToolTip("Alert"); + tray.add(trayIcon); + trayIcon.displayMessage(StringUtils.stripControlCodes(alert.alert), message, TrayIcon.MessageType.INFO); + tray.remove(trayIcon); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + return; } } @@ -61,14 +91,18 @@ public class Alerts { public static class Alert { public String mode; + public String location; public String message; public String alert; + public boolean desktop; public boolean toggled; - public Alert(String mode, String message, String alert, boolean toggled) { + public Alert(String mode, String location, String message, String alert, boolean desktop, boolean toggled) { this.mode = mode; + this.location = location; this.message = message; this.alert = alert; + this.desktop = desktop; this.toggled = toggled; } @@ -76,6 +110,10 @@ public class Alerts { toggled = !toggled; } + public void toggleDesktop() { + desktop = !desktop; + } + } } diff --git a/src/main/java/me/Danker/gui/alerts/AlertActionGui.java b/src/main/java/me/Danker/gui/alerts/AlertActionGui.java index 02ef186..7a73f5a 100644 --- a/src/main/java/me/Danker/gui/alerts/AlertActionGui.java +++ b/src/main/java/me/Danker/gui/alerts/AlertActionGui.java @@ -16,6 +16,7 @@ public class AlertActionGui extends GuiScreen { private GuiButton goBack; private GuiButton toggle; + private GuiButton toggleDesktop; private GuiButton edit; private GuiButton delete; @@ -40,10 +41,12 @@ public class AlertActionGui extends GuiScreen { goBack = new GuiButton(0, 2, height - 30, 100, 20, "Go Back"); toggle = new GuiButton(0, width / 2 - 100, (int) (height * 0.1), "Enabled: " + Utils.getColouredBoolean(alert.toggled)); - edit = new GuiButton(0, width / 2 - 100, (int) (height * 0.2), "Edit >"); + toggleDesktop = new GuiButton(0, width / 2 - 100, (int) (height * 0.2), "Desktop Notification: " + Utils.getColouredBoolean(alert.desktop)); + edit = new GuiButton(0, width / 2 - 100, (int) (height * 0.3), "Edit >"); delete = new GuiButton(0, width / 2 - 100, (int) (height * 0.8), EnumChatFormatting.RED + "Delete Alert"); this.buttonList.add(toggle); + this.buttonList.add(toggleDesktop); this.buttonList.add(edit); this.buttonList.add(delete); this.buttonList.add(goBack); @@ -70,6 +73,9 @@ public class AlertActionGui extends GuiScreen { } else if (button == toggle) { alert.toggle(); toggle.displayString = "Enabled: " + Utils.getColouredBoolean(alert.toggled); + } else if (button == toggleDesktop) { + alert.toggleDesktop(); + toggleDesktop.displayString = "Desktop Notification: " + Utils.getColouredBoolean(alert.desktop); } else if (button == edit) { mc.displayGuiScreen(new AlertAddGui(alert, id)); } else if (button == delete) { diff --git a/src/main/java/me/Danker/gui/alerts/AlertAddGui.java b/src/main/java/me/Danker/gui/alerts/AlertAddGui.java index efc099c..5f01d6d 100644 --- a/src/main/java/me/Danker/gui/alerts/AlertAddGui.java +++ b/src/main/java/me/Danker/gui/alerts/AlertAddGui.java @@ -2,6 +2,7 @@ package me.Danker.gui.alerts; import me.Danker.features.Alerts; import me.Danker.handlers.TextRenderer; +import me.Danker.utils.RenderUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; @@ -20,11 +21,16 @@ public class AlertAddGui extends GuiScreen { private GuiButton cancel; private String mode = "Contains"; + private String location = "Skyblock"; private GuiButton startsWith; private GuiButton contains; private GuiButton endsWith; + private GuiButton everywhere; + private GuiButton skyblock; + private GuiButton dungeons; private GuiTextField message; private GuiTextField alert; + private GuiCheckBox desktop; private GuiCheckBox toggled; private GuiButton add; @@ -54,15 +60,21 @@ public class AlertAddGui extends GuiScreen { startsWith = new GuiButton(0, width / 2 - 200, (int) (height * 0.2), 120, 20, "Starts With"); contains = new GuiButton(0, width / 2 - 60, (int) (height * 0.2), 120, 20, "Contains"); endsWith = new GuiButton(0, width / 2 + 80, (int) (height * 0.2), 120, 20, "Ends With"); - message = new GuiTextField(0, this.fontRendererObj, width / 2 - 100, (int) (height * 0.3), 200, 20); - alert = new GuiTextField(0, this.fontRendererObj, width / 2 - 100, (int) (height * 0.4), 200, 20); - toggled = new GuiCheckBox(0, width / 2 - 26, (int) (height * 0.5), "Toggled", true); - add = new GuiButton(0, width / 2 - 25, (int) (height * 0.7), 50, 20, "Add"); + everywhere = new GuiButton(0, width / 2 - 200, (int) (height * 0.3), 120, 20, "Everywhere"); + skyblock = new GuiButton(0, width / 2 - 60, (int) (height * 0.3), 120, 20, "Skyblock"); + dungeons = new GuiButton(0, width / 2 + 80, (int) (height * 0.3), 120, 20, "Dungeons"); + message = new GuiTextField(0, this.fontRendererObj, width / 2 - 100, (int) (height * 0.4), 200, 20); + alert = new GuiTextField(0, this.fontRendererObj, width / 2 - 100, (int) (height * 0.5), 200, 20); + desktop = new GuiCheckBox(0, width / 2 - 58, (int) (height * 0.6), "Desktop Notification", false); + toggled = new GuiCheckBox(0, width / 2 - 26, (int) (height * 0.65), "Toggled", true); + add = new GuiButton(0, width / 2 - 25, (int) (height * 0.8), 50, 20, "Add"); if (editing) { mode = base.mode; + location = base.location; message.setText(base.message); alert.setText(base.alert); + desktop.setIsChecked(base.desktop); toggled.setIsChecked(base.toggled); } @@ -75,6 +87,10 @@ public class AlertAddGui extends GuiScreen { this.buttonList.add(startsWith); this.buttonList.add(contains); this.buttonList.add(endsWith); + this.buttonList.add(everywhere); + this.buttonList.add(skyblock); + this.buttonList.add(dungeons); + this.buttonList.add(desktop); this.buttonList.add(toggled); this.buttonList.add(add); } @@ -87,9 +103,10 @@ public class AlertAddGui extends GuiScreen { message.drawTextBox(); alert.drawTextBox(); - new TextRenderer(mc, "Mode: " + mode, width / 2 - 35, (int) (height * 0.15), 1D); - new TextRenderer(mc, "Trigger:", width / 2 - 145, (int) (height * 0.32), 1D); - new TextRenderer(mc, "Alert Text:", width / 2 - 158, (int) (height * 0.42), 1D); + RenderUtils.drawCenteredText("Mode: " + mode, width, (int) (height * 0.1), 1D); + RenderUtils.drawCenteredText("Location: " + location, width, (int) (height * 0.15), 1D); + new TextRenderer(mc, "Trigger:", width / 2 - 145, (int) (height * 0.42), 1D); + new TextRenderer(mc, "Alert Text:", width / 2 - 158, (int) (height * 0.52), 1D); } @Override @@ -102,9 +119,19 @@ public class AlertAddGui extends GuiScreen { mode = "Contains"; } else if (button == endsWith) { mode = "Ends With"; + } else if (button == everywhere) { + location = "Everywhere"; + } else if (button == skyblock) { + location = "Skyblock"; + } else if (button == dungeons) { + location = "Dungeons"; } else if (button == add) { - Alerts.alerts.add(new Alerts.Alert(mode, message.getText(), alert.getText(), toggled.isChecked())); - if (editing) Alerts.alerts.remove(id); + Alerts.Alert newAlert = new Alerts.Alert(mode, location, message.getText(), alert.getText(), desktop.isChecked(), toggled.isChecked()); + if (editing) { + Alerts.alerts.set(id, newAlert); + } else { + Alerts.alerts.add(newAlert); + } Alerts.saveToFile(); mc.displayGuiScreen(new AlertsGui(1)); } |