| 1 | package net.minecraft.command.server;
|
| 2 |
|
| 3 | import com.mojang.authlib.GameProfile;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.command.CommandBase;
|
| 6 | import net.minecraft.command.CommandException;
|
| 7 | import net.minecraft.command.ICommandSender;
|
| 8 | import net.minecraft.command.WrongUsageException;
|
| 9 | import net.minecraft.server.MinecraftServer;
|
| 10 | import net.minecraft.util.BlockPos;
|
| 11 | import net.minecraft.util.ChatComponentText;
|
| 12 | import net.minecraft.util.ChatComponentTranslation;
|
| 13 |
|
| 14 | public class CommandWhitelist extends CommandBase
|
| 15 | {
|
| 16 | /**
|
| 17 | * Gets the name of the command
|
| 18 | */
|
| 19 | public String getCommandName()
|
| 20 | {
|
| 21 | return "whitelist";
|
| 22 | }
|
| 23 |
|
| 24 | /**
|
| 25 | * Return the required permission level for this command.
|
| 26 | */
|
| 27 | public int getRequiredPermissionLevel()
|
| 28 | {
|
| 29 | return 3;
|
| 30 | }
|
| 31 |
|
| 32 | /**
|
| 33 | * Gets the usage string for the command.
|
| 34 | */
|
| 35 | public String getCommandUsage(ICommandSender sender)
|
| 36 | {
|
| 37 | return "commands.whitelist.usage";
|
| 38 | }
|
| 39 |
|
| 40 | /**
|
| 41 | * Callback when the command is invoked
|
| 42 | */
|
| 43 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 44 | {
|
| 45 | if (args.length < 1)
|
| 46 | {
|
| 47 | throw new WrongUsageException("commands.whitelist.usage", new Object[0]);
|
| 48 | }
|
| 49 | else
|
| 50 | {
|
| 51 | MinecraftServer minecraftserver = MinecraftServer.getServer();
|
| 52 |
|
| 53 | if (args[0].equals("on"))
|
| 54 | {
|
| 55 | minecraftserver.getConfigurationManager().setWhiteListEnabled(true);
|
| 56 | notifyOperators(sender, this, "commands.whitelist.enabled", new Object[0]);
|
| 57 | }
|
| 58 | else if (args[0].equals("off"))
|
| 59 | {
|
| 60 | minecraftserver.getConfigurationManager().setWhiteListEnabled(false);
|
| 61 | notifyOperators(sender, this, "commands.whitelist.disabled", new Object[0]);
|
| 62 | }
|
| 63 | else if (args[0].equals("list"))
|
| 64 | {
|
| 65 | sender.addChatMessage(new ChatComponentTranslation("commands.whitelist.list", new Object[] {Integer.valueOf(minecraftserver.getConfigurationManager().getWhitelistedPlayerNames().length), Integer.valueOf(minecraftserver.getConfigurationManager().getAvailablePlayerDat().length)}));
|
| 66 | String[] astring = minecraftserver.getConfigurationManager().getWhitelistedPlayerNames();
|
| 67 | sender.addChatMessage(new ChatComponentText(joinNiceString(astring)));
|
| 68 | }
|
| 69 | else if (args[0].equals("add"))
|
| 70 | {
|
| 71 | if (args.length < 2)
|
| 72 | {
|
| 73 | throw new WrongUsageException("commands.whitelist.add.usage", new Object[0]);
|
| 74 | }
|
| 75 |
|
| 76 | GameProfile gameprofile = minecraftserver.getPlayerProfileCache().getGameProfileForUsername(args[1]);
|
| 77 |
|
| 78 | if (gameprofile == null)
|
| 79 | {
|
| 80 | throw new CommandException("commands.whitelist.add.failed", new Object[] {args[1]});
|
| 81 | }
|
| 82 |
|
| 83 | minecraftserver.getConfigurationManager().addWhitelistedPlayer(gameprofile);
|
| 84 | notifyOperators(sender, this, "commands.whitelist.add.success", new Object[] {args[1]});
|
| 85 | }
|
| 86 | else if (args[0].equals("remove"))
|
| 87 | {
|
| 88 | if (args.length < 2)
|
| 89 | {
|
| 90 | throw new WrongUsageException("commands.whitelist.remove.usage", new Object[0]);
|
| 91 | }
|
| 92 |
|
| 93 | GameProfile gameprofile1 = minecraftserver.getConfigurationManager().getWhitelistedPlayers().getBannedProfile(args[1]);
|
| 94 |
|
| 95 | if (gameprofile1 == null)
|
| 96 | {
|
| 97 | throw new CommandException("commands.whitelist.remove.failed", new Object[] {args[1]});
|
| 98 | }
|
| 99 |
|
| 100 | minecraftserver.getConfigurationManager().removePlayerFromWhitelist(gameprofile1);
|
| 101 | notifyOperators(sender, this, "commands.whitelist.remove.success", new Object[] {args[1]});
|
| 102 | }
|
| 103 | else if (args[0].equals("reload"))
|
| 104 | {
|
| 105 | minecraftserver.getConfigurationManager().loadWhiteList();
|
| 106 | notifyOperators(sender, this, "commands.whitelist.reloaded", new Object[0]);
|
| 107 | }
|
| 108 | }
|
| 109 | }
|
| 110 |
|
| 111 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 112 | {
|
| 113 | if (args.length == 1)
|
| 114 | {
|
| 115 | return getListOfStringsMatchingLastWord(args, new String[] {"on", "off", "list", "add", "remove", "reload"});
|
| 116 | }
|
| 117 | else
|
| 118 | {
|
| 119 | if (args.length == 2)
|
| 120 | {
|
| 121 | if (args[0].equals("remove"))
|
| 122 | {
|
| 123 | return getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getConfigurationManager().getWhitelistedPlayerNames());
|
| 124 | }
|
| 125 |
|
| 126 | if (args[0].equals("add"))
|
| 127 | {
|
| 128 | return getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getPlayerProfileCache().getUsernames());
|
| 129 | }
|
| 130 | }
|
| 131 |
|
| 132 | return null;
|
| 133 | }
|
| 134 | }
|
| 135 | }
|
| 136 |
|