RegionSelectionPreference .java

com.mojang.realmsclient.dto.RegionSelectionPreference (enum, 49 lines): members: AUTOMATIC_PLAYER, AUTOMATIC_OWNER, MANUAL, DEFAULT_SELECTION.

com.mojang.realmsclient.dtoenum49 linescommon1.6 KB

API Surface (2)

void write(final JsonWriter jsonWriter, final RegionSelectionPreference regionSelectionPreference)
RegionSelectionPreference read(final JsonReader jsonReader)

Fields & Constants (3)

DEFAULT_SELECTION
id
translationKey

Full Source

RegionSelectionPreference.java49 lines · Minecraft 26.3 · verbatim
1
package com.mojang.realmsclient.dto;
2
3
import com.google.gson.TypeAdapter;
4
import com.google.gson.stream.JsonReader;
5
import com.google.gson.stream.JsonWriter;
6
import com.mojang.logging.LogUtils;
7
import java.io.IOException;
8
import net.fabricmc.api.EnvType;
9
import net.fabricmc.api.Environment;
10
import org.slf4j.Logger;
11
12
@Environment(EnvType.CLIENT)
13
public enum RegionSelectionPreference {
14
	AUTOMATIC_PLAYER(0, "realms.configuration.region_preference.automatic_player"),
15
	AUTOMATIC_OWNER(1, "realms.configuration.region_preference.automatic_owner"),
16
	MANUAL(2, "");
17
18
	public static final RegionSelectionPreference DEFAULT_SELECTION = AUTOMATIC_PLAYER;
19
	public final int id;
20
	public final String translationKey;
21
22
	RegionSelectionPreference(final int id, final String translationKey) {
23
		this.id = id;
24
		this.translationKey = translationKey;
25
	}
26
27
	@Environment(EnvType.CLIENT)
28
	public static class RegionSelectionPreferenceJsonAdapter extends TypeAdapter<RegionSelectionPreference> {
29
		private static final Logger LOGGER = LogUtils.getLogger();
30
31
		public void write(final JsonWriter jsonWriter, final RegionSelectionPreference regionSelectionPreference) throws IOException {
32
			jsonWriter.value(regionSelectionPreference.id);
33
		}
34
35
		public RegionSelectionPreference read(final JsonReader jsonReader) throws IOException {
36
			int id = jsonReader.nextInt();
37
38
			for (RegionSelectionPreference value : RegionSelectionPreference.values()) {
39
				if (value.id == id) {
40
					return value;
41
				}
42
			}
43
44
			LOGGER.warn("Unsupported RegionSelectionPreference {}", id);
45
			return RegionSelectionPreference.DEFAULT_SELECTION;
46
		}
47
	}
48
}
49

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