PardonIpCommand .java

net.minecraft.server.commands.PardonIpCommand (class): members: ERROR_NOT_BANNED, ERROR_INVALID, register. strings: "commands.pardonip.invalid", "target".

net.minecraft.server.commandsclass45 linesserver1.8 KB

API Surface (1)

void register(final CommandDispatcher<CommandSourceStack> dispatcher)

Fields & Constants (2)

ERROR_INVALID
ERROR_NOT_BANNED

String literals (5)

"commands.pardonip.invalid"
"commands.pardonip.failed"
"pardon-ip"
"target"
"commands.pardonip.success"

Code Graph: Dependencies (5)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

PardonIpCommand.java45 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.commands;
2
3
import com.google.common.net.InetAddresses;
4
import com.mojang.brigadier.CommandDispatcher;
5
import com.mojang.brigadier.arguments.StringArgumentType;
6
import com.mojang.brigadier.exceptions.CommandSyntaxException;
7
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
8
import net.minecraft.commands.CommandSourceStack;
9
import net.minecraft.commands.Commands;
10
import net.minecraft.commands.SharedSuggestionProvider;
11
import net.minecraft.network.chat.Component;
12
import net.minecraft.server.players.IpBanList;
13
14
public class PardonIpCommand {
15
	private static final SimpleCommandExceptionType ERROR_INVALID = new SimpleCommandExceptionType(Component.translatable("commands.pardonip.invalid"));
16
	private static final SimpleCommandExceptionType ERROR_NOT_BANNED = new SimpleCommandExceptionType(Component.translatable("commands.pardonip.failed"));
17
18
	public static void register(final CommandDispatcher<CommandSourceStack> dispatcher) {
19
		dispatcher.register(
20
			Commands.literal("pardon-ip")
21
				.requires(Commands.hasPermission(Commands.LEVEL_ADMINS))
22
				.then(
23
					Commands.argument("target", StringArgumentType.word())
24
						.suggests((c, p) -> SharedSuggestionProvider.suggest(c.getSource().getServer().getPlayerList().getIpBans().getUserList(), p))
25
						.executes(c -> unban(c.getSource(), StringArgumentType.getString(c, "target")))
26
				)
27
		);
28
	}
29
30
	private static int unban(final CommandSourceStack source, final String ip) throws CommandSyntaxException {
31
		if (!InetAddresses.isInetAddress(ip)) {
32
			throw ERROR_INVALID.create();
33
		}
34
35
		IpBanList bans = source.getServer().getPlayerList().getIpBans();
36
		if (!bans.isBanned(ip)) {
37
			throw ERROR_NOT_BANNED.create();
38
		}
39
40
		bans.remove(ip);
41
		source.sendSuccess(() -> Component.translatable("commands.pardonip.success", ip), true);
42
		return 1;
43
	}
44
}
45

Decompiled Minecraft 26.3 source of PardonIpCommand (net/minecraft/server/commands/PardonIpCommand.java) with Mojang official mappings, stored verbatim on the site.