WorldTemplatePaginatedList .java

com.mojang.realmsclient.dto.WorldTemplatePaginatedList (record): members: templates, page, size, total, isLastPage, parse, LOGGER. strings: "total".

com.mojang.realmsclient.dtorecord53 linescommon1.6 KB

API Surface (3)

record WorldTemplatePaginatedList(List<WorldTemplate> templates, int page, int size, int total)
boolean isLastPage()
WorldTemplatePaginatedList parse(final String json)

Fields & Constants (1)

LOGGER

String literals (5)

"templates"
"page"
"size"
"total"
"Could not parse WorldTemplatePaginatedList"

Code Graph: Dependencies (3)

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

Full Source

WorldTemplatePaginatedList.java53 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.util.ArrayList;
8
import java.util.List;
9
import net.fabricmc.api.EnvType;
10
import net.fabricmc.api.Environment;
11
import net.minecraft.util.LenientJsonParser;
12
import org.slf4j.Logger;
13
14
@Environment(EnvType.CLIENT)
15
public record WorldTemplatePaginatedList(List<WorldTemplate> templates, int page, int size, int total) {
16
	private static final Logger LOGGER = LogUtils.getLogger();
17
18
	public WorldTemplatePaginatedList(final int size) {
19
		this(List.of(), 0, size, -1);
20
	}
21
22
	public boolean isLastPage() {
23
		return this.page * this.size >= this.total && this.page > 0 && this.total > 0 && this.size > 0;
24
	}
25
26
	public static WorldTemplatePaginatedList parse(final String json) {
27
		List<WorldTemplate> templates = new ArrayList<>();
28
		int page = 0;
29
		int size = 0;
30
		int total = 0;
31
32
		try {
33
			JsonObject object = LenientJsonParser.parse(json).getAsJsonObject();
34
			if (object.get("templates").isJsonArray()) {
35
				for (JsonElement element : object.get("templates").getAsJsonArray()) {
36
					WorldTemplate template = WorldTemplate.parse(element.getAsJsonObject());
37
					if (template != null) {
38
						templates.add(template);
39
					}
40
				}
41
			}
42
43
			page = JsonUtils.getIntOr("page", object, 0);
44
			size = JsonUtils.getIntOr("size", object, 0);
45
			total = JsonUtils.getIntOr("total", object, 0);
46
		} catch (Exception e) {
47
			LOGGER.error("Could not parse WorldTemplatePaginatedList", e);
48
		}
49
50
		return new WorldTemplatePaginatedList(templates, page, size, total);
51
	}
52
}
53

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