Minor fix to netmsg

This commit is contained in:
Chipmunk 2023-01-23 21:08:27 -05:00
parent 888f16782e
commit ec0d1c8a93

View file

@ -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);
}