2025-11-24 22:52:51 +03:00

68 lines
2.4 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.logging.LogUtils
* org.jspecify.annotations.Nullable
* org.slf4j.Logger
*/
package net.minecraft.client.server;
import com.mojang.logging.LogUtils;
import java.net.SocketAddress;
import net.minecraft.client.server.IntegratedServer;
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.NameAndId;
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.jspecify.annotations.Nullable;
import org.slf4j.Logger;
public class IntegratedPlayerList
extends PlayerList {
private static final Logger LOGGER = LogUtils.getLogger();
private @Nullable CompoundTag playerData;
public IntegratedPlayerList(IntegratedServer server, LayeredRegistryAccess<RegistryLayer> registryHolder, PlayerDataStorage playerDataStorage) {
super(server, registryHolder, playerDataStorage, server.notificationManager());
this.setViewDistance(10);
}
@Override
protected void save(ServerPlayer player) {
if (this.getServer().isSingleplayerOwner(player.nameAndId())) {
try (ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(player.problemPath(), LOGGER);){
TagValueOutput output = TagValueOutput.createWithContext(reporter, player.registryAccess());
player.saveWithoutId(output);
this.playerData = output.buildResult();
}
}
super.save(player);
}
@Override
public Component canPlayerLogin(SocketAddress address, NameAndId nameAndId) {
if (this.getServer().isSingleplayerOwner(nameAndId) && this.getPlayerByName(nameAndId.name()) != null) {
return Component.translatable("multiplayer.disconnect.name_taken");
}
return super.canPlayerLogin(address, nameAndId);
}
@Override
public IntegratedServer getServer() {
return (IntegratedServer)super.getServer();
}
@Override
public @Nullable CompoundTag getSingleplayerData() {
return this.playerData;
}
}