aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md14
-rw-r--r--src/main/java/me/Danker/features/Alerts.java83
-rw-r--r--src/main/java/me/Danker/features/GpartyNotifications.java13
-rw-r--r--src/main/java/me/Danker/gui/alerts/AlertActionGui.java4
-rw-r--r--src/main/java/me/Danker/gui/alerts/AlertAddGui.java15
-rw-r--r--src/main/java/me/Danker/utils/Utils.java17
6 files changed, 96 insertions, 50 deletions
diff --git a/README.md b/README.md
index 30fec71..55fb29f 100644
--- a/README.md
+++ b/README.md
@@ -134,6 +134,20 @@ By adding numbers to the end of the file, you can have multiple music files for
- dungeon2.wav
- dungeon99.wav
+## Alert Regex
+To replace alert text with a captured group, add `$$x$$` to the alert text, with `x` being the number of the capture group. `$$0$$` will always be replaced with the entire trigger message.
+
+For example, with the following alert
+
+Regex: `From (.*) (.*): (.*)`
+Alert Text: `$$2$$ says $$3$$`
+Trigger Message: `From [ADMIN] Plancke: Nice autogg`
+
+the following alert text would appear
+
+`Plancke says Nice autogg`.
+
+
### Notes
- Slayer tracker for token drops and 20% chance drops uses a 12x12x12 bounding box centered on the player to detect the drops. If you are out of the range of the item drop, it will not count on the tracker.
- API commands may take a while depending on your internet connection. The API may also go down.
diff --git a/src/main/java/me/Danker/features/Alerts.java b/src/main/java/me/Danker/features/Alerts.java
index aab99b3..8f45423 100644
--- a/src/main/java/me/Danker/features/Alerts.java
+++ b/src/main/java/me/Danker/features/Alerts.java
@@ -1,6 +1,7 @@
package me.Danker.features;
import com.google.gson.GsonBuilder;
+import javafx.scene.control.Alert;
import me.Danker.commands.ToggleCommand;
import me.Danker.utils.Utils;
import net.minecraft.util.EnumChatFormatting;
@@ -12,11 +13,15 @@ import java.awt.*;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class Alerts {
public static List<Alert> alerts = new ArrayList<>();
+ public static HashMap<Alert, Pattern> patterns = new HashMap<>();
public static String configFile;
@SubscribeEvent
@@ -41,45 +46,59 @@ public class Alerts {
}
if (!location) continue;
- boolean trigger;
- switch (alert.mode) {
- case "Starts With":
- trigger = message.startsWith(alert.message);
- break;
- case "Contains":
- trigger = message.contains(alert.message);
- break;
- case "Ends With":
- trigger = message.endsWith(alert.message);
- break;
- default:
- continue;
- }
-
- 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();
+ if (alert.mode.equals("Regex")) {
+ Matcher matcher = patterns.get(alert).matcher(message);
+ if (matcher.matches()) {
+ matcher.reset();
+ String alertText = alert.alert;
+
+ int i = 0;
+ while (matcher.find()) {
+ for (int j = 0; j <= matcher.groupCount(); j++) {
+ alertText = alertText.replace("$$" + i + "$$", matcher.group(j));
+ i++;
+ }
}
+
+ Utils.createTitle(EnumChatFormatting.RED + alertText.replace("&", "§"), 2);
+ if (alert.desktop) Utils.desktopNotification("Alert", alertText, message, TrayIcon.MessageType.INFO);
+
+ return;
}
+ } else {
+ boolean trigger;
+ switch (alert.mode) {
+ case "Starts With":
+ trigger = message.startsWith(alert.message);
+ break;
+ case "Contains":
+ trigger = message.contains(alert.message);
+ break;
+ case "Ends With":
+ trigger = message.endsWith(alert.message);
+ break;
+ default:
+ continue;
+ }
+
+ if (trigger) {
+ Utils.createTitle(EnumChatFormatting.RED + alert.alert.replace("&", "§"), 2);
+ if (alert.desktop) Utils.desktopNotification("Alert", alert.alert, message, TrayIcon.MessageType.INFO);
- return;
+ return;
+ }
}
}
}
- public static void saveToFile() {
+ public static void save() {
+ for (Alert alert : alerts) {
+ if (alert.mode.equals("Regex")) {
+ Pattern pattern = Pattern.compile(alert.message);
+ patterns.put(alert, pattern);
+ }
+ }
+
try (FileWriter writer = new FileWriter(configFile)) {
new GsonBuilder().create().toJson(alerts, writer);
writer.flush();
diff --git a/src/main/java/me/Danker/features/GpartyNotifications.java b/src/main/java/me/Danker/features/GpartyNotifications.java
index f3aec69..76c0a66 100644
--- a/src/main/java/me/Danker/features/GpartyNotifications.java
+++ b/src/main/java/me/Danker/features/GpartyNotifications.java
@@ -19,18 +19,7 @@ public class GpartyNotifications {
if (ToggleCommand.gpartyToggled) {
if (message.contains(" has invited all members of ")) {
- try {
- final SystemTray tray = SystemTray.getSystemTray();
- final Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
- final TrayIcon trayIcon = new TrayIcon(image, "Guild Party Notifier");
- trayIcon.setImageAutoSize(true);
- trayIcon.setToolTip("Guild Party Notifier");
- tray.add(trayIcon);
- trayIcon.displayMessage("Guild Party", message, TrayIcon.MessageType.INFO);
- tray.remove(trayIcon);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
+ Utils.desktopNotification("Guild Party Notifier", "Guild Party", message, TrayIcon.MessageType.INFO);
}
}
}
diff --git a/src/main/java/me/Danker/gui/alerts/AlertActionGui.java b/src/main/java/me/Danker/gui/alerts/AlertActionGui.java
index 7a73f5a..3d0eb90 100644
--- a/src/main/java/me/Danker/gui/alerts/AlertActionGui.java
+++ b/src/main/java/me/Danker/gui/alerts/AlertActionGui.java
@@ -80,12 +80,12 @@ public class AlertActionGui extends GuiScreen {
mc.displayGuiScreen(new AlertAddGui(alert, id));
} else if (button == delete) {
Alerts.alerts.remove(id);
- Alerts.saveToFile();
+ Alerts.save();
mc.displayGuiScreen(new AlertsGui(1));
return;
}
Alerts.alerts.set(id, alert);
- Alerts.saveToFile();
+ Alerts.save();
}
}
diff --git a/src/main/java/me/Danker/gui/alerts/AlertAddGui.java b/src/main/java/me/Danker/gui/alerts/AlertAddGui.java
index 5f01d6d..304c77a 100644
--- a/src/main/java/me/Danker/gui/alerts/AlertAddGui.java
+++ b/src/main/java/me/Danker/gui/alerts/AlertAddGui.java
@@ -25,6 +25,7 @@ public class AlertAddGui extends GuiScreen {
private GuiButton startsWith;
private GuiButton contains;
private GuiButton endsWith;
+ private GuiButton regex;
private GuiButton everywhere;
private GuiButton skyblock;
private GuiButton dungeons;
@@ -57,9 +58,10 @@ public class AlertAddGui extends GuiScreen {
cancel = new GuiButton(0, 2, height - 30, 100, 20, "Cancel");
- 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");
+ startsWith = new GuiButton(0, width / 2 - 260, (int) (height * 0.2), 120, 20, "Starts With");
+ contains = new GuiButton(0, width / 2 - 130, (int) (height * 0.2), 120, 20, "Contains");
+ endsWith = new GuiButton(0, width / 2 + 10, (int) (height * 0.2), 120, 20, "Ends With");
+ regex = new GuiButton(0, width / 2 + 140, (int) (height * 0.2), 120, 20, "Regex");
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");
@@ -80,13 +82,16 @@ public class AlertAddGui extends GuiScreen {
message.setVisible(true);
message.setEnabled(true);
+ message.setMaxStringLength(100);
alert.setVisible(true);
alert.setEnabled(true);
+ alert.setMaxStringLength(100);
this.buttonList.add(cancel);
this.buttonList.add(startsWith);
this.buttonList.add(contains);
this.buttonList.add(endsWith);
+ this.buttonList.add(regex);
this.buttonList.add(everywhere);
this.buttonList.add(skyblock);
this.buttonList.add(dungeons);
@@ -119,6 +124,8 @@ public class AlertAddGui extends GuiScreen {
mode = "Contains";
} else if (button == endsWith) {
mode = "Ends With";
+ } else if (button == regex) {
+ mode = "Regex";
} else if (button == everywhere) {
location = "Everywhere";
} else if (button == skyblock) {
@@ -132,7 +139,7 @@ public class AlertAddGui extends GuiScreen {
} else {
Alerts.alerts.add(newAlert);
}
- Alerts.saveToFile();
+ Alerts.save();
mc.displayGuiScreen(new AlertsGui(1));
}
}
diff --git a/src/main/java/me/Danker/utils/Utils.java b/src/main/java/me/Danker/utils/Utils.java
index 2229d65..3cef436 100644
--- a/src/main/java/me/Danker/utils/Utils.java
+++ b/src/main/java/me/Danker/utils/Utils.java
@@ -19,7 +19,9 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.util.*;
+import java.awt.*;
import java.util.*;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -492,6 +494,21 @@ public class Utils {
return (Math.floor(level / 2D) + 25) / 100D;
}
+ public static void desktopNotification(String name, String title, String text, TrayIcon.MessageType messageType) {
+ try {
+ final SystemTray tray = SystemTray.getSystemTray();
+ final Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
+ final TrayIcon trayIcon = new TrayIcon(image, name);
+ trayIcon.setImageAutoSize(true);
+ trayIcon.setToolTip(name);
+ tray.add(trayIcon);
+ trayIcon.displayMessage(title, text, messageType);
+ tray.remove(trayIcon);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
public enum DungeonFloor {
NONE,
E0,