ServerDebugSubscribers .java

net.minecraft.util.debug.ServerDebugSubscribers (class, 57 lines): members: hasRequiredPermissions, broadcastToAll, enabledSubscriptions, server, tick.

net.minecraft.util.debugclass57 linescommon1.9 KB

API Surface (5)

void tick()
void broadcastToAll(final DebugSubscription<?> subscription, final Packet<?> packet)
Set<DebugSubscription<?>> enabledSubscriptions()
boolean hasAnySubscriberFor(final DebugSubscription<?> subscription)
boolean hasRequiredPermissions(final ServerPlayer player)

Fields & Constants (2)

server
enabledSubscriptions

Code Graph: Dependencies (6)

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

Full Source

ServerDebugSubscribers.java57 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.debug;
2
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Map;
7
import java.util.Set;
8
import net.minecraft.SharedConstants;
9
import net.minecraft.network.protocol.Packet;
10
import net.minecraft.server.MinecraftServer;
11
import net.minecraft.server.level.ServerPlayer;
12
import net.minecraft.server.players.NameAndId;
13
14
public class ServerDebugSubscribers {
15
	private final MinecraftServer server;
16
	private final Map<DebugSubscription<?>, List<ServerPlayer>> enabledSubscriptions = new HashMap<>();
17
18
	public ServerDebugSubscribers(final MinecraftServer server) {
19
		this.server = server;
20
	}
21
22
	private List<ServerPlayer> getSubscribersFor(final DebugSubscription<?> subscription) {
23
		return this.enabledSubscriptions.getOrDefault(subscription, List.of());
24
	}
25
26
	public void tick() {
27
		this.enabledSubscriptions.values().forEach(List::clear);
28
29
		for (ServerPlayer player : this.server.getPlayerList().getPlayers()) {
30
			for (DebugSubscription<?> subscription : player.debugSubscriptions()) {
31
				this.enabledSubscriptions.computeIfAbsent(subscription, s -> new ArrayList<>()).add(player);
32
			}
33
		}
34
35
		this.enabledSubscriptions.values().removeIf(List::isEmpty);
36
	}
37
38
	public void broadcastToAll(final DebugSubscription<?> subscription, final Packet<?> packet) {
39
		for (ServerPlayer player : this.getSubscribersFor(subscription)) {
40
			player.connection.send(packet);
41
		}
42
	}
43
44
	public Set<DebugSubscription<?>> enabledSubscriptions() {
45
		return Set.copyOf(this.enabledSubscriptions.keySet());
46
	}
47
48
	public boolean hasAnySubscriberFor(final DebugSubscription<?> subscription) {
49
		return !this.getSubscribersFor(subscription).isEmpty();
50
	}
51
52
	public boolean hasRequiredPermissions(final ServerPlayer player) {
53
		NameAndId nameAndId = player.nameAndId();
54
		return SharedConstants.IS_RUNNING_IN_IDE && this.server.isSingleplayerOwner(nameAndId) ? true : this.server.getPlayerList().isOp(nameAndId);
55
	}
56
}
57

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