IpBanList .java

net.minecraft.server.players.IpBanList (class, 78 lines): members: isBanned, createEntry, clear, remove, add, get. imports: NotificationService, Nullable.

net.minecraft.server.playersclass78 linesserverextends StoredUserList<String1.7 KB

API Surface (6)

StoredUserEntry<String> createEntry(final JsonObject object)
boolean isBanned(final SocketAddress address)
boolean isBanned(final String ip)
boolean add(final IpBanListEntry infos)
boolean remove(final String ip)
void clear()

Code Graph: Dependencies (4)

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

Full Source

IpBanList.java78 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.net.SocketAddress;
6
import net.minecraft.server.notifications.NotificationService;
7
import org.jspecify.annotations.Nullable;
8
9
public class IpBanList extends StoredUserList<String, IpBanListEntry> {
10
	public IpBanList(final File file, final NotificationService notificationService) {
11
		super(file, notificationService);
12
	}
13
14
	@Override
15
	protected StoredUserEntry<String> createEntry(final JsonObject object) {
16
		return new IpBanListEntry(object);
17
	}
18
19
	public boolean isBanned(final SocketAddress address) {
20
		String ip = this.getIpFromAddress(address);
21
		return this.contains(ip);
22
	}
23
24
	public boolean isBanned(final String ip) {
25
		return this.contains(ip);
26
	}
27
28
	public @Nullable IpBanListEntry get(final SocketAddress address) {
29
		String ip = this.getIpFromAddress(address);
30
		return this.get(ip);
31
	}
32
33
	private String getIpFromAddress(final SocketAddress address) {
34
		String ip = address.toString();
35
		if (ip.contains("/")) {
36
			ip = ip.substring(ip.indexOf(47) + 1);
37
		}
38
39
		if (ip.contains(":")) {
40
			ip = ip.substring(0, ip.indexOf(58));
41
		}
42
43
		return ip;
44
	}
45
46
	public boolean add(final IpBanListEntry infos) {
47
		if (super.add(infos)) {
48
			if (infos.getUser() != null) {
49
				this.notificationService.ipBanned(infos);
50
			}
51
52
			return true;
53
		} else {
54
			return false;
55
		}
56
	}
57
58
	public boolean remove(final String ip) {
59
		if (super.remove(ip)) {
60
			this.notificationService.ipUnbanned(ip);
61
			return true;
62
		} else {
63
			return false;
64
		}
65
	}
66
67
	@Override
68
	public void clear() {
69
		for (IpBanListEntry user : this.getEntries()) {
70
			if (user.getUser() != null) {
71
				this.notificationService.ipUnbanned(user.getUser());
72
			}
73
		}
74
75
		super.clear();
76
	}
77
}
78

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