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