Refactor ChatListener to improve readability and formatting consistency across message handling and ignored players logic.
This commit is contained in:
parent
af6820d1bf
commit
92979e9789
|
|
@ -59,7 +59,10 @@ public class ChatListener implements Listener {
|
|||
plainTextComponentSerializer.serialize(event.originalMessage())
|
||||
);
|
||||
|
||||
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
||||
event.result(formatComponent.replaceText(TextReplacementConfig.builder()
|
||||
.match("%message%")
|
||||
.replacement(message)
|
||||
.build()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
|
|
@ -73,7 +76,10 @@ public class ChatListener implements Listener {
|
|||
plainTextComponentSerializer.serialize(event.originalMessage())
|
||||
);
|
||||
|
||||
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
||||
event.result(formatComponent.replaceText(TextReplacementConfig.builder()
|
||||
.match("%message%")
|
||||
.replacement(message)
|
||||
.build()));
|
||||
}
|
||||
|
||||
private final Component mention = MiniMessage.miniMessage().deserialize(Config.MENTIONPLAYERTAG);
|
||||
|
|
@ -120,7 +126,12 @@ public class ChatListener implements Listener {
|
|||
""
|
||||
);
|
||||
String originalMessage = PlainTextComponentSerializer.plainText().serialize(inputComponent);
|
||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), originalMessage, inputComponent, true);
|
||||
chatLogHandler.addChatLog(uuid,
|
||||
ServerName.getServerName(),
|
||||
originalMessage,
|
||||
render(player, inputComponent).asComponent(),
|
||||
true
|
||||
);
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
|
|
@ -128,9 +139,13 @@ public class ChatListener implements Listener {
|
|||
.map(audience -> (Player) audience);
|
||||
|
||||
if (!player.hasPermission("chat.ignorebypass")) {
|
||||
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(
|
||||
uuid)
|
||||
|| receiver.hasPermission("chat.ignorebypass"));
|
||||
stream = stream.filter(receiver -> {
|
||||
boolean isPlayerIgnored = ChatUserManager
|
||||
.getChatUser(receiver.getUniqueId())
|
||||
.getIgnoredPlayers()
|
||||
.contains(uuid);
|
||||
return !isPlayerIgnored || receiver.hasPermission("chat.ignorebypass");
|
||||
});
|
||||
}
|
||||
Set<Player> receivers = stream.collect(Collectors.toSet());
|
||||
|
||||
|
|
@ -147,7 +162,7 @@ public class ChatListener implements Listener {
|
|||
chatLogHandler.addChatLog(uuid,
|
||||
ServerName.getServerName(),
|
||||
modifiableString.string(),
|
||||
modifiableString.component(),
|
||||
input.asComponent(),
|
||||
false
|
||||
);
|
||||
ALogger.info(PlainTextComponentSerializer.plainText().serialize(inputComponent));
|
||||
|
|
@ -179,7 +194,9 @@ public class ChatListener implements Listener {
|
|||
// return ;
|
||||
// });
|
||||
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId())
|
||||
.getIgnoredPlayers()
|
||||
.contains(player.getUniqueId())
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
playersToPing.add(onlinePlayer);
|
||||
}
|
||||
|
|
@ -189,7 +206,9 @@ public class ChatListener implements Listener {
|
|||
.match(nickPattern)
|
||||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId())
|
||||
.getIgnoredPlayers()
|
||||
.contains(player.getUniqueId())
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
playersToPing.add(onlinePlayer);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user