48 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package com.mojang.realmsclient.dto;
 | |
| 
 | |
| import com.google.gson.TypeAdapter;
 | |
| import com.google.gson.stream.JsonReader;
 | |
| import com.google.gson.stream.JsonWriter;
 | |
| import com.mojang.logging.LogUtils;
 | |
| import java.io.IOException;
 | |
| import net.fabricmc.api.EnvType;
 | |
| import net.fabricmc.api.Environment;
 | |
| import org.slf4j.Logger;
 | |
| 
 | |
| @Environment(EnvType.CLIENT)
 | |
| public enum RegionSelectionPreference {
 | |
| 	AUTOMATIC_PLAYER(0, "realms.configuration.region_preference.automatic_player"),
 | |
| 	AUTOMATIC_OWNER(1, "realms.configuration.region_preference.automatic_owner"),
 | |
| 	MANUAL(2, "");
 | |
| 
 | |
| 	public static final RegionSelectionPreference DEFAULT_SELECTION = AUTOMATIC_PLAYER;
 | |
| 	public final int id;
 | |
| 	public final String translationKey;
 | |
| 
 | |
| 	private RegionSelectionPreference(final int id, final String translationKey) {
 | |
| 		this.id = id;
 | |
| 		this.translationKey = translationKey;
 | |
| 	}
 | |
| 
 | |
| 	@Environment(EnvType.CLIENT)
 | |
| 	public static class RegionSelectionPreferenceJsonAdapter extends TypeAdapter<RegionSelectionPreference> {
 | |
| 		private static final Logger LOGGER = LogUtils.getLogger();
 | |
| 
 | |
| 		public void write(JsonWriter writer, RegionSelectionPreference regionSelectionPreference) throws IOException {
 | |
| 			writer.value((long)regionSelectionPreference.id);
 | |
| 		}
 | |
| 
 | |
| 		public RegionSelectionPreference read(JsonReader reader) throws IOException {
 | |
| 			int i = reader.nextInt();
 | |
| 
 | |
| 			for (RegionSelectionPreference regionSelectionPreference : RegionSelectionPreference.values()) {
 | |
| 				if (regionSelectionPreference.id == i) {
 | |
| 					return regionSelectionPreference;
 | |
| 				}
 | |
| 			}
 | |
| 
 | |
| 			LOGGER.warn("Unsupported RegionSelectionPreference {}", i);
 | |
| 			return RegionSelectionPreference.DEFAULT_SELECTION;
 | |
| 		}
 | |
| 	}
 | |
| }
 |