UserWhiteList .java

net.minecraft.server.players.UserWhiteList (class, 63 lines): members: isWhiteListed, getKeyForUser, getUserList, createEntry, clear, remove, add.

net.minecraft.server.playersclass63 linesserverextends StoredUserList<NameAndId1.5 KB

API Surface (7)

StoredUserEntry<NameAndId> createEntry(final JsonObject object)
boolean isWhiteListed(final NameAndId user)
boolean add(final UserWhiteListEntry infos)
boolean remove(final NameAndId user)
void clear()
String[] getUserList()
String getKeyForUser(final NameAndId user)

Code Graph: Dependencies (5)

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

Full Source

UserWhiteList.java63 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.players;
2
3
import com.google.gson.JsonObject;
4
import java.io.File;
5
import java.util.Objects;
6
import net.minecraft.server.notifications.NotificationService;
7
8
public class UserWhiteList extends StoredUserList<NameAndId, UserWhiteListEntry> {
9
	public UserWhiteList(final File file, final NotificationService notificationService) {
10
		super(file, notificationService);
11
	}
12
13
	@Override
14
	protected StoredUserEntry<NameAndId> createEntry(final JsonObject object) {
15
		return new UserWhiteListEntry(object);
16
	}
17
18
	public boolean isWhiteListed(final NameAndId user) {
19
		return this.contains(user);
20
	}
21
22
	public boolean add(final UserWhiteListEntry infos) {
23
		if (super.add(infos)) {
24
			if (infos.getUser() != null) {
25
				this.notificationService.playerAddedToAllowlist(infos.getUser());
26
			}
27
28
			return true;
29
		} else {
30
			return false;
31
		}
32
	}
33
34
	public boolean remove(final NameAndId user) {
35
		if (super.remove(user)) {
36
			this.notificationService.playerRemovedFromAllowlist(user);
37
			return true;
38
		} else {
39
			return false;
40
		}
41
	}
42
43
	@Override
44
	public void clear() {
45
		for (UserWhiteListEntry user : this.getEntries()) {
46
			if (user.getUser() != null) {
47
				this.notificationService.playerRemovedFromAllowlist(user.getUser());
48
			}
49
		}
50
51
		super.clear();
52
	}
53
54
	@Override
55
	public String[] getUserList() {
56
		return this.getEntries().stream().map(StoredUserEntry::getUser).filter(Objects::nonNull).map(NameAndId::name).toArray(String[]::new);
57
	}
58
59
	protected String getKeyForUser(final NameAndId user) {
60
		return user.id().toString();
61
	}
62
}
63

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