ChatSelectionLogFiller.java

net.minecraft.client.gui.screens.reporting.ChatSelectionLogFiller

信息

  • 全限定名:net.minecraft.client.gui.screens.reporting.ChatSelectionLogFiller
  • 类型:public class
  • 包:net.minecraft.client.gui.screens.reporting
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/reporting/ChatSelectionLogFiller.java
  • 起始行号:L18
  • 职责:

    TODO

字段/常量

  • log

    • 类型: ChatLog
    • 修饰符: private final
    • 源码定位: L19
    • 说明:

      TODO

  • contextBuilder

    • 类型: ChatReportContextBuilder
    • 修饰符: private final
    • 源码定位: L20
    • 说明:

      TODO

  • canReport

    • 类型: Predicate<LoggedChatMessage.Player>
    • 修饰符: private final
    • 源码定位: L21
    • 说明:

      TODO

  • previousLink

    • 类型: SignedMessageLink
    • 修饰符: private
    • 源码定位: L22
    • 说明:

      TODO

  • eventId

    • 类型: int
    • 修饰符: private
    • 源码定位: L23
    • 说明:

      TODO

  • missedCount

    • 类型: int
    • 修饰符: private
    • 源码定位: L24
    • 说明:

      TODO

  • lastMessage

    • 类型: PlayerChatMessage
    • 修饰符: private
    • 源码定位: L25
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.screens.reporting.ChatSelectionLogFiller.Output
    • 类型: interface
    • 修饰符: public
    • 源码定位: L79
    • 说明:

      TODO

构造器

public ChatSelectionLogFiller(ReportingContext reportingContext, Predicate<LoggedChatMessage.Player> canReport) @ L27

  • 构造器名:ChatSelectionLogFiller
  • 源码定位:L27
  • 修饰符:public

参数:

  • reportingContext: ReportingContext
  • canReport: Predicate<LoggedChatMessage.Player>

说明:

TODO

方法

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

public void fillNextPage(int pageSize, ChatSelectionLogFiller.Output output) @ L34

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

参数:

  • pageSize: int
  • output: ChatSelectionLogFiller.Output

说明:

TODO

private boolean acceptMessage(ChatSelectionLogFiller.Output output, LoggedChatMessage.Player event) @ L62

  • 方法名:acceptMessage
  • 源码定位:L62
  • 返回类型:boolean
  • 修饰符:private

参数:

  • output: ChatSelectionLogFiller.Output
  • event: LoggedChatMessage.Player

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class ChatSelectionLogFiller {
    private final ChatLog log;
    private final ChatReportContextBuilder contextBuilder;
    private final Predicate<LoggedChatMessage.Player> canReport;
    private @Nullable SignedMessageLink previousLink = null;
    private int eventId;
    private int missedCount;
    private @Nullable PlayerChatMessage lastMessage;
 
    public ChatSelectionLogFiller(ReportingContext reportingContext, Predicate<LoggedChatMessage.Player> canReport) {
        this.log = reportingContext.chatLog();
        this.contextBuilder = new ChatReportContextBuilder(reportingContext.sender().reportLimits().leadingContextMessageCount());
        this.canReport = canReport;
        this.eventId = this.log.end();
    }
 
    public void fillNextPage(int pageSize, ChatSelectionLogFiller.Output output) {
        int count = 0;
 
        while (count < pageSize) {
            LoggedChatEvent event = this.log.lookup(this.eventId);
            if (event == null) {
                break;
            }
 
            int eventId = this.eventId--;
            if (event instanceof LoggedChatMessage.Player message && !message.message().equals(this.lastMessage)) {
                if (this.acceptMessage(output, message)) {
                    if (this.missedCount > 0) {
                        output.acceptDivider(Component.translatable("gui.chatSelection.fold", this.missedCount));
                        this.missedCount = 0;
                    }
 
                    output.acceptMessage(eventId, message);
                    count++;
                } else {
                    this.missedCount++;
                }
 
                this.lastMessage = message.message();
            }
        }
    }
 
    private boolean acceptMessage(ChatSelectionLogFiller.Output output, LoggedChatMessage.Player event) {
        PlayerChatMessage message = event.message();
        boolean context = this.contextBuilder.acceptContext(message);
        if (this.canReport.test(event)) {
            this.contextBuilder.trackContext(message);
            if (this.previousLink != null && !this.previousLink.isDescendantOf(message.link())) {
                output.acceptDivider(Component.translatable("gui.chatSelection.join", event.profile().name()).withStyle(ChatFormatting.YELLOW));
            }
 
            this.previousLink = message.link();
            return true;
        } else {
            return context;
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public interface Output {
        void acceptMessage(int id, LoggedChatMessage.Player message);
 
        void acceptDivider(Component text);
    }
}

引用的其他类