BanListCommands .java

net.minecraft.server.commands.BanListCommands (class): members: register. strings: "commands.banlist.entry", "commands.banlist.list", "banlist", "players".

net.minecraft.server.commandsclass41 linesserver1.7 KB

API Surface (1)

void register(final CommandDispatcher<CommandSourceStack> dispatcher)

String literals (5)

"banlist"
"players"
"commands.banlist.none"
"commands.banlist.list"
"commands.banlist.entry"

Code Graph: Dependencies (5)

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

Full Source

BanListCommands.java41 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.commands;
2
3
import com.google.common.collect.Iterables;
4
import com.google.common.collect.Lists;
5
import com.mojang.brigadier.CommandDispatcher;
6
import java.util.Collection;
7
import net.minecraft.commands.CommandSourceStack;
8
import net.minecraft.commands.Commands;
9
import net.minecraft.network.chat.Component;
10
import net.minecraft.server.players.BanListEntry;
11
import net.minecraft.server.players.PlayerList;
12
13
public class BanListCommands {
14
	public static void register(final CommandDispatcher<CommandSourceStack> dispatcher) {
15
		dispatcher.register(
16
			Commands.literal("banlist")
17
				.requires(Commands.hasPermission(Commands.LEVEL_ADMINS))
18
				.executes(s -> {
19
					PlayerList players = s.getSource().getServer().getPlayerList();
20
					return showList(s.getSource(), Lists.newArrayList(Iterables.concat(players.getBans().getEntries(), players.getIpBans().getEntries())));
21
				})
22
				.then(Commands.literal("ips").executes(s -> showList(s.getSource(), s.getSource().getServer().getPlayerList().getIpBans().getEntries())))
23
				.then(Commands.literal("players").executes(s -> showList(s.getSource(), s.getSource().getServer().getPlayerList().getBans().getEntries())))
24
		);
25
	}
26
27
	private static int showList(final CommandSourceStack source, final Collection<? extends BanListEntry<?>> list) {
28
		if (list.isEmpty()) {
29
			source.sendSuccess(() -> Component.translatable("commands.banlist.none"), false);
30
		} else {
31
			source.sendSuccess(() -> Component.translatable("commands.banlist.list", list.size()), false);
32
33
			for (BanListEntry<?> entry : list) {
34
				source.sendSuccess(() -> Component.translatable("commands.banlist.entry", entry.getDisplayName(), entry.getSource(), entry.getReasonMessage()), false);
35
			}
36
		}
37
38
		return list.size();
39
	}
40
}
41

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