Refactor ChatListener to improve readability and formatting consistency across message handling and ignored players logic.

This commit is contained in:
akastijn 2026-07-19 01:03:07 +02:00
parent af6820d1bf
commit 92979e9789

View File

@ -59,7 +59,10 @@ public class ChatListener implements Listener {
plainTextComponentSerializer.serialize(event.originalMessage()) 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) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@ -73,7 +76,10 @@ public class ChatListener implements Listener {
plainTextComponentSerializer.serialize(event.originalMessage()) 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); private final Component mention = MiniMessage.miniMessage().deserialize(Config.MENTIONPLAYERTAG);
@ -120,7 +126,12 @@ public class ChatListener implements Listener {
"" ""
); );
String originalMessage = PlainTextComponentSerializer.plainText().serialize(inputComponent); 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 return; // the message was blocked
} }
@ -128,9 +139,13 @@ public class ChatListener implements Listener {
.map(audience -> (Player) audience); .map(audience -> (Player) audience);
if (!player.hasPermission("chat.ignorebypass")) { if (!player.hasPermission("chat.ignorebypass")) {
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains( stream = stream.filter(receiver -> {
uuid) boolean isPlayerIgnored = ChatUserManager
|| receiver.hasPermission("chat.ignorebypass")); .getChatUser(receiver.getUniqueId())
.getIgnoredPlayers()
.contains(uuid);
return !isPlayerIgnored || receiver.hasPermission("chat.ignorebypass");
});
} }
Set<Player> receivers = stream.collect(Collectors.toSet()); Set<Player> receivers = stream.collect(Collectors.toSet());
@ -147,7 +162,7 @@ public class ChatListener implements Listener {
chatLogHandler.addChatLog(uuid, chatLogHandler.addChatLog(uuid,
ServerName.getServerName(), ServerName.getServerName(),
modifiableString.string(), modifiableString.string(),
modifiableString.component(), input.asComponent(),
false false
); );
ALogger.info(PlainTextComponentSerializer.plainText().serialize(inputComponent)); ALogger.info(PlainTextComponentSerializer.plainText().serialize(inputComponent));
@ -179,7 +194,9 @@ public class ChatListener implements Listener {
// return ; // return ;
// }); // });
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId()) if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId())
.getIgnoredPlayers()
.contains(player.getUniqueId())
|| player.hasPermission("chat.ignorebypass")) { || player.hasPermission("chat.ignorebypass")) {
playersToPing.add(onlinePlayer); playersToPing.add(onlinePlayer);
} }
@ -189,7 +206,9 @@ public class ChatListener implements Listener {
.match(nickPattern) .match(nickPattern)
.replacement(mention.append(onlinePlayerUser.getDisplayName())) .replacement(mention.append(onlinePlayerUser.getDisplayName()))
.build()); .build());
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId()) if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId())
.getIgnoredPlayers()
.contains(player.getUniqueId())
|| player.hasPermission("chat.ignorebypass")) { || player.hasPermission("chat.ignorebypass")) {
playersToPing.add(onlinePlayer); playersToPing.add(onlinePlayer);
} }