DeOpCommands.java
net.minecraft.server.commands.DeOpCommands
信息
- 全限定名:net.minecraft.server.commands.DeOpCommands
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/DeOpCommands.java
- 起始行号:L15
- 职责:
TODO
字段/常量
ERROR_NOT_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 deopPlayers(CommandSourceStack source, Collection<NameAndId> players) @ L30
- 方法名:deopPlayers
- 源码定位:L30
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- players: Collection
说明:
TODO
代码
public class DeOpCommands {
private static final SimpleCommandExceptionType ERROR_NOT_OP = new SimpleCommandExceptionType(Component.translatable("commands.deop.failed"));
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(
Commands.literal("deop")
.requires(Commands.hasPermission(Commands.LEVEL_ADMINS))
.then(
Commands.argument("targets", GameProfileArgument.gameProfile())
.suggests((c, p) -> SharedSuggestionProvider.suggest(c.getSource().getServer().getPlayerList().getOpNames(), p))
.executes(c -> deopPlayers(c.getSource(), GameProfileArgument.getGameProfiles(c, "targets")))
)
);
}
private static int deopPlayers(CommandSourceStack source, Collection<NameAndId> players) throws CommandSyntaxException {
PlayerList list = source.getServer().getPlayerList();
int count = 0;
for (NameAndId player : players) {
if (list.isOp(player)) {
list.deop(player);
count++;
source.sendSuccess(() -> Component.translatable("commands.deop.success", players.iterator().next().name()), true);
}
}
if (count == 0) {
throw ERROR_NOT_OP.create();
} else {
source.getServer().kickUnlistedPlayers();
return count;
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.hasPermission(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SharedSuggestionProvider.suggest()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
GameProfileArgument.gameProfile(), GameProfileArgument.getGameProfiles()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: