NameAndId .java

net.minecraft.server.players.NameAndId (record): members: createOffline, appendTo, fromJson, name, CODEC. strings: "uuid". imports: UUIDUtil, GameProfile.

net.minecraft.server.playersrecord51 linesserver1.5 KB

API Surface (3)

record NameAndId(UUID id, String name)
void appendTo(final JsonObject output)
NameAndId createOffline(final String name)

Fields & Constants (1)

CODEC

String literals (1)

"uuid"

Code Graph: Dependencies (1)

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

Full Source

NameAndId.java51 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.players;
2
3
import com.google.gson.JsonObject;
4
import com.mojang.authlib.GameProfile;
5
import com.mojang.serialization.Codec;
6
import com.mojang.serialization.codecs.RecordCodecBuilder;
7
import java.util.UUID;
8
import net.minecraft.core.UUIDUtil;
9
import org.jspecify.annotations.Nullable;
10
11
public record NameAndId(UUID id, String name) {
12
	public static final Codec<NameAndId> CODEC = RecordCodecBuilder.create(
13
		i -> i.group(UUIDUtil.STRING_CODEC.fieldOf("id").forGetter(NameAndId::id), Codec.STRING.fieldOf("name").forGetter(NameAndId::name)).apply(i, NameAndId::new)
14
	);
15
16
	public NameAndId(final GameProfile profile) {
17
		this(profile.id(), profile.name());
18
	}
19
20
	public NameAndId(final com.mojang.authlib.services.response.NameAndId profile) {
21
		this(profile.id(), profile.name());
22
	}
23
24
	public static @Nullable NameAndId fromJson(final JsonObject object) {
25
		if (object.has("uuid") && object.has("name")) {
26
			String uuidString = object.get("uuid").getAsString();
27
28
			UUID uuid;
29
			try {
30
				uuid = UUID.fromString(uuidString);
31
			} catch (Throwable ignored) {
32
				return null;
33
			}
34
35
			return new NameAndId(uuid, object.get("name").getAsString());
36
		} else {
37
			return null;
38
		}
39
	}
40
41
	public void appendTo(final JsonObject output) {
42
		output.addProperty("uuid", this.id().toString());
43
		output.addProperty("name", this.name());
44
	}
45
46
	public static NameAndId createOffline(final String name) {
47
		UUID id = UUIDUtil.createOfflinePlayerUUID(name);
48
		return new NameAndId(id, name);
49
	}
50
}
51

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