package net.minecraft.client.server; import com.mojang.authlib.GameProfile; import com.mojang.logging.LogUtils; import java.net.SocketAddress; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.core.LayeredRegistryAccess; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.server.RegistryLayer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.players.PlayerList; import net.minecraft.util.ProblemReporter; import net.minecraft.world.level.storage.PlayerDataStorage; import net.minecraft.world.level.storage.TagValueOutput; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @Environment(EnvType.CLIENT) public class IntegratedPlayerList extends PlayerList { private static final Logger LOGGER = LogUtils.getLogger(); @Nullable private CompoundTag playerData; public IntegratedPlayerList(IntegratedServer server, LayeredRegistryAccess registries, PlayerDataStorage playerIo) { super(server, registries, playerIo, 8); this.setViewDistance(10); } @Override protected void save(ServerPlayer player) { if (this.getServer().isSingleplayerOwner(player.getGameProfile())) { try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(player.problemPath(), LOGGER)) { TagValueOutput tagValueOutput = TagValueOutput.createWithContext(scopedCollector, player.registryAccess()); player.saveWithoutId(tagValueOutput); this.playerData = tagValueOutput.buildResult(); } } super.save(player); } @Override public Component canPlayerLogin(SocketAddress socketAddress, GameProfile gameProfile) { return (Component)(this.getServer().isSingleplayerOwner(gameProfile) && this.getPlayerByName(gameProfile.getName()) != null ? Component.translatable("multiplayer.disconnect.name_taken") : super.canPlayerLogin(socketAddress, gameProfile)); } public IntegratedServer getServer() { return (IntegratedServer)super.getServer(); } @Nullable @Override public CompoundTag getSingleplayerData() { return this.playerData; } }