| 1 | package net.minecraft.command;
|
| 2 |
|
| 3 | import java.util.Arrays;
|
| 4 | import java.util.Collections;
|
| 5 | import java.util.List;
|
| 6 | import java.util.Map;
|
| 7 | import java.util.Set;
|
| 8 | import net.minecraft.entity.player.EntityPlayer;
|
| 9 | import net.minecraft.event.ClickEvent;
|
| 10 | import net.minecraft.server.MinecraftServer;
|
| 11 | import net.minecraft.util.BlockPos;
|
| 12 | import net.minecraft.util.ChatComponentTranslation;
|
| 13 | import net.minecraft.util.EnumChatFormatting;
|
| 14 | import net.minecraft.util.MathHelper;
|
| 15 |
|
| 16 | public class CommandHelp extends CommandBase
|
| 17 | {
|
| 18 | /**
|
| 19 | * Gets the name of the command
|
| 20 | */
|
| 21 | public String getCommandName()
|
| 22 | {
|
| 23 | return "help";
|
| 24 | }
|
| 25 |
|
| 26 | /**
|
| 27 | * Return the required permission level for this command.
|
| 28 | */
|
| 29 | public int getRequiredPermissionLevel()
|
| 30 | {
|
| 31 | return 0;
|
| 32 | }
|
| 33 |
|
| 34 | /**
|
| 35 | * Gets the usage string for the command.
|
| 36 | */
|
| 37 | public String getCommandUsage(ICommandSender sender)
|
| 38 | {
|
| 39 | return "commands.help.usage";
|
| 40 | }
|
| 41 |
|
| 42 | public List<String> getCommandAliases()
|
| 43 | {
|
| 44 | return Arrays.<String>asList(new String[] {"?"});
|
| 45 | }
|
| 46 |
|
| 47 | /**
|
| 48 | * Callback when the command is invoked
|
| 49 | */
|
| 50 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 51 | {
|
| 52 | List<ICommand> list = this.getSortedPossibleCommands(sender);
|
| 53 | int i = 7;
|
| 54 | int j = (list.size() - 1) / 7;
|
| 55 | int k = 0;
|
| 56 |
|
| 57 | try
|
| 58 | {
|
| 59 | k = args.length == 0 ? 0 : parseInt(args[0], 1, j + 1) - 1;
|
| 60 | }
|
| 61 | catch (NumberInvalidException numberinvalidexception)
|
| 62 | {
|
| 63 | Map<String, ICommand> map = this.getCommands();
|
| 64 | ICommand icommand = (ICommand)map.get(args[0]);
|
| 65 |
|
| 66 | if (icommand != null)
|
| 67 | {
|
| 68 | throw new WrongUsageException(icommand.getCommandUsage(sender), new Object[0]);
|
| 69 | }
|
| 70 |
|
| 71 | if (MathHelper.parseIntWithDefault(args[0], -1) != -1)
|
| 72 | {
|
| 73 | throw numberinvalidexception;
|
| 74 | }
|
| 75 |
|
| 76 | throw new CommandNotFoundException();
|
| 77 | }
|
| 78 |
|
| 79 | int l = Math.min((k + 1) * 7, list.size());
|
| 80 | ChatComponentTranslation chatcomponenttranslation1 = new ChatComponentTranslation("commands.help.header", new Object[] {Integer.valueOf(k + 1), Integer.valueOf(j + 1)});
|
| 81 | chatcomponenttranslation1.getChatStyle().setColor(EnumChatFormatting.DARK_GREEN);
|
| 82 | sender.addChatMessage(chatcomponenttranslation1);
|
| 83 |
|
| 84 | for (int i1 = k * 7; i1 < l; ++i1)
|
| 85 | {
|
| 86 | ICommand icommand1 = (ICommand)list.get(i1);
|
| 87 | ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation(icommand1.getCommandUsage(sender), new Object[0]);
|
| 88 | chatcomponenttranslation.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + icommand1.getCommandName() + " "));
|
| 89 | sender.addChatMessage(chatcomponenttranslation);
|
| 90 | }
|
| 91 |
|
| 92 | if (k == 0 && sender instanceof EntityPlayer)
|
| 93 | {
|
| 94 | ChatComponentTranslation chatcomponenttranslation2 = new ChatComponentTranslation("commands.help.footer", new Object[0]);
|
| 95 | chatcomponenttranslation2.getChatStyle().setColor(EnumChatFormatting.GREEN);
|
| 96 | sender.addChatMessage(chatcomponenttranslation2);
|
| 97 | }
|
| 98 | }
|
| 99 |
|
| 100 | protected List<ICommand> getSortedPossibleCommands(ICommandSender p_71534_1_)
|
| 101 | {
|
| 102 | List<ICommand> list = MinecraftServer.getServer().getCommandManager().getPossibleCommands(p_71534_1_);
|
| 103 | Collections.sort(list);
|
| 104 | return list;
|
| 105 | }
|
| 106 |
|
| 107 | protected Map<String, ICommand> getCommands()
|
| 108 | {
|
| 109 | return MinecraftServer.getServer().getCommandManager().getCommands();
|
| 110 | }
|
| 111 |
|
| 112 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 113 | {
|
| 114 | if (args.length == 1)
|
| 115 | {
|
| 116 | Set<String> set = this.getCommands().keySet();
|
| 117 | return getListOfStringsMatchingLastWord(args, (String[])set.toArray(new String[set.size()]));
|
| 118 | }
|
| 119 | else
|
| 120 | {
|
| 121 | return null;
|
| 122 | }
|
| 123 | }
|
| 124 | }
|
| 125 |
|