Uploaded image for project: 'Minecraft'
  1. Minecraft
  2. MC-99814

help -1 throws unknown command exception

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: Minecraft 1.9.1 Pre-Release 3, Minecraft 1.9.1, Minecraft 1.9.2
    • Fix Version/s: Minecraft 16w41a
    • Labels:
    • Confirmation Status:
      Community Consensus

      Description

      The bug

      Using the /help command with -1 as page prints the unknown command error. However using anyother invalid number like -2 or 15 (in 1.9.1-pre3 too high) prints an invalid number error.

      How to reproduce

      1. Use the following command
        /help -2
        

        It will print an error stating that the number is too low

      2. Use the following command
        /help -1
        

        It will print that the command is unknown

      The reason

      The following is based on decompiled version of Minecraft 1.9 using MCP 9.24 beta. All method and class names are the names used in the decompiled version.

      The reason why this happens is because the method net.minecraft.command.CommandHelp.execute(MinecraftServer, ICommandSender, String[]) first calls a method that parses the number and tests if it is in a specified range. If this method throws a NumberInvalidException it then uses a method which tries to parse a number and if it fails uses a given number (in this case -1). This is done to differentiate between commands and indexes. The problem with this is, that is treats -1 as command then.

      /**
       * Callback for when the command is executed
       *  
       * @param server The Minecraft server instance
       * @param sender The source of the command invocation
       * @param args The arguments that were passed
       */
      public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
      {
          if (sender instanceof CommandBlockBaseLogic)
          {
              sender.addChatMessage((new TextComponentString("Searge says: ")).appendText(seargeSays[this.rand.nextInt(seargeSays.length) % seargeSays.length]));
          }
          else
          {
              List<ICommand> list = this.func_184900_a(sender, server);
              int i = 7;
              int j = (list.size() - 1) / 7;
              int k = 0;
      
              // Replaced this
              //try
              //{
              //    k = args.length == 0 ? 0 : parseInt(args[0], 1, j + 1) - 1;
              //}
              //catch (NumberInvalidException numberinvalidexception)
              //{
              //    Map<String, ICommand> map = this.func_184899_a(server);
              //    ICommand icommand = (ICommand)map.get(args[0]);
              //
              //    if (icommand != null)
              //    {
              //        throw new WrongUsageException(icommand.getCommandUsage(sender), new Object[0]);
              //    }
              //
              //    if (MathHelper.parseIntWithDefault(args[0], -1) != -1)
              //    {
              //        throw numberinvalidexception;
              //    }
              //
              //    throw new CommandNotFoundException();
              //}
              
              if (args.length > 0) {
                  try {
                      k = Integer.parseInt(args[0]);
                  }
                  catch (NumberFormatException numberFormatException) {
                      Map<String, ICommand> map = this.func_184899_a(server);
                      ICommand icommand = (ICommand)map.get(args[0]);
      
                      if (icommand != null)
                      {
                          throw new WrongUsageException(icommand.getCommandUsage(sender), new Object[0]);
                      }
      
                      throw new CommandNotFoundException();
                  }
                  
                  // Not optimal because the String needs to be parsed again
                  k = parseInt(args[0], 1, j + 1) - 1;
              }
              
              //...
          }
      }
      

      Note: This change is not optimal because the String needs to be parsed twice, but there is with the currently given methods probably no other way to solve this. Additionally with the current design the String needs to be parsed twice as well.

        Attachments

          Activity

            People

            • Assignee:
              FruBasilicum [Mojang] Agnes Larsson
              Reporter:
              marcono1234 [Helper] Marcono1234
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                CHK: