PlayerDto .java

net.minecraft.server.jsonrpc.api.PlayerDto (record): members: name, CODEC. imports: NameAndId, UUIDUtil, GameProfile, ServerPlayer, RecordCodecBuilder.

net.minecraft.server.jsonrpc.apirecord32 linesserver1.2 KB

API Surface (4)

record PlayerDto(Optional<UUID> id, Optional<String> name)
PlayerDto from(final GameProfile gameProfile)
PlayerDto from(final NameAndId nameAndId)
PlayerDto from(final ServerPlayer player)

Fields & Constants (1)

CODEC

Code Graph: Dependencies (3)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

PlayerDto.java32 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.jsonrpc.api;
2
3
import com.mojang.authlib.GameProfile;
4
import com.mojang.serialization.Codec;
5
import com.mojang.serialization.MapCodec;
6
import com.mojang.serialization.codecs.RecordCodecBuilder;
7
import java.util.Optional;
8
import java.util.UUID;
9
import net.minecraft.core.UUIDUtil;
10
import net.minecraft.server.level.ServerPlayer;
11
import net.minecraft.server.players.NameAndId;
12
13
public record PlayerDto(Optional<UUID> id, Optional<String> name) {
14
	public static final MapCodec<PlayerDto> CODEC = RecordCodecBuilder.mapCodec(
15
		i -> i.group(UUIDUtil.STRING_CODEC.optionalFieldOf("id").forGetter(PlayerDto::id), Codec.STRING.optionalFieldOf("name").forGetter(PlayerDto::name))
16
			.apply(i, PlayerDto::new)
17
	);
18
19
	public static PlayerDto from(final GameProfile gameProfile) {
20
		return new PlayerDto(Optional.of(gameProfile.id()), Optional.of(gameProfile.name()));
21
	}
22
23
	public static PlayerDto from(final NameAndId nameAndId) {
24
		return new PlayerDto(Optional.of(nameAndId.id()), Optional.of(nameAndId.name()));
25
	}
26
27
	public static PlayerDto from(final ServerPlayer player) {
28
		GameProfile gameProfile = player.getGameProfile();
29
		return from(gameProfile);
30
	}
31
}
32

Decompiled Minecraft 26.3 source of PlayerDto (net/minecraft/server/jsonrpc/api/PlayerDto.java) with Mojang official mappings, stored verbatim on the site.