OpCommand.java
net.minecraft.server.commands.OpCommand
信息
- 全限定名:net.minecraft.server.commands.OpCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/OpCommand.java
- 起始行号:L15
- 职责:
TODO
字段/常量
ERROR_ALREADY_OP- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L16 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) @ L18
- 方法名:register
- 源码定位:L18
- 返回类型:void
- 修饰符:public static
参数:
- dispatcher: CommandDispatcher
说明:
TODO
private static int opPlayers(CommandSourceStack source, Collection<NameAndId> players) @ L37
- 方法名:opPlayers
- 源码定位:L37
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- players: Collection
说明:
TODO
代码
public class OpCommand {
private static final SimpleCommandExceptionType ERROR_ALREADY_OP = new SimpleCommandExceptionType(Component.translatable("commands.op.failed"));
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(
Commands.literal("op")
.requires(Commands.hasPermission(Commands.LEVEL_ADMINS))
.then(
Commands.argument("targets", GameProfileArgument.gameProfile())
.suggests(
(c, p) -> {
PlayerList list = c.getSource().getServer().getPlayerList();
return SharedSuggestionProvider.suggest(
list.getPlayers().stream().filter(player -> !list.isOp(player.nameAndId())).map(pl -> pl.getGameProfile().name()), p
);
}
)
.executes(c -> opPlayers(c.getSource(), GameProfileArgument.getGameProfiles(c, "targets")))
)
);
}
private static int opPlayers(CommandSourceStack source, Collection<NameAndId> players) throws CommandSyntaxException {
PlayerList list = source.getServer().getPlayerList();
int count = 0;
for (NameAndId player : players) {
if (!list.isOp(player)) {
list.op(player);
count++;
source.sendSuccess(() -> Component.translatable("commands.op.success", player.name()), true);
}
}
if (count == 0) {
throw ERROR_ALREADY_OP.create();
} else {
return count;
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.hasPermission(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SharedSuggestionProvider.suggest()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
GameProfileArgument.gameProfile(), GameProfileArgument.getGameProfiles()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: