package net.minecraft.client.multiplayer; import com.mojang.authlib.GameProfile; import java.util.function.Supplier; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.RemoteChatSession; import net.minecraft.network.chat.SignedMessageValidator; import net.minecraft.world.entity.player.PlayerSkin; import net.minecraft.world.entity.player.ProfilePublicKey; import net.minecraft.world.level.GameType; import net.minecraft.world.scores.PlayerTeam; import org.jspecify.annotations.Nullable; @Environment(EnvType.CLIENT) public class PlayerInfo { private final GameProfile profile; @Nullable private Supplier skinLookup; private GameType gameMode = GameType.DEFAULT_MODE; private int latency; @Nullable private Component tabListDisplayName; private boolean showHat = true; @Nullable private RemoteChatSession chatSession; private SignedMessageValidator messageValidator; private int tabListOrder; public PlayerInfo(final GameProfile profile, final boolean enforcesSecureChat) { this.profile = profile; this.messageValidator = fallbackMessageValidator(enforcesSecureChat); } private static Supplier createSkinLookup(final GameProfile profile) { Minecraft minecraft = Minecraft.getInstance(); boolean requireSecure = !minecraft.isLocalPlayer(profile.id()); return minecraft.getSkinManager().createLookup(profile, requireSecure); } public GameProfile getProfile() { return this.profile; } @Nullable public RemoteChatSession getChatSession() { return this.chatSession; } public SignedMessageValidator getMessageValidator() { return this.messageValidator; } public boolean hasVerifiableChat() { return this.chatSession != null; } protected void setChatSession(final RemoteChatSession chatSession) { this.chatSession = chatSession; this.messageValidator = chatSession.createMessageValidator(ProfilePublicKey.EXPIRY_GRACE_PERIOD); } protected void clearChatSession(final boolean enforcesSecureChat) { this.chatSession = null; this.messageValidator = fallbackMessageValidator(enforcesSecureChat); } private static SignedMessageValidator fallbackMessageValidator(final boolean enforcesSecureChat) { return enforcesSecureChat ? SignedMessageValidator.REJECT_ALL : SignedMessageValidator.ACCEPT_UNSIGNED; } public GameType getGameMode() { return this.gameMode; } protected void setGameMode(final GameType gameMode) { this.gameMode = gameMode; } public int getLatency() { return this.latency; } protected void setLatency(final int latency) { this.latency = latency; } public PlayerSkin getSkin() { if (this.skinLookup == null) { this.skinLookup = createSkinLookup(this.profile); } return (PlayerSkin)this.skinLookup.get(); } @Nullable public PlayerTeam getTeam() { return Minecraft.getInstance().level.getScoreboard().getPlayersTeam(this.getProfile().name()); } public void setTabListDisplayName(@Nullable final Component tabListDisplayName) { this.tabListDisplayName = tabListDisplayName; } @Nullable public Component getTabListDisplayName() { return this.tabListDisplayName; } public void setShowHat(final boolean showHat) { this.showHat = showHat; } public boolean showHat() { return this.showHat; } public void setTabListOrder(final int tabListOrder) { this.tabListOrder = tabListOrder; } public int getTabListOrder() { return this.tabListOrder; } }