Spaces:
Build error
Build error
File size: 2,393 Bytes
d46f4a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
package net.minecraft.server.commands;
import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import java.util.Collection;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.commands.arguments.GameProfileArgument;
import net.minecraft.network.chat.Component;
import net.minecraft.server.players.UserBanList;
public class PardonCommand {
private static final SimpleCommandExceptionType ERROR_NOT_BANNED = new SimpleCommandExceptionType(Component.translatable("commands.pardon.failed"));
public static void register(CommandDispatcher<CommandSourceStack> p_138094_) {
p_138094_.register(
Commands.literal("pardon")
.requires(p_138101_ -> p_138101_.hasPermission(3))
.then(
Commands.argument("targets", GameProfileArgument.gameProfile())
.suggests(
(p_138098_, p_138099_) -> SharedSuggestionProvider.suggest(
p_138098_.getSource().getServer().getPlayerList().getBans().getUserList(), p_138099_
)
)
.executes(p_138096_ -> pardonPlayers(p_138096_.getSource(), GameProfileArgument.getGameProfiles(p_138096_, "targets")))
)
);
}
private static int pardonPlayers(CommandSourceStack p_138103_, Collection<GameProfile> p_138104_) throws CommandSyntaxException {
UserBanList userbanlist = p_138103_.getServer().getPlayerList().getBans();
int i = 0;
for (GameProfile gameprofile : p_138104_) {
if (userbanlist.isBanned(gameprofile)) {
userbanlist.remove(gameprofile);
i++;
p_138103_.sendSuccess(() -> Component.translatable("commands.pardon.success", Component.literal(gameprofile.getName())), true);
}
}
if (i == 0) {
throw ERROR_NOT_BANNED.create();
} else {
return i;
}
}
} |