| 1 | package net.minecraft.command.server;
|
| 2 |
|
| 3 | import com.mojang.authlib.GameProfile;
|
| 4 | import java.util.Date;
|
| 5 | import java.util.List;
|
| 6 | import net.minecraft.command.CommandBase;
|
| 7 | import net.minecraft.command.CommandException;
|
| 8 | import net.minecraft.command.ICommandSender;
|
| 9 | import net.minecraft.command.WrongUsageException;
|
| 10 | import net.minecraft.entity.player.EntityPlayerMP;
|
| 11 | import net.minecraft.server.MinecraftServer;
|
| 12 | import net.minecraft.server.management.UserListBansEntry;
|
| 13 | import net.minecraft.util.BlockPos;
|
| 14 |
|
| 15 | public class CommandBanPlayer extends CommandBase
|
| 16 | {
|
| 17 | /**
|
| 18 | * Gets the name of the command
|
| 19 | */
|
| 20 | public String getCommandName()
|
| 21 | {
|
| 22 | return "ban";
|
| 23 | }
|
| 24 |
|
| 25 | /**
|
| 26 | * Return the required permission level for this command.
|
| 27 | */
|
| 28 | public int getRequiredPermissionLevel()
|
| 29 | {
|
| 30 | return 3;
|
| 31 | }
|
| 32 |
|
| 33 | /**
|
| 34 | * Gets the usage string for the command.
|
| 35 | */
|
| 36 | public String getCommandUsage(ICommandSender sender)
|
| 37 | {
|
| 38 | return "commands.ban.usage";
|
| 39 | }
|
| 40 |
|
| 41 | /**
|
| 42 | * Returns true if the given command sender is allowed to use this command.
|
| 43 | */
|
| 44 | public boolean canCommandSenderUseCommand(ICommandSender sender)
|
| 45 | {
|
| 46 | return MinecraftServer.getServer().getConfigurationManager().getBannedPlayers().isLanServer() && super.canCommandSenderUseCommand(sender);
|
| 47 | }
|
| 48 |
|
| 49 | /**
|
| 50 | * Callback when the command is invoked
|
| 51 | */
|
| 52 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 53 | {
|
| 54 | if (args.length >= 1 && args[0].length() > 0)
|
| 55 | {
|
| 56 | MinecraftServer minecraftserver = MinecraftServer.getServer();
|
| 57 | GameProfile gameprofile = minecraftserver.getPlayerProfileCache().getGameProfileForUsername(args[0]);
|
| 58 |
|
| 59 | if (gameprofile == null)
|
| 60 | {
|
| 61 | throw new CommandException("commands.ban.failed", new Object[] {args[0]});
|
| 62 | }
|
| 63 | else
|
| 64 | {
|
| 65 | String s = null;
|
| 66 |
|
| 67 | if (args.length >= 2)
|
| 68 | {
|
| 69 | s = getChatComponentFromNthArg(sender, args, 1).getUnformattedText();
|
| 70 | }
|
| 71 |
|
| 72 | UserListBansEntry userlistbansentry = new UserListBansEntry(gameprofile, (Date)null, sender.getName(), (Date)null, s);
|
| 73 | minecraftserver.getConfigurationManager().getBannedPlayers().addEntry(userlistbansentry);
|
| 74 | EntityPlayerMP entityplayermp = minecraftserver.getConfigurationManager().getPlayerByUsername(args[0]);
|
| 75 |
|
| 76 | if (entityplayermp != null)
|
| 77 | {
|
| 78 | entityplayermp.playerNetServerHandler.kickPlayerFromServer("You are banned from this server.");
|
| 79 | }
|
| 80 |
|
| 81 | notifyOperators(sender, this, "commands.ban.success", new Object[] {args[0]});
|
| 82 | }
|
| 83 | }
|
| 84 | else
|
| 85 | {
|
| 86 | throw new WrongUsageException("commands.ban.usage", new Object[0]);
|
| 87 | }
|
| 88 | }
|
| 89 |
|
| 90 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 91 | {
|
| 92 | return args.length >= 1 ? getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames()) : null;
|
| 93 | }
|
| 94 | }
|
| 95 |
|