diff --git a/bukkit/src/main/resources/config.yml b/bukkit/src/main/resources/config.yml index 84bd18bb6..c8468ee93 100644 --- a/bukkit/src/main/resources/config.yml +++ b/bukkit/src/main/resources/config.yml @@ -304,6 +304,12 @@ require-sender-group-membership-to-modify: false # '/lp log notify ' log-notify: true +# Defines a list of log entries which should not be sent as notifications to users. +# +# - Each entry in the list is a RegEx expression which is matched against the log entry description. +log-notify-filtered-descriptions: +# - "parent add example" + # Defines the options for prefix and suffix stacking. # # - The feature allows you to display multiple prefixes or suffixes alongside a players username in diff --git a/bungee/src/main/resources/config.yml b/bungee/src/main/resources/config.yml index 760aa01b9..e4c959602 100644 --- a/bungee/src/main/resources/config.yml +++ b/bungee/src/main/resources/config.yml @@ -312,6 +312,12 @@ require-sender-group-membership-to-modify: false # '/lp log notify ' log-notify: true +# Defines a list of log entries which should not be sent as notifications to users. +# +# - Each entry in the list is a RegEx expression which is matched against the log entry description. +log-notify-filtered-descriptions: +# - "parent add example" + # Defines the options for prefix and suffix stacking. # # - The feature allows you to display multiple prefixes or suffixes alongside a players username in diff --git a/common/src/main/java/me/lucko/luckperms/common/actionlog/LogDispatcher.java b/common/src/main/java/me/lucko/luckperms/common/actionlog/LogDispatcher.java index 6ad4e29ac..07a368d02 100644 --- a/common/src/main/java/me/lucko/luckperms/common/actionlog/LogDispatcher.java +++ b/common/src/main/java/me/lucko/luckperms/common/actionlog/LogDispatcher.java @@ -35,6 +35,9 @@ import me.lucko.luckperms.common.sender.Sender; import net.luckperms.api.event.log.LogBroadcastEvent; import net.luckperms.api.event.log.LogNotifyEvent; +import java.util.Collection; +import java.util.regex.Pattern; + public class LogDispatcher { private final LuckPermsPlugin plugin; @@ -42,6 +45,26 @@ public class LogDispatcher { this.plugin = plugin; } + private boolean shouldBroadcast(LoggedAction entry, LogBroadcastEvent.Origin origin) { + boolean cancelled = false; + + if (!this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY)) { + cancelled = true; + } else if (origin == LogBroadcastEvent.Origin.REMOTE && !this.plugin.getConfiguration().get(ConfigKeys.BROADCAST_RECEIVED_LOG_ENTRIES)) { + cancelled = true; + } else { + Collection filters = this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY_FILTERED_DESCRIPTIONS); + for (Pattern filter : filters) { + if (filter.matcher(entry.getDescription()).matches()) { + cancelled = true; + break; + } + } + } + + return !this.plugin.getEventDispatcher().dispatchLogBroadcast(cancelled, entry, origin); + } + private void broadcast(LoggedAction entry, LogNotifyEvent.Origin origin, Sender sender) { this.plugin.getOnlineSenders() .filter(CommandPermission.LOG_NOTIFY::isAuthorized) @@ -64,12 +87,19 @@ public class LogDispatcher { this.plugin.getMessagingService().ifPresent(service -> service.pushLog(entry)); - boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY); - if (!this.plugin.getEventDispatcher().dispatchLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL)) { + if (shouldBroadcast(entry, LogBroadcastEvent.Origin.LOCAL)) { broadcast(entry, LogNotifyEvent.Origin.LOCAL, sender); } } + public void broadcastFromApi(LoggedAction entry) { + this.plugin.getMessagingService().ifPresent(extendedMessagingService -> extendedMessagingService.pushLog(entry)); + + if (shouldBroadcast(entry, LogBroadcastEvent.Origin.LOCAL_API)) { + broadcast(entry, LogNotifyEvent.Origin.LOCAL_API, null); + } + } + public void dispatchFromApi(LoggedAction entry) { if (!this.plugin.getEventDispatcher().dispatchLogPublish(false, entry)) { try { @@ -82,18 +112,8 @@ public class LogDispatcher { broadcastFromApi(entry); } - public void broadcastFromApi(LoggedAction entry) { - this.plugin.getMessagingService().ifPresent(extendedMessagingService -> extendedMessagingService.pushLog(entry)); - - boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY); - if (!this.plugin.getEventDispatcher().dispatchLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.LOCAL_API)) { - broadcast(entry, LogNotifyEvent.Origin.LOCAL_API, null); - } - } - public void dispatchFromRemote(LoggedAction entry) { - boolean shouldCancel = !this.plugin.getConfiguration().get(ConfigKeys.BROADCAST_RECEIVED_LOG_ENTRIES) || !this.plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY); - if (!this.plugin.getEventDispatcher().dispatchLogBroadcast(shouldCancel, entry, LogBroadcastEvent.Origin.REMOTE)) { + if (shouldBroadcast(entry, LogBroadcastEvent.Origin.REMOTE)) { broadcast(entry, LogNotifyEvent.Origin.REMOTE, null); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java index de97b12bd..a2e1dc0c7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.config; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; @@ -62,6 +63,8 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.function.Function; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import static me.lucko.luckperms.common.config.generic.key.ConfigKeyFactory.booleanKey; import static me.lucko.luckperms.common.config.generic.key.ConfigKeyFactory.key; @@ -388,6 +391,23 @@ public final class ConfigKeys { */ public static final ConfigKey LOG_NOTIFY = booleanKey("log-notify", true); + /** + * Defines a list of log entries which should not be sent as notifications to users. + */ + public static final ConfigKey> LOG_NOTIFY_FILTERED_DESCRIPTIONS = key(c -> { + return c.getStringList("log-notify-filtered-descriptions", ImmutableList.of()).stream() + .map(entry -> { + try { + return Pattern.compile(entry, Pattern.CASE_INSENSITIVE); + } catch (PatternSyntaxException e) { + new IllegalArgumentException("Invalid pattern: " + entry, e).printStackTrace(); + return null; + } + }) + .filter(Objects::nonNull) + .collect(ImmutableCollectors.toList()); + }); + /** * If auto op is enabled. Only used by the Bukkit platform. */ diff --git a/nukkit/src/main/resources/config.yml b/nukkit/src/main/resources/config.yml index d6a7b126b..dd45a557b 100644 --- a/nukkit/src/main/resources/config.yml +++ b/nukkit/src/main/resources/config.yml @@ -299,6 +299,12 @@ require-sender-group-membership-to-modify: false # '/lp log notify ' log-notify: true +# Defines a list of log entries which should not be sent as notifications to users. +# +# - Each entry in the list is a RegEx expression which is matched against the log entry description. +log-notify-filtered-descriptions: +# - "parent add example" + # Defines the options for prefix and suffix stacking. # # - The feature allows you to display multiple prefixes or suffixes alongside a players username in diff --git a/sponge/src/main/resources/luckperms.conf b/sponge/src/main/resources/luckperms.conf index a2cab6399..797d05f17 100644 --- a/sponge/src/main/resources/luckperms.conf +++ b/sponge/src/main/resources/luckperms.conf @@ -308,6 +308,13 @@ require-sender-group-membership-to-modify = false # '/lp log notify ' log-notify = true +# Defines a list of log entries which should not be sent as notifications to users. +# +# - Each entry in the list is a RegEx expression which is matched against the log entry description. +log-notify-filtered-descriptions = [ +# "parent add example" +] + # Defines the options for prefix and suffix stacking. # # - The feature allows you to display multiple prefixes or suffixes alongside a players username in diff --git a/velocity/src/main/resources/config.yml b/velocity/src/main/resources/config.yml index 4289e400d..e8f618ee1 100644 --- a/velocity/src/main/resources/config.yml +++ b/velocity/src/main/resources/config.yml @@ -303,6 +303,12 @@ require-sender-group-membership-to-modify: false # '/lp log notify ' log-notify: true +# Defines a list of log entries which should not be sent as notifications to users. +# +# - Each entry in the list is a RegEx expression which is matched against the log entry description. +log-notify-filtered-descriptions: +# - "parent add example" + # Defines the options for prefix and suffix stacking. # # - The feature allows you to display multiple prefixes or suffixes alongside a players username in