ChatSelectionLogFiller .java

net.minecraft.client.gui.screens.reporting.ChatSelectionLogFiller (class, 85 lines): members: contextBuilder, fillNextPage, previousLink, lastMessage, log.

net.minecraft.client.gui.screens.reportingclass85 linesclient2.9 KB

API Surface (1)

void fillNextPage(final int pageSize, final ChatSelectionLogFiller.Output output)

Fields & Constants (7)

log
contextBuilder
canReport
previousLink
eventId
missedCount
lastMessage

String literals (2)

"gui.chatSelection.fold"
"gui.chatSelection.join"

Full Source

ChatSelectionLogFiller.java85 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.screens.reporting;
2
3
import java.util.function.Predicate;
4
import net.fabricmc.api.EnvType;
5
import net.fabricmc.api.Environment;
6
import net.minecraft.ChatFormatting;
7
import net.minecraft.client.multiplayer.chat.ChatLog;
8
import net.minecraft.client.multiplayer.chat.LoggedChatEvent;
9
import net.minecraft.client.multiplayer.chat.LoggedChatMessage;
10
import net.minecraft.client.multiplayer.chat.report.ChatReportContextBuilder;
11
import net.minecraft.client.multiplayer.chat.report.ReportingContext;
12
import net.minecraft.network.chat.Component;
13
import net.minecraft.network.chat.PlayerChatMessage;
14
import net.minecraft.network.chat.SignedMessageLink;
15
import org.jspecify.annotations.Nullable;
16
17
@Environment(EnvType.CLIENT)
18
public class ChatSelectionLogFiller {
19
	private final ChatLog log;
20
	private final ChatReportContextBuilder contextBuilder;
21
	private final Predicate<LoggedChatMessage.Player> canReport;
22
	private @Nullable SignedMessageLink previousLink = null;
23
	private int eventId;
24
	private int missedCount;
25
	private @Nullable PlayerChatMessage lastMessage;
26
27
	public ChatSelectionLogFiller(final ReportingContext reportingContext, final Predicate<LoggedChatMessage.Player> canReport) {
28
		this.log = reportingContext.chatLog();
29
		this.contextBuilder = new ChatReportContextBuilder(reportingContext.sender().reportLimits().leadingContextMessageCount());
30
		this.canReport = canReport;
31
		this.eventId = this.log.end();
32
	}
33
34
	public void fillNextPage(final int pageSize, final ChatSelectionLogFiller.Output output) {
35
		int count = 0;
36
37
		while (count < pageSize) {
38
			LoggedChatEvent event = this.log.lookup(this.eventId);
39
			if (event == null) {
40
				break;
41
			}
42
43
			int eventId = this.eventId--;
44
			if (event instanceof LoggedChatMessage.Player message && !message.message().equals(this.lastMessage)) {
45
				if (this.acceptMessage(output, message)) {
46
					if (this.missedCount > 0) {
47
						output.acceptDivider(Component.translatable("gui.chatSelection.fold", this.missedCount));
48
						this.missedCount = 0;
49
					}
50
51
					output.acceptMessage(eventId, message);
52
					count++;
53
				} else {
54
					this.missedCount++;
55
				}
56
57
				this.lastMessage = message.message();
58
			}
59
		}
60
	}
61
62
	private boolean acceptMessage(final ChatSelectionLogFiller.Output output, final LoggedChatMessage.Player event) {
63
		PlayerChatMessage message = event.message();
64
		boolean context = this.contextBuilder.acceptContext(message);
65
		if (this.canReport.test(event)) {
66
			this.contextBuilder.trackContext(message);
67
			if (this.previousLink != null && !this.previousLink.isDescendantOf(message.link())) {
68
				output.acceptDivider(Component.translatable("gui.chatSelection.join", event.profile().name()).withStyle(ChatFormatting.YELLOW));
69
			}
70
71
			this.previousLink = message.link();
72
			return true;
73
		} else {
74
			return context;
75
		}
76
	}
77
78
	@Environment(EnvType.CLIENT)
79
	public interface Output {
80
		void acceptMessage(int id, LoggedChatMessage.Player message);
81
82
		void acceptDivider(Component text);
83
	}
84
}
85

Decompiled Minecraft 26.3 source of ChatSelectionLogFiller (net/minecraft/client/gui/screens/reporting/ChatSelectionLogFiller.java) with Mojang official mappings, stored verbatim on the site.