3939import com .velocitypowered .proxy .network .Connections ;
4040import com .velocitypowered .proxy .protocol .MinecraftPacket ;
4141import com .velocitypowered .proxy .protocol .ProtocolUtils ;
42+ import com .velocitypowered .proxy .protocol .StateRegistry ;
4243import com .velocitypowered .proxy .protocol .VelocityConnectionEvent ;
4344import com .velocitypowered .proxy .protocol .packet .AvailableCommands ;
4445import com .velocitypowered .proxy .protocol .packet .JoinGame ;
7071import java .util .concurrent .atomic .LongAdder ;
7172import java .util .concurrent .locks .ReadWriteLock ;
7273import java .util .concurrent .locks .ReentrantReadWriteLock ;
74+ import java .util .function .Supplier ;
7375import net .elytrium .commons .utils .reflection .ReflectionException ;
7476import net .elytrium .fastprepare .PreparedPacketFactory ;
7577import net .elytrium .limboapi .LimboAPI ;
8183import net .elytrium .limboapi .api .chunk .VirtualWorld ;
8284import net .elytrium .limboapi .api .command .LimboCommandMeta ;
8385import net .elytrium .limboapi .api .player .GameMode ;
86+ import net .elytrium .limboapi .api .protocol .PacketDirection ;
8487import net .elytrium .limboapi .api .protocol .PreparedPacket ;
88+ import net .elytrium .limboapi .api .protocol .packets .PacketMapping ;
8589import net .elytrium .limboapi .injection .packet .MinecraftLimitedCompressDecoder ;
8690import net .elytrium .limboapi .material .Biome ;
8791import net .elytrium .limboapi .protocol .LimboProtocol ;
@@ -143,6 +147,7 @@ public class LimboImpl implements Limbo {
143147 private PreparedPacket firstChunks ;
144148 private List <PreparedPacket > delayedChunks ;
145149 private PreparedPacket respawnPackets ;
150+ private StateRegistry localStateRegistry ;
146151 private boolean shouldRespawn = true ;
147152 private boolean shouldRejoin = true ;
148153 private boolean shouldUpdateTags = true ;
@@ -155,6 +160,7 @@ public class LimboImpl implements Limbo {
155160 public LimboImpl (LimboAPI plugin , VirtualWorld world ) {
156161 this .plugin = plugin ;
157162 this .world = world ;
163+ this .localStateRegistry = LimboProtocol .getLimboStateRegistry ();
158164
159165 this .refresh ();
160166 }
@@ -240,8 +246,8 @@ public void spawnPlayer(Player apiPlayer, LimboSessionHandler handler) {
240246
241247 boolean shouldSpawnPlayerImmediately = true ;
242248
243- if (connection .getState () != LimboProtocol . getLimboStateRegistry () ) {
244- connection .eventLoop ().execute (() -> connection .setState (LimboProtocol . getLimboStateRegistry () ));
249+ if (connection .getState () != this . localStateRegistry ) {
250+ connection .eventLoop ().execute (() -> connection .setState (this . localStateRegistry ));
245251 VelocityServerConnection server = player .getConnectedServer ();
246252 if (server != null ) {
247253 RegisteredServer previousServer = server .getServer ();
@@ -525,6 +531,17 @@ public Limbo registerCommand(CommandMeta commandMeta, Command command) {
525531 throw new IllegalArgumentException (command + " does not implement a registrable Command sub-interface." );
526532 }
527533
534+ public Limbo registerPacket (PacketDirection direction , Class <?> packetClass , Supplier <?> packetSupplier , PacketMapping [] packetMappings ) {
535+ if (this .localStateRegistry == LimboProtocol .getLimboStateRegistry ()) {
536+ this .localStateRegistry = LimboProtocol .createLocalStateRegistry ();
537+ this .plugin .getPreparedPacketFactory ().addStateRegistry (this .localStateRegistry );
538+ }
539+
540+ LimboProtocol .register (this .localStateRegistry , direction , packetClass , packetSupplier , packetMappings );
541+
542+ return this ;
543+ }
544+
528545 @ Override
529546 public void dispose () {
530547 if (this .getCurrentOnline () == 0 ) {
0 commit comments