Question Cannot invoke "net.minecraft.server.network.ServerGamePacketListenerImpl.latency()" because "player.connection" is null

Zor1s

New member
Feb 16, 2022
2
0
1
I'm trying to port my 1.21 plugin to 1.21.3 and trying to port NPC spawning. Before, I used to spawn them with NMS like this:
Code:
connection.send(ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, npc))
connection.send(ClientboundAddPlayerPacket(npc))

But now I'm trying to do it with
Code:
connection.send(ClientboundPlayerInfoUpdatePacket.createSinglePlayerInitializing(npc, false))

and getting this error:
Code:
Caused by: java.lang.NullPointerException: Cannot invoke "net.minecraft.server.network.ServerGamePacketListenerImpl.latency()" because "player.connection" is null

it points at that line. connection's type is ServerGamePacketListenerImpl and npc's type is CraftPlayer