From ef17bad9535052ca9815457d9a1b6cb093137d27 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 4 Jun 2023 07:33:11 +0700 Subject: [PATCH] nullpointer netmsg fix? --- .../commands/NetMessageCommand.java | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/NetMessageCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/NetMessageCommand.java index 77620cf4..5b7b2c0d 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/NetMessageCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/NetMessageCommand.java @@ -4,7 +4,6 @@ import land.chipmunk.chayapak.chomens_bot.Bot; import land.chipmunk.chayapak.chomens_bot.command.Command; import land.chipmunk.chayapak.chomens_bot.command.CommandContext; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; @@ -39,35 +38,37 @@ public class NetMessageCommand implements Command { } public Component execute(CommandContext context, String[] args, String[] fullArgs) { - final Bot bot = context.bot(); - final List bots = bot.bots(); + try { + final Bot bot = context.bot(); + final List bots = bot.bots(); - final String hostAndPort = bot.host() + ":" + bot.port(); + final String hostAndPort = bot.host() + ":" + bot.port(); - final Component component = Component.translatable( - "[%s]%s%s%s› %s", - Component - .text(hostAndPort) - .color(NamedTextColor.GRAY) - .clickEvent(ClickEvent.copyToClipboard(hostAndPort)) - .hoverEvent( - HoverEvent.showText( - Component.empty() - .append(Component.text(hostAndPort).color(NamedTextColor.GRAY)) - .append(Component.newline()) - .append(Component.text("Click here to copy the server host and port to your clipboard").color(NamedTextColor.GREEN)) - ) - ), - Component.text(" "), - context.sender().displayName().color(NamedTextColor.GRAY), - Component.text(" "), - Component.text(String.join(" ", args)).color(NamedTextColor.GRAY) - ).color(NamedTextColor.DARK_GRAY); + final Component component = Component.translatable( + "[%s]%s%s%s› %s", + Component + .text(hostAndPort) + .color(NamedTextColor.GRAY) + .clickEvent(ClickEvent.copyToClipboard(hostAndPort)) + .hoverEvent( + HoverEvent.showText( + Component.empty() + .append(Component.text(hostAndPort).color(NamedTextColor.GRAY)) + .append(Component.newline()) + .append(Component.text("Click here to copy the server host and port to your clipboard").color(NamedTextColor.GREEN)) + ) + ), + Component.text(" "), + context.sender().displayName().color(NamedTextColor.GRAY), + Component.text(" "), + Component.text(String.join(" ", args)).color(NamedTextColor.GRAY) + ).color(NamedTextColor.DARK_GRAY); - for (Bot eachBot : bots) { - if (!eachBot.loggedIn()) continue; - eachBot.chat().tellraw(component); - } + for (Bot eachBot : bots) { + if (!eachBot.loggedIn()) continue; + eachBot.chat().tellraw(component); + } + } catch (Exception ignored) {} // lazy fix for the bot spamming nullpointers in console (mabe) return null; }