ChatTrustLevel .java

net.minecraft.client.multiplayer.chat.ChatTrustLevel (enum): members: SECURE, MODIFIED, NOT_SECURE, containsModifiedStyle, isModifiedStyle, isNotSecure.

net.minecraft.client.multiplayer.chatenum70 linesclient2.3 KB

Implements

API Surface (3)

ChatTrustLevel evaluate(final PlayerChatMessage message, final Component decoratedMessage, final Instant received)
boolean isNotSecure()
String getSerializedName()

Fields & Constants (2)

CODEC
serializedName

String literals (3)

"secure"
"modified"
"not_secure"

Code Graph: Dependencies (6)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ChatTrustLevel.java70 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.multiplayer.chat;
2
3
import com.mojang.serialization.Codec;
4
import java.time.Instant;
5
import java.util.Optional;
6
import net.fabricmc.api.EnvType;
7
import net.fabricmc.api.Environment;
8
import net.minecraft.network.chat.Component;
9
import net.minecraft.network.chat.FontDescription;
10
import net.minecraft.network.chat.PlayerChatMessage;
11
import net.minecraft.network.chat.Style;
12
import net.minecraft.util.StringRepresentable;
13
import org.jspecify.annotations.Nullable;
14
15
@Environment(EnvType.CLIENT)
16
public enum ChatTrustLevel implements StringRepresentable {
17
	SECURE("secure"),
18
	MODIFIED("modified"),
19
	NOT_SECURE("not_secure");
20
21
	public static final Codec<ChatTrustLevel> CODEC = StringRepresentable.fromEnum(ChatTrustLevel::values);
22
	private final String serializedName;
23
24
	ChatTrustLevel(final String serializedName) {
25
		this.serializedName = serializedName;
26
	}
27
28
	public static ChatTrustLevel evaluate(final PlayerChatMessage message, final Component decoratedMessage, final Instant received) {
29
		if (!message.hasSignature() || message.hasExpiredClient(received)) {
30
			return NOT_SECURE;
31
		} else {
32
			return isModified(message, decoratedMessage) ? MODIFIED : SECURE;
33
		}
34
	}
35
36
	private static boolean isModified(final PlayerChatMessage message, final Component decoratedMessage) {
37
		if (!decoratedMessage.getString().contains(message.signedContent())) {
38
			return true;
39
		}
40
41
		Component decoratedContent = message.unsignedContent();
42
		return decoratedContent == null ? false : containsModifiedStyle(decoratedContent);
43
	}
44
45
	private static boolean containsModifiedStyle(final Component decoratedContent) {
46
		return decoratedContent.<Boolean>visit((style, contents) -> isModifiedStyle(style) ? Optional.of(true) : Optional.empty(), Style.EMPTY).orElse(false);
47
	}
48
49
	private static boolean isModifiedStyle(final Style style) {
50
		return !style.getFont().equals(FontDescription.DEFAULT);
51
	}
52
53
	public boolean isNotSecure() {
54
		return this == NOT_SECURE;
55
	}
56
57
	public @Nullable GuiMessageTag createTag(final PlayerChatMessage message) {
58
		return switch (this) {
59
			case MODIFIED -> GuiMessageTag.chatModified(message.signedContent());
60
			case NOT_SECURE -> GuiMessageTag.chatNotSecure();
61
			default -> null;
62
		};
63
	}
64
65
	@Override
66
	public String getSerializedName() {
67
		return this.serializedName;
68
	}
69
}
70

Decompiled Minecraft 26.3 source of ChatTrustLevel (net/minecraft/client/multiplayer/chat/ChatTrustLevel.java) with Mojang official mappings, stored verbatim on the site.