ListPlayersCommand.java
net.minecraft.server.commands.ListPlayersCommand
信息
- 全限定名:net.minecraft.server.commands.ListPlayersCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/ListPlayersCommand.java
- 起始行号:L14
- 职责:
TODO
字段/常量
- 无
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) @ L15
- 方法名:register
- 源码定位:L15
- 返回类型:void
- 修饰符:public static
参数:
- dispatcher: CommandDispatcher
说明:
TODO
private static int listPlayers(CommandSourceStack source) @ L23
- 方法名:listPlayers
- 源码定位:L23
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
说明:
TODO
private static int listPlayersWithUuids(CommandSourceStack source) @ L27
- 方法名:listPlayersWithUuids
- 源码定位:L27
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
说明:
TODO
private static int format(CommandSourceStack source, Function<ServerPlayer,Component> formatter) @ L33
- 方法名:format
- 源码定位:L33
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- formatter: Function<ServerPlayer,Component>
说明:
TODO
代码
public class ListPlayersCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(
Commands.literal("list")
.executes(c -> listPlayers(c.getSource()))
.then(Commands.literal("uuids").executes(c -> listPlayersWithUuids(c.getSource())))
);
}
private static int listPlayers(CommandSourceStack source) {
return format(source, Player::getDisplayName);
}
private static int listPlayersWithUuids(CommandSourceStack source) {
return format(
source, player -> Component.translatable("commands.list.nameAndId", player.getName(), Component.translationArg(player.getGameProfile().id()))
);
}
private static int format(CommandSourceStack source, Function<ServerPlayer, Component> formatter) {
PlayerList playerList = source.getServer().getPlayerList();
List<ServerPlayer> players = playerList.getPlayers();
Component listComponent = ComponentUtils.formatList(players, formatter);
source.sendSuccess(() -> Component.translatable("commands.list.players", players.size(), playerList.getMaxPlayers(), listComponent), false);
return players.size();
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.literal()
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
Component.translatable(), Component.translationArg()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ComponentUtils.formatList()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: