diff --git a/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/impl/sync/server/DelayedPacketsHolder.java b/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/impl/sync/server/DelayedPacketsHolder.java index df1b9f3a9..84f4c1c15 100644 --- a/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/impl/sync/server/DelayedPacketsHolder.java +++ b/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/impl/sync/server/DelayedPacketsHolder.java @@ -26,5 +26,5 @@ @ApiStatus.Internal public interface DelayedPacketsHolder { void frozenLib$setPacketList(List packetList); - List> frozenLib$getPacketList(); + List frozenLib$getPacketList(); } diff --git a/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/mixin/PlayerListMixin.java b/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/mixin/PlayerListMixin.java new file mode 100644 index 000000000..33aed1984 --- /dev/null +++ b/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/mixin/PlayerListMixin.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 The Quilt Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.frozenblock.core.registry.mixin; + +import net.minecraft.network.Connection; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.players.PlayerList; +import org.quiltmc.qsl.frozenblock.core.registry.impl.sync.server.DelayedPacketsHolder; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(PlayerList.class) +public class PlayerListMixin { + + @Inject(method = "placeNewPlayer", at = @At("TAIL")) + private void sendSync(Connection netManager, ServerPlayer player, CallbackInfo ci) { + var delayedList = ((DelayedPacketsHolder) player).frozenLib$getPacketList(); + + if (delayedList != null) { + for (var packet : delayedList) { + packet.handle(player.connection); + } + } + + ((DelayedPacketsHolder) player).frozenLib$setPacketList(null); + } +} diff --git a/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/mixin/ServerLoginNetworkHandlerMixin.java b/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/mixin/ServerLoginNetworkHandlerMixin.java index 209dd1871..6f523267e 100644 --- a/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/mixin/ServerLoginNetworkHandlerMixin.java +++ b/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/mixin/ServerLoginNetworkHandlerMixin.java @@ -1,19 +1,17 @@ /* - * Copyright 2023 FrozenBlock - * This file is part of FrozenLib. + * Copyright 2022 The Quilt Project * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * http://www.apache.org/licenses/LICENSE-2.0 * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, see . + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.quiltmc.qsl.frozenblock.core.registry.mixin; @@ -37,19 +35,19 @@ public abstract class ServerLoginNetworkHandlerMixin { @Shadow @Final - public Connection connection; + Connection connection; @Shadow protected abstract void placeNewPlayer(ServerPlayer player); @Unique - private boolean quilt$continueJoining = false; + private boolean frozenLib$continueJoining = false; @Inject(method = "placeNewPlayer", at = @At("HEAD"), cancellable = true) - private void quilt$applySyncHandler(ServerPlayer player, CallbackInfo ci) { - if (!player.server.isSingleplayerOwner(player.getGameProfile()) && !this.quilt$continueJoining && ServerRegistrySync.shouldSync()) { + private void applySyncHandler(ServerPlayer player, CallbackInfo ci) { + if (!player.server.isSingleplayerOwner(player.getGameProfile()) && !this.frozenLib$continueJoining && ServerRegistrySync.shouldSync()) { this.connection.setListener(new ServerRegistrySyncNetworkHandler(player, this.connection, () -> { - this.quilt$continueJoining = true; + this.frozenLib$continueJoining = true; this.connection.setListener((PacketListener) this); this.placeNewPlayer(player); })); diff --git a/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/mixin/ServerPlayerMixin.java b/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/mixin/ServerPlayerMixin.java new file mode 100644 index 000000000..3295fc9e3 --- /dev/null +++ b/src/main/java/org/quiltmc/qsl/frozenblock/core/registry/mixin/ServerPlayerMixin.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 The Quilt Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.frozenblock.core.registry.mixin; + +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; +import net.minecraft.server.level.ServerPlayer; +import org.quiltmc.qsl.frozenblock.core.registry.impl.sync.server.DelayedPacketsHolder; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import java.util.List; + +@Mixin(ServerPlayer.class) +public class ServerPlayerMixin implements DelayedPacketsHolder { + + @Unique + private List frozenLib$delayedPackets; + + @Override + public void frozenLib$setPacketList(List packetList) { + this.frozenLib$delayedPackets = packetList; + } + + @Override + public List frozenLib$getPacketList() { + return this.frozenLib$delayedPackets; + } +} diff --git a/src/main/resources/mixin/frozenlib_quiltmc_registry.mixins.json b/src/main/resources/mixin/frozenlib_quiltmc_registry.mixins.json index 7385cca92..c4baa600a 100644 --- a/src/main/resources/mixin/frozenlib_quiltmc_registry.mixins.json +++ b/src/main/resources/mixin/frozenlib_quiltmc_registry.mixins.json @@ -7,8 +7,10 @@ "BuiltInRegistriesMixin", "ConnectionMixin", "MappedRegistryMixin", + "PlayerListMixin", "RegistryDataLoaderMixin", "ServerLoginNetworkHandlerMixin", + "ServerPlayerMixin", "ServerStatusVersionMixin" ], "injectors": {