fix(room): last join pos is got overwritten by spawnpos

This commit is contained in:
iceBear67 committed 2024-09-01 23:44:02 +08:00
1 parent d66918fe78
commit df0fe6a130
1 file changed
+15 -1
@@ -1,13 +1,17 @@
package io.ib67.sfcraft.mixin.server.subserver;
import com.mojang.authlib.GameProfile;
import io.ib67.sfcraft.SFCraft;
import io.ib67.sfcraft.module.RoomModule;
import io.ib67.sfcraft.registry.RoomRegistry;
import io.ib67.sfcraft.util.Helper;
import net.minecraft.entity.Entity;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ConnectedClientData;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.math.GlobalPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
@@ -15,12 +19,14 @@ import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.net.SocketAddress;
import java.util.Set;
@Mixin(PlayerManager.class)
@@ -36,7 +42,9 @@ public abstract class PlayerManagerMixin {
var room = registry.getRoomBy(player.getUuid());
if (room != null) {
var spawn = room.getSpawnPosition();
teleportToRoom(player, spawn);
if(player.getWorld().getRegistryKey() != spawn.dimension()){
teleportToRoom(player, spawn);
}
LOGGER.info("Room player joined as " + player.getName().getLiteralString() + "/" + player.getUuid());
room.onPlayerJoin(player);
@@ -53,6 +61,12 @@ public abstract class PlayerManagerMixin {
}
}
@Inject(method = "checkCanJoin", cancellable = true, at = @At("HEAD"))
private void sf$bypassJoinLimit(SocketAddress address, GameProfile profile, CallbackInfoReturnable<Text> cir) {
if (RoomModule.isVirtual(profile.getId())) cir.setReturnValue(null);
}
@Unique
private void teleportToRoom(ServerPlayerEntity player, GlobalPos spawn) {
var world = player.getServer().getWorld(spawn.dimension());
var pos = spawn.pos();