Skip to content

Commit

Permalink
Merge pull request #161 from nea89o/fix/alert-regex-npe
Browse files Browse the repository at this point in the history
Fix NPE in alert patterns
  • Loading branch information
bowser0000 authored Feb 24, 2024
2 parents 0870ef4 + d35d303 commit ddd7196
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/me/Danker/features/Alerts.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public void init(ModInitEvent event) {
configFile = event.configDirectory + "/dsm/dsmalerts.json";
}

public Pattern getRegexForAlert(Alert alert) {
return patterns.computeIfAbsent(alert, it -> Pattern.compile(it.message));
}

@SubscribeEvent
public void onChat(ClientChatReceivedEvent event) {
if (!ModConfig.alerts || event.type == 2) return;
Expand All @@ -52,7 +56,7 @@ public void onChat(ClientChatReceivedEvent event) {
if (!location) continue;

if (alert.mode.equals("Regex")) {
Matcher matcher = patterns.get(alert).matcher(message);
Matcher matcher = getRegexForAlert(alert).matcher(message);
if (matcher.matches()) {
matcher.reset();
String alertText = alert.alert;
Expand Down

0 comments on commit ddd7196

Please sign in to comment.