AbuseReportSender.java

net.minecraft.client.multiplayer.chat.report.AbuseReportSender

信息

  • 全限定名:net.minecraft.client.multiplayer.chat.report.AbuseReportSender
  • 类型:public interface
  • 包:net.minecraft.client.multiplayer.chat.report
  • 源码路径:src/main/java/net/minecraft/client/multiplayer/chat/report/AbuseReportSender.java
  • 起始行号:L20
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

  • net.minecraft.client.multiplayer.chat.report.AbuseReportSender.SendException

    • 类型: class
    • 修饰符: public static
    • 源码定位: L34
    • 说明:

      TODO

  • net.minecraft.client.multiplayer.chat.report.AbuseReportSender.Services

    • 类型: record
    • 修饰符: public
    • 源码定位: L41
    • 说明:

      TODO

构造器

方法

下面的方法块按源码顺序生成。

static AbuseReportSender create(ReportEnvironment environment, UserApiService userApiService) @ L21

  • 方法名:create
  • 源码定位:L21
  • 返回类型:AbuseReportSender
  • 修饰符:static

参数:

  • environment: ReportEnvironment
  • userApiService: UserApiService

说明:

TODO

CompletableFuture<Unit> send(UUID id, ReportType reportType, AbuseReport report) @ L25

  • 方法名:send
  • 源码定位:L25
  • 返回类型:CompletableFuture
  • 修饰符:package-private

参数:

  • id: UUID
  • reportType: ReportType
  • report: AbuseReport

说明:

TODO

boolean isEnabled() @ L27

  • 方法名:isEnabled
  • 源码定位:L27
  • 返回类型:boolean
  • 修饰符:package-private

参数:

说明:

TODO

default AbuseReportLimits reportLimits() @ L29

  • 方法名:reportLimits
  • 源码定位:L29
  • 返回类型:AbuseReportLimits
  • 修饰符:default

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public interface AbuseReportSender {
    static AbuseReportSender create(ReportEnvironment environment, UserApiService userApiService) {
        return new AbuseReportSender.Services(environment, userApiService);
    }
 
    CompletableFuture<Unit> send(UUID id, ReportType reportType, AbuseReport report);
 
    boolean isEnabled();
 
    default AbuseReportLimits reportLimits() {
        return AbuseReportLimits.DEFAULTS;
    }
 
    @OnlyIn(Dist.CLIENT)
    public static class SendException extends ThrowingComponent {
        public SendException(Component component, Throwable cause) {
            super(component, cause);
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public record Services(ReportEnvironment environment, UserApiService userApiService) implements AbuseReportSender {
        private static final Component SERVICE_UNAVAILABLE_TEXT = Component.translatable("gui.abuseReport.send.service_unavailable");
        private static final Component HTTP_ERROR_TEXT = Component.translatable("gui.abuseReport.send.http_error");
        private static final Component JSON_ERROR_TEXT = Component.translatable("gui.abuseReport.send.json_error");
 
        @Override
        public CompletableFuture<Unit> send(UUID id, ReportType reportType, AbuseReport report) {
            return CompletableFuture.supplyAsync(
                () -> {
                    AbuseReportRequest request = new AbuseReportRequest(
                        1,
                        id,
                        report,
                        this.environment.clientInfo(),
                        this.environment.thirdPartyServerInfo(),
                        this.environment.realmInfo(),
                        reportType.backendName()
                    );
 
                    try {
                        this.userApiService.reportAbuse(request);
                        return Unit.INSTANCE;
                    } catch (MinecraftClientHttpException var7) {
                        Component description = this.getHttpErrorDescription(var7);
                        throw new CompletionException(new AbuseReportSender.SendException(description, var7));
                    } catch (MinecraftClientException var8) {
                        Component descriptionx = this.getErrorDescription(var8);
                        throw new CompletionException(new AbuseReportSender.SendException(descriptionx, var8));
                    }
                },
                Util.ioPool()
            );
        }
 
        @Override
        public boolean isEnabled() {
            return this.userApiService.canSendReports();
        }
 
        private Component getHttpErrorDescription(MinecraftClientHttpException e) {
            return Component.translatable("gui.abuseReport.send.error_message", e.getMessage());
        }
 
        private Component getErrorDescription(MinecraftClientException e) {
            return switch (e.getType()) {
                case SERVICE_UNAVAILABLE -> SERVICE_UNAVAILABLE_TEXT;
                case HTTP_ERROR -> HTTP_ERROR_TEXT;
                case JSON_ERROR -> JSON_ERROR_TEXT;
            };
        }
 
        @Override
        public AbuseReportLimits reportLimits() {
            return this.userApiService.getAbuseReportLimits();
        }
    }
}

引用的其他类

  • ReportEnvironment

    • 引用位置: 参数
  • ReportType

    • 引用位置: 参数
  • Component

    • 引用位置: 方法调用
    • 关联成员: Component.translatable()
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.ioPool()