PardonIpCommand.java
net.minecraft.server.commands.PardonIpCommand
信息
- 全限定名:net.minecraft.server.commands.PardonIpCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/PardonIpCommand.java
- 起始行号:L14
- 职责:
TODO
字段/常量
-
ERROR_INVALID- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
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 unban(CommandSourceStack source, String ip) @ L30
- 方法名:unban
- 源码定位:L30
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- ip: String
说明:
TODO
代码
public class PardonIpCommand {
private static final SimpleCommandExceptionType ERROR_INVALID = new SimpleCommandExceptionType(Component.translatable("commands.pardonip.invalid"));
private static final SimpleCommandExceptionType ERROR_NOT_BANNED = new SimpleCommandExceptionType(Component.translatable("commands.pardonip.failed"));
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(
Commands.literal("pardon-ip")
.requires(Commands.hasPermission(Commands.LEVEL_ADMINS))
.then(
Commands.argument("target", StringArgumentType.word())
.suggests((c, p) -> SharedSuggestionProvider.suggest(c.getSource().getServer().getPlayerList().getIpBans().getUserList(), p))
.executes(c -> unban(c.getSource(), StringArgumentType.getString(c, "target")))
)
);
}
private static int unban(CommandSourceStack source, String ip) throws CommandSyntaxException {
if (!InetAddresses.isInetAddress(ip)) {
throw ERROR_INVALID.create();
} else {
IpBanList bans = source.getServer().getPlayerList().getIpBans();
if (!bans.isBanned(ip)) {
throw ERROR_NOT_BANNED.create();
} else {
bans.remove(ip);
source.sendSuccess(() -> Component.translatable("commands.pardonip.success", ip), true);
return 1;
}
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.hasPermission(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SharedSuggestionProvider.suggest()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable()
- 引用位置: