ChatReport.java

net.minecraft.client.multiplayer.chat.report.ChatReport

信息

  • 全限定名:net.minecraft.client.multiplayer.chat.report.ChatReport
  • 类型:public class
  • 包:net.minecraft.client.multiplayer.chat.report
  • 源码路径:src/main/java/net/minecraft/client/multiplayer/chat/report/ChatReport.java
  • 起始行号:L31
  • 继承:Report
  • 职责:

    TODO

字段/常量

  • reportedMessages
    • 类型: IntSet
    • 修饰符: private final
    • 源码定位: L32
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.multiplayer.chat.report.ChatReport.Builder
    • 类型: class
    • 修饰符: public static
    • 源码定位: L61
    • 说明:

      TODO

构造器

private ChatReport(UUID reportId, Instant createdAt, UUID reportedProfileId) @ L34

  • 构造器名:ChatReport
  • 源码定位:L34
  • 修饰符:private

参数:

  • reportId: UUID
  • createdAt: Instant
  • reportedProfileId: UUID

说明:

TODO

方法

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

public void toggleReported(int id, AbuseReportLimits limits) @ L38

  • 方法名:toggleReported
  • 源码定位:L38
  • 返回类型:void
  • 修饰符:public

参数:

  • id: int
  • limits: AbuseReportLimits

说明:

TODO

public ChatReport copy() @ L46

  • 方法名:copy
  • 源码定位:L46
  • 返回类型:ChatReport
  • 修饰符:public

参数:

说明:

TODO

public Screen createScreen(Screen lastScreen, ReportingContext context) @ L55

  • 方法名:createScreen
  • 源码定位:L55
  • 返回类型:Screen
  • 修饰符:public

参数:

  • lastScreen: Screen
  • context: ReportingContext

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class ChatReport extends Report {
    private final IntSet reportedMessages = new IntOpenHashSet();
 
    private ChatReport(UUID reportId, Instant createdAt, UUID reportedProfileId) {
        super(reportId, createdAt, reportedProfileId);
    }
 
    public void toggleReported(int id, AbuseReportLimits limits) {
        if (this.reportedMessages.contains(id)) {
            this.reportedMessages.remove(id);
        } else if (this.reportedMessages.size() < limits.maxReportedMessageCount()) {
            this.reportedMessages.add(id);
        }
    }
 
    public ChatReport copy() {
        ChatReport result = new ChatReport(this.reportId, this.createdAt, this.reportedProfileId);
        result.reportedMessages.addAll(this.reportedMessages);
        result.comments = this.comments;
        result.reason = this.reason;
        result.attested = this.attested;
        return result;
    }
 
    @Override
    public Screen createScreen(Screen lastScreen, ReportingContext context) {
        return new ChatReportScreen(lastScreen, context, this);
    }
 
    @OnlyIn(Dist.CLIENT)
    public static class Builder extends Report.Builder<ChatReport> {
        public Builder(ChatReport report, AbuseReportLimits limits) {
            super(report, limits);
        }
 
        public Builder(UUID reportedProfileId, AbuseReportLimits limits) {
            super(new ChatReport(UUID.randomUUID(), Instant.now(), reportedProfileId), limits);
        }
 
        public IntSet reportedMessages() {
            return this.report.reportedMessages;
        }
 
        public void toggleReported(int id) {
            this.report.toggleReported(id, this.limits);
        }
 
        public boolean isReported(int id) {
            return this.report.reportedMessages.contains(id);
        }
 
        @Override
        public boolean hasContent() {
            return StringUtils.isNotEmpty(this.comments()) || !this.reportedMessages().isEmpty() || this.reason() != null;
        }
 
        @Override
        public Report.@Nullable CannotBuildReason checkBuildable() {
            if (this.report.reportedMessages.isEmpty()) {
                return Report.CannotBuildReason.NO_REPORTED_MESSAGES;
            } else if (this.report.reportedMessages.size() > this.limits.maxReportedMessageCount()) {
                return Report.CannotBuildReason.TOO_MANY_MESSAGES;
            } else if (this.report.reason == null) {
                return Report.CannotBuildReason.NO_REASON;
            } else {
                return this.report.comments.length() > this.limits.maxOpinionCommentsLength()
                    ? Report.CannotBuildReason.COMMENT_TOO_LONG
                    : super.checkBuildable();
            }
        }
 
        @Override
        public Either<Report.Result, Report.CannotBuildReason> build(ReportingContext reportingContext) {
            Report.CannotBuildReason error = this.checkBuildable();
            if (error != null) {
                return Either.right(error);
            } else {
                String reason = Objects.requireNonNull(this.report.reason).backendName();
                ReportEvidence evidence = this.buildEvidence(reportingContext);
                ReportedEntity reportedEntity = new ReportedEntity(this.report.reportedProfileId);
                AbuseReport abuseReport = AbuseReport.chat(this.report.comments, reason, evidence, reportedEntity, this.report.createdAt);
                return Either.left(new Report.Result(this.report.reportId, ReportType.CHAT, abuseReport));
            }
        }
 
        private ReportEvidence buildEvidence(ReportingContext reportingContext) {
            List<ReportChatMessage> allReportMessages = new ArrayList<>();
            ChatReportContextBuilder contextBuilder = new ChatReportContextBuilder(this.limits.leadingContextMessageCount());
            contextBuilder.collectAllContext(
                reportingContext.chatLog(),
                this.report.reportedMessages,
                (id, event) -> allReportMessages.add(this.buildReportedChatMessage(event, this.isReported(id)))
            );
            return new ReportEvidence(Lists.reverse(allReportMessages));
        }
 
        private ReportChatMessage buildReportedChatMessage(LoggedChatMessage.Player chat, boolean reported) {
            SignedMessageLink link = chat.message().link();
            SignedMessageBody body = chat.message().signedBody();
            List<ByteBuffer> lastSeen = body.lastSeen().entries().stream().map(MessageSignature::asByteBuffer).toList();
            ByteBuffer signature = Optionull.map(chat.message().signature(), MessageSignature::asByteBuffer);
            return new ReportChatMessage(
                link.index(), link.sender(), link.sessionId(), body.timeStamp(), body.salt(), lastSeen, body.content(), signature, reported
            );
        }
 
        public ChatReport.Builder copy() {
            return new ChatReport.Builder(this.report.copy(), this.limits);
        }
    }
}

引用的其他类

  • Optionull

    • 引用位置: 方法调用
    • 关联成员: Optionull.map()
  • Screen

    • 引用位置: 参数/返回值
  • ChatReportScreen

    • 引用位置: 构造调用
    • 关联成员: ChatReportScreen()
  • ChatReportContextBuilder

    • 引用位置: 构造调用
    • 关联成员: ChatReportContextBuilder()
  • Report

    • 引用位置: 方法调用/构造调用/继承
    • 关联成员: Report.Result(), Result()
  • ReportingContext

    • 引用位置: 参数