| 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 |
|