Advertisement
Superloup10

Untitled

Sep 10th, 2018
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.38 KB | None | 0 0
  1. package net.minecraft.command.impl;
  2.  
  3. import com.mojang.authlib.GameProfile;
  4. import com.mojang.brigadier.CommandDispatcher;
  5. import com.mojang.brigadier.builder.LiteralArgumentBuilder;
  6. import com.mojang.brigadier.builder.RequiredArgumentBuilder;
  7. import com.mojang.brigadier.exceptions.CommandSyntaxException;
  8. import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
  9. import java.util.Collection;
  10. import java.util.Date;
  11. import javax.annotation.Nullable;
  12. import net.minecraft.command.CommandSource;
  13. import net.minecraft.command.Commands;
  14. import net.minecraft.command.arguments.GameProfileArgument;
  15. import net.minecraft.command.arguments.MessageArgument;
  16. import net.minecraft.entity.player.EntityPlayerMP;
  17. import net.minecraft.server.management.UserListBans;
  18. import net.minecraft.server.management.UserListBansEntry;
  19. import net.minecraft.util.text.ITextComponent;
  20. import net.minecraft.util.text.TextComponentTranslation;
  21. import net.minecraft.util.text.TextComponentUtils;
  22.  
  23. public class BanCommand {
  24.    private static final SimpleCommandExceptionType field_198239_a = new SimpleCommandExceptionType(new TextComponentTranslation("commands.ban.failed", new Object[0]));
  25.  
  26.    public static void func_198235_a(CommandDispatcher<CommandSource> p_198235_0_) {
  27.       p_198235_0_.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.func_197057_a("ban").requires((p_198238_0_) -> {
  28.          return p_198238_0_.func_197028_i().getPlayerList().getBannedPlayers().isLanServer() && p_198238_0_.func_197034_c(3);
  29.       })).then(((RequiredArgumentBuilder)Commands.func_197056_a("targets", GameProfileArgument.func_197108_a()).executes((p_198234_0_) -> {
  30.          return func_198236_a((CommandSource)p_198234_0_.getSource(), GameProfileArgument.func_197109_a(p_198234_0_, "targets"), (ITextComponent)null);
  31.       })).then(Commands.func_197056_a("reason", MessageArgument.func_197123_a()).executes((p_198237_0_) -> {
  32.          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"));
  33.       }))));
  34.    }
  35.  
  36.    private static int func_198236_a(CommandSource p_198236_0_, Collection<GameProfile> p_198236_1_, @Nullable ITextComponent p_198236_2_) throws CommandSyntaxException {
  37.       UserListBans userlistbans = p_198236_0_.func_197028_i().getPlayerList().getBannedPlayers();
  38.       int i = 0;
  39.  
  40.       for(GameProfile gameprofile : p_198236_1_) {
  41.          if (!userlistbans.isBanned(gameprofile)) {
  42.             UserListBansEntry userlistbansentry = new UserListBansEntry(gameprofile, (Date)null, p_198236_0_.func_197037_c(), (Date)null, p_198236_2_ == null ? null : p_198236_2_.getString());
  43.             userlistbans.addEntry(userlistbansentry);
  44.             ++i;
  45.             p_198236_0_.func_197030_a(new TextComponentTranslation("commands.ban.success", new Object[]{TextComponentUtils.func_197679_a(gameprofile), userlistbansentry.getBanReason()}), true);
  46.             EntityPlayerMP entityplayermp = p_198236_0_.func_197028_i().getPlayerList().getPlayerByUUID(gameprofile.getId());
  47.             if (entityplayermp != null) {
  48.                entityplayermp.connection.disconnect(new TextComponentTranslation("multiplayer.disconnect.banned", new Object[0]));
  49.             }
  50.          }
  51.       }
  52.  
  53.       if (i == 0) {
  54.          throw field_198239_a.create();
  55.       } else {
  56.          return i;
  57.       }
  58.    }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement