| 1 | package net.minecraft.client.multiplayer.chat.report;
|
| 2 |
|
| 3 | import com.mojang.authlib.services.request.AbuseReportRequest.ClientInfo;
|
| 4 | import com.mojang.authlib.services.request.AbuseReportRequest.RealmInfo;
|
| 5 | import com.mojang.authlib.services.request.AbuseReportRequest.ThirdPartyServerInfo;
|
| 6 | import com.mojang.realmsclient.dto.RealmsServer;
|
| 7 | import java.util.Locale;
|
| 8 | import net.fabricmc.api.EnvType;
|
| 9 | import net.fabricmc.api.Environment;
|
| 10 | import net.minecraft.SharedConstants;
|
| 11 | import net.minecraft.client.Minecraft;
|
| 12 | import net.minecraft.client.multiplayer.chat.report.ReportEnvironment.Server.Realm;
|
| 13 | import net.minecraft.client.multiplayer.chat.report.ReportEnvironment.Server.ThirdParty;
|
| 14 | import org.jspecify.annotations.Nullable;
|
| 15 |
|
| 16 | @Environment(EnvType.CLIENT)
|
| 17 | public record ReportEnvironment(String clientVersion, ReportEnvironment.@Nullable Server server) {
|
| 18 | public static ReportEnvironment local() {
|
| 19 | return create(null);
|
| 20 | }
|
| 21 |
|
| 22 | public static ReportEnvironment thirdParty(final String ip) {
|
| 23 | return create(new ThirdParty(ip));
|
| 24 | }
|
| 25 |
|
| 26 | public static ReportEnvironment realm(final RealmsServer realm) {
|
| 27 | return create(new Realm(realm));
|
| 28 | }
|
| 29 |
|
| 30 | public static ReportEnvironment create(final ReportEnvironment.@Nullable Server server) {
|
| 31 | return new ReportEnvironment(getClientVersion(), server);
|
| 32 | }
|
| 33 |
|
| 34 | public ClientInfo clientInfo() {
|
| 35 | return new ClientInfo(this.clientVersion, Locale.getDefault().toLanguageTag());
|
| 36 | }
|
| 37 |
|
| 38 | public @Nullable ThirdPartyServerInfo thirdPartyServerInfo() {
|
| 39 | return this.server instanceof ThirdParty thirdParty ? new ThirdPartyServerInfo(thirdParty.ip) : null;
|
| 40 | }
|
| 41 |
|
| 42 | public @Nullable RealmInfo realmInfo() {
|
| 43 | return this.server instanceof Realm realm ? new RealmInfo(String.valueOf(realm.realmId()), realm.slotId()) : null;
|
| 44 | }
|
| 45 |
|
| 46 | private static String getClientVersion() {
|
| 47 | StringBuilder version = new StringBuilder();
|
| 48 | version.append(SharedConstants.getCurrentVersion().id());
|
| 49 | if (Minecraft.checkModStatus().shouldReportAsModified()) {
|
| 50 | version.append(" (modded)");
|
| 51 | }
|
| 52 |
|
| 53 | return version.toString();
|
| 54 | }
|
| 55 |
|
| 56 | @Environment(EnvType.CLIENT)
|
| 57 | public interface Server {
|
| 58 | }
|
| 59 | }
|
| 60 |
|