Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.command.impl;
- import com.mojang.authlib.GameProfile;
- import com.mojang.brigadier.CommandDispatcher;
- import com.mojang.brigadier.builder.LiteralArgumentBuilder;
- import com.mojang.brigadier.builder.RequiredArgumentBuilder;
- import com.mojang.brigadier.exceptions.CommandSyntaxException;
- import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
- import java.util.Collection;
- import java.util.Date;
- import javax.annotation.Nullable;
- import net.minecraft.command.CommandSource;
- import net.minecraft.command.Commands;
- import net.minecraft.command.arguments.GameProfileArgument;
- import net.minecraft.command.arguments.MessageArgument;
- import net.minecraft.entity.player.EntityPlayerMP;
- import net.minecraft.server.management.UserListBans;
- import net.minecraft.server.management.UserListBansEntry;
- import net.minecraft.util.text.ITextComponent;
- import net.minecraft.util.text.TextComponentTranslation;
- import net.minecraft.util.text.TextComponentUtils;
- public class BanCommand {
- private static final SimpleCommandExceptionType field_198239_a = new SimpleCommandExceptionType(new TextComponentTranslation("commands.ban.failed", new Object[0]));
- public static void func_198235_a(CommandDispatcher<CommandSource> p_198235_0_) {
- p_198235_0_.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.func_197057_a("ban").requires((p_198238_0_) -> {
- return p_198238_0_.func_197028_i().getPlayerList().getBannedPlayers().isLanServer() && p_198238_0_.func_197034_c(3);
- })).then(((RequiredArgumentBuilder)Commands.func_197056_a("targets", GameProfileArgument.func_197108_a()).executes((p_198234_0_) -> {
- return func_198236_a((CommandSource)p_198234_0_.getSource(), GameProfileArgument.func_197109_a(p_198234_0_, "targets"), (ITextComponent)null);
- })).then(Commands.func_197056_a("reason", MessageArgument.func_197123_a()).executes((p_198237_0_) -> {
- return func_198236_a((CommandSource)p_198237_0_.getSource(), GameProfileArgument.func_197109_a(p_198237_0_, "targets"), MessageArgument.func_197124_a(p_198237_0_, "reason"));
- }))));
- }
- private static int func_198236_a(CommandSource p_198236_0_, Collection<GameProfile> p_198236_1_, @Nullable ITextComponent p_198236_2_) throws CommandSyntaxException {
- UserListBans userlistbans = p_198236_0_.func_197028_i().getPlayerList().getBannedPlayers();
- int i = 0;
- for(GameProfile gameprofile : p_198236_1_) {
- if (!userlistbans.isBanned(gameprofile)) {
- UserListBansEntry userlistbansentry = new UserListBansEntry(gameprofile, (Date)null, p_198236_0_.func_197037_c(), (Date)null, p_198236_2_ == null ? null : p_198236_2_.getString());
- userlistbans.addEntry(userlistbansentry);
- ++i;
- p_198236_0_.func_197030_a(new TextComponentTranslation("commands.ban.success", new Object[]{TextComponentUtils.func_197679_a(gameprofile), userlistbansentry.getBanReason()}), true);
- EntityPlayerMP entityplayermp = p_198236_0_.func_197028_i().getPlayerList().getPlayerByUUID(gameprofile.getId());
- if (entityplayermp != null) {
- entityplayermp.connection.disconnect(new TextComponentTranslation("multiplayer.disconnect.banned", new Object[0]));
- }
- }
- }
- if (i == 0) {
- throw field_198239_a.create();
- } else {
- return i;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement