Advertisement
Superloup10

Untitled

Sep 10th, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.31 KB | None | 0 0
  1. package net.minecraft.command.server;
  2.  
  3. import com.mojang.authlib.GameProfile;
  4. import java.util.Collections;
  5. import java.util.Date;
  6. import java.util.List;
  7. import javax.annotation.Nullable;
  8. import net.minecraft.command.CommandBase;
  9. import net.minecraft.command.CommandException;
  10. import net.minecraft.command.ICommandSender;
  11. import net.minecraft.command.WrongUsageException;
  12. import net.minecraft.entity.player.EntityPlayerMP;
  13. import net.minecraft.server.MinecraftServer;
  14. import net.minecraft.server.management.UserListBansEntry;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraft.util.text.TextComponentTranslation;
  17.  
  18. public class CommandBanPlayer extends CommandBase
  19. {
  20.     /**
  21.      * Gets the name of the command
  22.      */
  23.     public String getName()
  24.     {
  25.         return "ban";
  26.     }
  27.  
  28.     /**
  29.      * Return the required permission level for this command.
  30.      */
  31.     public int getRequiredPermissionLevel()
  32.     {
  33.         return 3;
  34.     }
  35.  
  36.     /**
  37.      * Gets the usage string for the command.
  38.      */
  39.     public String getUsage(ICommandSender sender)
  40.     {
  41.         return "commands.ban.usage";
  42.     }
  43.  
  44.     /**
  45.      * Check if the given ICommandSender has permission to execute this command
  46.      */
  47.     public boolean checkPermission(MinecraftServer server, ICommandSender sender)
  48.     {
  49.         return server.getPlayerList().getBannedPlayers().isLanServer() && super.checkPermission(server, sender);
  50.     }
  51.  
  52.     /**
  53.      * Callback for when the command is executed
  54.      */
  55.     public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
  56.     {
  57.         if (args.length >= 1 && args[0].length() > 0)
  58.         {
  59.             GameProfile gameprofile = server.getPlayerProfileCache().getGameProfileForUsername(args[0]);
  60.  
  61.             if (gameprofile == null)
  62.             {
  63.                 throw new CommandException("commands.ban.failed", new Object[] {args[0]});
  64.             }
  65.             else
  66.             {
  67.                 String s = null;
  68.  
  69.                 if (args.length >= 2)
  70.                 {
  71.                     s = getChatComponentFromNthArg(sender, args, 1).getUnformattedText();
  72.                 }
  73.  
  74.                 UserListBansEntry userlistbansentry = new UserListBansEntry(gameprofile, (Date)null, sender.getName(), (Date)null, s);
  75.                 server.getPlayerList().getBannedPlayers().addEntry(userlistbansentry);
  76.                 EntityPlayerMP entityplayermp = server.getPlayerList().getPlayerByUsername(args[0]);
  77.  
  78.                 if (entityplayermp != null)
  79.                 {
  80.                     entityplayermp.connection.disconnect(new TextComponentTranslation("multiplayer.disconnect.banned", new Object[0]));
  81.                 }
  82.  
  83.                 notifyCommandListener(sender, this, "commands.ban.success", new Object[] {args[0]});
  84.             }
  85.         }
  86.         else
  87.         {
  88.             throw new WrongUsageException("commands.ban.usage", new Object[0]);
  89.         }
  90.     }
  91.  
  92.     /**
  93.      * Get a list of options for when the user presses the TAB key
  94.      */
  95.     public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos)
  96.     {
  97.         return args.length >= 1 ? getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()) : Collections.emptyList();
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement