From eb29b4f989f23260b0cc2f244d1c7b703114ac0a Mon Sep 17 00:00:00 2001 From: sandtechnology <20417547+sandtechnology@users.noreply.github.com> Date: Fri, 21 Oct 2022 10:35:48 +0800 Subject: [PATCH] Fix couples issues related to respawn and cross-world teleport (#752) Co-authored-by: IzzelAliz --- .../server/management/PlayerListMixin.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java index 4639633f..195d945e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java @@ -84,6 +84,7 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -166,11 +167,11 @@ public abstract class PlayerListMixin implements PlayerListBridge { this.players.add(playerIn); this.playersByUUID.put(playerIn.getUUID(), playerIn); this.cserver.getPluginManager().callEvent(playerJoinEvent); + this.players.remove(playerIn); if (!playerIn.connection.connection.isConnected()) { ci.cancel(); return; } - this.players.remove(playerIn); String joinMessage = playerJoinEvent.getJoinMessage(); if (joinMessage != null && joinMessage.length() > 0) { for (Component line : CraftChatMessage.fromString(joinMessage)) { @@ -179,6 +180,18 @@ public abstract class PlayerListMixin implements PlayerListBridge { } } + @Redirect(method = "placeNewPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addNewPlayer(Lnet/minecraft/server/level/ServerPlayer;)V")) + private void arclight$addNewPlayer(ServerLevel instance, ServerPlayer player) { + if (player.level == instance && !instance.players().contains(player)) { + instance.addNewPlayer(player); + } + } + + @ModifyVariable(method = "placeNewPlayer", ordinal = 1, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/level/ServerLevel;addNewPlayer(Lnet/minecraft/server/level/ServerPlayer;)V")) + private ServerLevel arclight$handleWorldChanges(ServerLevel value, Connection connection, ServerPlayer player) { + return player.getLevel(); + } + @Inject(method = "save", cancellable = true, at = @At("HEAD")) private void arclight$returnIfNotPersist(ServerPlayer playerIn, CallbackInfo ci) { if (!((ServerPlayerEntityBridge) playerIn).bridge$isPersist()) { @@ -319,9 +332,9 @@ public abstract class PlayerListMixin implements PlayerListBridge { location.setWorld(((WorldBridge) worldIn).bridge$getWorld()); } ServerLevel serverWorld = ((CraftWorld) location.getWorld()).getHandle(); - playerIn.absMoveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + playerIn.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); playerIn.connection.resetPosition(); - while (avoidSuffocation && !serverWorld.noCollision(playerIn) && playerIn.getY() < 256.0) { + while (avoidSuffocation && !serverWorld.noCollision(playerIn) && playerIn.getY() < serverWorld.getMaxBuildHeight()) { playerIn.setPos(playerIn.getX(), playerIn.getY() + 1.0, playerIn.getZ()); } LevelData worlddata = serverWorld.getLevelData(); @@ -337,7 +350,7 @@ public abstract class PlayerListMixin implements PlayerListBridge { this.sendLevelInfo(playerIn, serverWorld); this.sendPlayerPermissionLevel(playerIn); if (!((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) { - serverWorld.addDuringCommandTeleport(playerIn); + serverWorld.addRespawnedPlayer(playerIn); this.addPlayer(playerIn); this.playersByUUID.put(playerIn.getUUID(), playerIn); } @@ -463,7 +476,7 @@ public abstract class PlayerListMixin implements PlayerListBridge { serverplayerentity.addTag(s); } - serverplayerentity.absMoveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + serverplayerentity.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); serverplayerentity.connection.resetPosition(); while (avoidSuffocation && !serverWorld.noCollision(serverplayerentity) && serverplayerentity.getY() < serverWorld.getMaxBuildHeight()) {