From e8a5b0151ed51905923aa94ae89ffbb55f9458e5 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 29 Jun 2025 08:50:41 +0700 Subject: [PATCH] refactor: make netmsg still tellraw when not logged in on target server + refactor the command --- build-number.txt | 2 +- .../commands/NetMessageCommand.java | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/build-number.txt b/build-number.txt index ac2d85f2..6cf40af6 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -3478 \ No newline at end of file +3479 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/NetMessageCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/NetMessageCommand.java index d5273d0c..5c4b5989 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/NetMessageCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/NetMessageCommand.java @@ -9,6 +9,7 @@ import me.chayapak1.chomens_bot.data.chat.ChatPacketType; import me.chayapak1.chomens_bot.util.ChatMessageUtilities; import me.chayapak1.chomens_bot.util.I18nUtilities; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; @@ -23,7 +24,7 @@ public class NetMessageCommand extends Command { new String[] { "networkmessage", "irc" }, TrustLevel.PUBLIC, false, - new ChatPacketType[]{ ChatPacketType.SYSTEM, ChatPacketType.DISGUISED } + new ChatPacketType[] { ChatPacketType.SYSTEM, ChatPacketType.DISGUISED } ); } @@ -35,11 +36,11 @@ public class NetMessageCommand extends Command { final String originServerName = bot.getServerString(); final String originServerAddress = bot.getServerString(false); - Component serverNameComponent = Component - .text(originServerName) + final TextComponent.Builder serverNameComponent = Component.text() + .content(originServerName) .color(NamedTextColor.GRAY); - if (!bot.options.hidden) serverNameComponent = serverNameComponent + if (!bot.options.hidden) serverNameComponent .clickEvent(ClickEvent.copyToClipboard(originServerAddress)) .hoverEvent( HoverEvent.showText( @@ -55,13 +56,12 @@ public class NetMessageCommand extends Command { final Component stylizedMessage = ChatMessageUtilities.applyChatMessageStyling(rawMessage); final Component component = Component.translatable( - "[%s]%s%s%s› %s", - NamedTextColor.DARK_GRAY, + "[%s]%s%s%s› %s", NamedTextColor.DARK_GRAY, serverNameComponent, Component.space(), context.sender.displayName == null ? Component.text(context.sender.profile.getName(), NamedTextColor.GRAY) : - context.sender.displayName.color(NamedTextColor.GRAY), + context.sender.displayName.colorIfAbsent(NamedTextColor.GRAY), Component.space(), Component.empty() .append(stylizedMessage) @@ -77,10 +77,7 @@ public class NetMessageCommand extends Command { ) ); - for (final Bot eachBot : bots) { - if (!eachBot.loggedIn) continue; - eachBot.chat.tellraw(I18nUtilities.render(component)); - } + for (final Bot eachBot : bots) eachBot.chat.tellraw(I18nUtilities.render(component)); return null; }