UserBanList .java

net.minecraft.server.players.UserBanList (class): members: isBanned, getKeyForUser, getUserList, createEntry, clear, remove, add. imports: JsonObject.

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

API Surface (7)

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

Code Graph: Dependencies (5)

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

Full Source

UserBanList.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 UserBanList extends StoredUserList<NameAndId, UserBanListEntry> {
9
	public UserBanList(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 UserBanListEntry(object);
16
	}
17
18
	public boolean isBanned(final NameAndId user) {
19
		return this.contains(user);
20
	}
21
22
	@Override
23
	public String[] getUserList() {
24
		return this.getEntries().stream().map(StoredUserEntry::getUser).filter(Objects::nonNull).map(NameAndId::name).toArray(String[]::new);
25
	}
26
27
	protected String getKeyForUser(final NameAndId user) {
28
		return user.id().toString();
29
	}
30
31
	public boolean add(final UserBanListEntry infos) {
32
		if (super.add(infos)) {
33
			if (infos.getUser() != null) {
34
				this.notificationService.playerBanned(infos);
35
			}
36
37
			return true;
38
		} else {
39
			return false;
40
		}
41
	}
42
43
	public boolean remove(final NameAndId user) {
44
		if (super.remove(user)) {
45
			this.notificationService.playerUnbanned(user);
46
			return true;
47
		} else {
48
			return false;
49
		}
50
	}
51
52
	@Override
53
	public void clear() {
54
		for (UserBanListEntry user : this.getEntries()) {
55
			if (user.getUser() != null) {
56
				this.notificationService.playerUnbanned(user.getUser());
57
			}
58
		}
59
60
		super.clear();
61
	}
62
}
63

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