From ec0d1c8a93e8efc0e967db92430a0e942c75fbe3 Mon Sep 17 00:00:00 2001 From: Chip <65827213+ChipmunkMC@users.noreply.github.com> Date: Mon, 23 Jan 2023 21:08:27 -0500 Subject: [PATCH] Minor fix to `netmsg` --- .../chipmunk/chipmunkbot/commands/NetMsgCommand.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/land/chipmunk/chipmunkbot/commands/NetMsgCommand.java b/src/main/java/land/chipmunk/chipmunkbot/commands/NetMsgCommand.java index ee561cf..d004a41 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/commands/NetMsgCommand.java +++ b/src/main/java/land/chipmunk/chipmunkbot/commands/NetMsgCommand.java @@ -8,6 +8,10 @@ import static land.chipmunk.chipmunkbot.plugins.CommandManager.argument; import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; import static com.mojang.brigadier.arguments.StringArgumentType.getString; import com.mojang.brigadier.context.CommandContext; +import com.github.steveice10.packetlib.Session; +import com.github.steveice10.packetlib.packet.PacketProtocol; +import com.github.steveice10.mc.protocol.MinecraftProtocol; +import com.github.steveice10.mc.protocol.data.ProtocolState; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -38,6 +42,11 @@ public class NetMsgCommand extends Command { for (Client remote : source.client().allClients()) { if (!(remote instanceof ChipmunkBot)) continue; // ? Is this optimal? + + final Session session = remote.session(); + final PacketProtocol protocol = session.getPacketProtocol(); + if (!session.isConnected() || (protocol instanceof MinecraftProtocol && ((MinecraftProtocol) protocol).getState() != ProtocolState.GAME)) continue; + ((ChipmunkBot) remote).chat().tellraw(message); }