Fix bypass permission logic for ignored players in chat
Updated the filtering logic to correctly handle the "chat.ignorebypass" permission, ensuring players with bypass permission are not excluded due to ignore settings. Adjusted related conditionals in ChatHandler and ChatListener, and refactored patterns without altering functionality.
This commit is contained in:
parent
cb0bda8d5b
commit
769859a617
|
|
@ -261,7 +261,8 @@ public class ChatHandler {
|
|||
Stream<? extends Player> stream = Bukkit.getServer().getOnlinePlayers().stream()
|
||||
.filter(p -> p.hasPermission(chatChannel.getPermission()));
|
||||
if (!player.hasPermission("chat.ignorebypass")) {
|
||||
stream = stream.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid) && !p.hasPermission("chat.ignorebypass"));
|
||||
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
|
||||
|| receiver.hasPermission("chat.ignorebypass"));
|
||||
}
|
||||
stream.forEach(p -> p.sendMessage(component));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ public class ChatListener implements Listener {
|
|||
|
||||
if (!player.hasPermission("chat.ignorebypass")) {
|
||||
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
|
||||
&& !receiver.hasPermission("chat.ignorebypass"));
|
||||
|| receiver.hasPermission("chat.ignorebypass"));
|
||||
}
|
||||
Set<Player> receivers = stream.collect(Collectors.toSet());
|
||||
|
||||
|
|
@ -140,9 +140,9 @@ public class ChatListener implements Listener {
|
|||
String nickName = PlainTextComponentSerializer.plainText().serialize(onlinePlayer.displayName());
|
||||
|
||||
Pattern namePattern = Pattern.compile("\\b(?<!\\\\)" + name + "\\b", Pattern.CASE_INSENSITIVE);
|
||||
// Pattern escapedNamePattern = Pattern.compile("\\b\\\\" + name + "\\b", Pattern.CASE_INSENSITIVE);
|
||||
// Pattern escapedNamePattern = Pattern.compile("\\b\\\\" + name + "\\b", Pattern.CASE_INSENSITIVE);
|
||||
Pattern nickPattern = Pattern.compile("\\b(?<!\\\\)" + nickName + "\\b", Pattern.CASE_INSENSITIVE);
|
||||
// Pattern escapedNickPattern = Pattern.compile("\\b\\\\" + nickName + "\\b", Pattern.CASE_INSENSITIVE);
|
||||
// Pattern escapedNickPattern = Pattern.compile("\\b\\\\" + nickName + "\\b", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
ChatUser onlinePlayerUser = ChatUserManager.getChatUser(onlinePlayer.getUniqueId());
|
||||
if (namePattern.matcher(modifiableString.string()).find()) {
|
||||
|
|
@ -152,16 +152,18 @@ public class ChatListener implements Listener {
|
|||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
//TODO replace all instances of \name with just name but using the match result so the capitalization doesn't change
|
||||
// modifiableString.replace(TextReplacementConfig.builder()
|
||||
// .once()
|
||||
// .match(escapedNamePattern)
|
||||
// .replacement((a, b) -> {
|
||||
// String substring = a.group().substring(1);
|
||||
// return ;
|
||||
// });
|
||||
// modifiableString.replace(TextReplacementConfig.builder()
|
||||
// .once()
|
||||
// .match(escapedNamePattern)
|
||||
// .replacement((a, b) -> {
|
||||
// String substring = a.group().substring(1);
|
||||
// return ;
|
||||
// });
|
||||
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||
&& !player.hasPermission("chat.ignorebypass"))
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
playersToPing.add(onlinePlayer);
|
||||
}
|
||||
} else if (nickPattern.matcher(modifiableString.string()).find()) {
|
||||
modifiableString.replace(TextReplacementConfig.builder()
|
||||
.once()
|
||||
|
|
@ -169,8 +171,9 @@ public class ChatListener implements Listener {
|
|||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||
&& !player.hasPermission("chat.ignorebypass"))
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
playersToPing.add(onlinePlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user