InviteCode .java

com.mojang.realmsclient.dto.InviteCode (record, 45 lines): members: code, expirationDate, enabled, parse, LOGGER. strings: "Could not parse InviteCode".

com.mojang.realmsclient.dtorecord45 linescommon1.5 KB

API Surface (1)

record InviteCode(String code, @Nullable Instant expirationDate, boolean enabled)

Fields & Constants (1)

LOGGER

String literals (6)

"result"
"Could not parse InviteCode"
"code"
"Invite code response was missing a code"
"expirationDate"
"enabled"

Code Graph: Dependencies (2)

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

Full Source

InviteCode.java45 lines · Minecraft 26.3 · verbatim
1
package com.mojang.realmsclient.dto;
2
3
import com.google.gson.JsonElement;
4
import com.google.gson.JsonObject;
5
import com.mojang.logging.LogUtils;
6
import com.mojang.realmsclient.util.JsonUtils;
7
import java.time.Instant;
8
import net.fabricmc.api.EnvType;
9
import net.fabricmc.api.Environment;
10
import net.minecraft.util.LenientJsonParser;
11
import org.jspecify.annotations.Nullable;
12
import org.slf4j.Logger;
13
14
@Environment(EnvType.CLIENT)
15
public record InviteCode(String code, @Nullable Instant expirationDate, boolean enabled) {
16
	private static final Logger LOGGER = LogUtils.getLogger();
17
18
	public static @Nullable InviteCode parse(final String json) {
19
		try {
20
			JsonObject object = LenientJsonParser.parse(json).getAsJsonObject();
21
			JsonElement result = object.get("result");
22
			JsonObject payload = result != null && result.isJsonObject() ? result.getAsJsonObject() : object;
23
			return parse(payload);
24
		} catch (Exception e) {
25
			LOGGER.error("Could not parse InviteCode", e);
26
			return null;
27
		}
28
	}
29
30
	public static @Nullable InviteCode parse(final JsonObject json) {
31
		try {
32
			String code = JsonUtils.getStringOr("code", json, "");
33
			if (code.isEmpty()) {
34
				LOGGER.error("Invite code response was missing a code");
35
				return null;
36
			} else {
37
				return new InviteCode(code, JsonUtils.getEpochMillisOr("expirationDate", json, null), JsonUtils.getBooleanOr("enabled", json, false));
38
			}
39
		} catch (Exception e) {
40
			LOGGER.error("Could not parse InviteCode", e);
41
			return null;
42
		}
43
	}
44
}
45

Decompiled Minecraft 26.3 source of InviteCode (com/mojang/realmsclient/dto/InviteCode.java) with Mojang official mappings, stored verbatim on the site.