ServerLinks .java

net.minecraft.server.ServerLinks (record): members: entries, UNTRUSTED_LINKS_STREAM_CODEC, TYPE_STREAM_CODEC, UntrustedEntry, KnownLinkType, findKnownType.

net.minecraft.serverrecord90 linesserver3.2 KB

API Surface (10)

record ServerLinks(List<ServerLinks.Entry> entries)
boolean isEmpty()
Optional<ServerLinks.Entry> findKnownType(final ServerLinks.KnownLinkType type)
List<ServerLinks.UntrustedEntry> untrust()
record Entry(Either<ServerLinks.KnownLinkType, Component> type, URI link)
ServerLinks.Entry knownType(final ServerLinks.KnownLinkType type, final URI link)
ServerLinks.Entry custom(final Component displayName, final URI link)
Component displayName()
ServerLinks.Entry create(final URI link)
record UntrustedEntry(Either<ServerLinks.KnownLinkType, Component> type, String link)

Fields & Constants (3)

EMPTY
TYPE_STREAM_CODEC
UNTRUSTED_LINKS_STREAM_CODEC

String literals (11)

"report_bug"
"community_guidelines"
"support"
"status"
"feedback"
"community"
"website"
"forums"
"news"
"announcements"
"known_server_link."

Code Graph: Dependencies (6)

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

Full Source

ServerLinks.java90 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server;
2
3
import com.mojang.datafixers.util.Either;
4
import io.netty.buffer.ByteBuf;
5
import java.net.URI;
6
import java.util.List;
7
import java.util.Optional;
8
import java.util.function.IntFunction;
9
import net.minecraft.network.chat.Component;
10
import net.minecraft.network.chat.ComponentSerialization;
11
import net.minecraft.network.codec.ByteBufCodecs;
12
import net.minecraft.network.codec.StreamCodec;
13
import net.minecraft.util.ByIdMap;
14
15
public record ServerLinks(List<ServerLinks.Entry> entries) {
16
	public static final ServerLinks EMPTY = new ServerLinks(List.of());
17
	public static final StreamCodec<ByteBuf, Either<ServerLinks.KnownLinkType, Component>> TYPE_STREAM_CODEC = ByteBufCodecs.either(
18
		ServerLinks.KnownLinkType.STREAM_CODEC, ComponentSerialization.TRUSTED_CONTEXT_FREE_STREAM_CODEC
19
	);
20
	public static final StreamCodec<ByteBuf, List<ServerLinks.UntrustedEntry>> UNTRUSTED_LINKS_STREAM_CODEC = ServerLinks.UntrustedEntry.STREAM_CODEC
21
		.apply(ByteBufCodecs.list());
22
23
	public boolean isEmpty() {
24
		return this.entries.isEmpty();
25
	}
26
27
	public Optional<ServerLinks.Entry> findKnownType(final ServerLinks.KnownLinkType type) {
28
		return this.entries.stream().filter(e -> e.type.map(l -> l == type, r -> false)).findFirst();
29
	}
30
31
	public List<ServerLinks.UntrustedEntry> untrust() {
32
		return this.entries.stream().map(e -> new ServerLinks.UntrustedEntry(e.type, e.link.toString())).toList();
33
	}
34
35
	public record Entry(Either<ServerLinks.KnownLinkType, Component> type, URI link) {
36
		public static ServerLinks.Entry knownType(final ServerLinks.KnownLinkType type, final URI link) {
37
			return new ServerLinks.Entry(Either.left(type), link);
38
		}
39
40
		public static ServerLinks.Entry custom(final Component displayName, final URI link) {
41
			return new ServerLinks.Entry(Either.right(displayName), link);
42
		}
43
44
		public Component displayName() {
45
			return this.type.map(ServerLinks.KnownLinkType::displayName, r -> (Component)r);
46
		}
47
	}
48
49
	public enum KnownLinkType {
50
		BUG_REPORT(0, "report_bug"),
51
		COMMUNITY_GUIDELINES(1, "community_guidelines"),
52
		SUPPORT(2, "support"),
53
		STATUS(3, "status"),
54
		FEEDBACK(4, "feedback"),
55
		COMMUNITY(5, "community"),
56
		WEBSITE(6, "website"),
57
		FORUMS(7, "forums"),
58
		NEWS(8, "news"),
59
		ANNOUNCEMENTS(9, "announcements");
60
61
		private static final IntFunction<ServerLinks.KnownLinkType> BY_ID = ByIdMap.continuous(e -> e.id, values(), ByIdMap.OutOfBoundsStrategy.ZERO);
62
		public static final StreamCodec<ByteBuf, ServerLinks.KnownLinkType> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, e -> e.id);
63
		private final int id;
64
		private final String name;
65
66
		KnownLinkType(final int id, final String name) {
67
			this.id = id;
68
			this.name = name;
69
		}
70
71
		private Component displayName() {
72
			return Component.translatable("known_server_link." + this.name);
73
		}
74
75
		public ServerLinks.Entry create(final URI link) {
76
			return ServerLinks.Entry.knownType(this, link);
77
		}
78
	}
79
80
	public record UntrustedEntry(Either<ServerLinks.KnownLinkType, Component> type, String link) {
81
		public static final StreamCodec<ByteBuf, ServerLinks.UntrustedEntry> STREAM_CODEC = StreamCodec.composite(
82
			ServerLinks.TYPE_STREAM_CODEC,
83
			ServerLinks.UntrustedEntry::type,
84
			ByteBufCodecs.STRING_UTF8,
85
			ServerLinks.UntrustedEntry::link,
86
			ServerLinks.UntrustedEntry::new
87
		);
88
	}
89
}
90

Decompiled Minecraft 26.3 source of ServerLinks (net/minecraft/server/ServerLinks.java) with Mojang official mappings, stored verbatim on the site.