BanListCommands.java

net.minecraft.server.commands.BanListCommands

信息

  • 全限定名:net.minecraft.server.commands.BanListCommands
  • 类型:public class
  • 包:net.minecraft.server.commands
  • 源码路径:src/main/java/net/minecraft/server/commands/BanListCommands.java
  • 起始行号:L13
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

构造器

方法

下面的方法块按源码顺序生成。

public static void register(CommandDispatcher<CommandSourceStack> dispatcher) @ L14

  • 方法名:register
  • 源码定位:L14
  • 返回类型:void
  • 修饰符:public static

参数:

  • dispatcher: CommandDispatcher

说明:

TODO

private static int showList(CommandSourceStack source, Collection<?extends BanListEntry<?>> list) @ L27

  • 方法名:showList
  • 源码定位:L27
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • list: Collection>

说明:

TODO

代码

public class BanListCommands {
    public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
        dispatcher.register(
            Commands.literal("banlist")
                .requires(Commands.hasPermission(Commands.LEVEL_ADMINS))
                .executes(s -> {
                    PlayerList players = s.getSource().getServer().getPlayerList();
                    return showList(s.getSource(), Lists.newArrayList(Iterables.concat(players.getBans().getEntries(), players.getIpBans().getEntries())));
                })
                .then(Commands.literal("ips").executes(s -> showList(s.getSource(), s.getSource().getServer().getPlayerList().getIpBans().getEntries())))
                .then(Commands.literal("players").executes(s -> showList(s.getSource(), s.getSource().getServer().getPlayerList().getBans().getEntries())))
        );
    }
 
    private static int showList(CommandSourceStack source, Collection<? extends BanListEntry<?>> list) {
        if (list.isEmpty()) {
            source.sendSuccess(() -> Component.translatable("commands.banlist.none"), false);
        } else {
            source.sendSuccess(() -> Component.translatable("commands.banlist.list", list.size()), false);
 
            for (BanListEntry<?> entry : list) {
                source.sendSuccess(
                    () -> Component.translatable("commands.banlist.entry", entry.getDisplayName(), entry.getSource(), entry.getReasonMessage()), false
                );
            }
        }
 
        return list.size();
    }
}

引用的其他类

  • CommandSourceStack

    • 引用位置: 参数
  • Commands

    • 引用位置: 方法调用
    • 关联成员: Commands.hasPermission(), Commands.literal()
  • Component

    • 引用位置: 方法调用
    • 关联成员: Component.translatable()
  • BanListEntry

    • 引用位置: 参数