Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-2666

ServerCommandEvent,PlayerCommandPreprocessEvent is not launched when Bukkit.dispatchCommand() is called

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • All

    • N/A

      When a plugin calls Bukkit.dispatchCommand(sender, commandText), it will look directly into the commandmap for the server and execute from there, as seen in this code from CraftServer:

      public boolean dispatchCommand(CommandSender sender, String commandLine)
        {
          Validate.notNull(sender, "Sender cannot be null");
          Validate.notNull(commandLine, "CommandLine cannot be null");
      
          ....
      
          if (this.commandMap.dispatch(sender, commandLine)) {
            return true;
          }
          sender.sendMessage(SpigotConfig.unknownCommandMessage);
          
          return false;
        }
      

      This can cause some unintended behavior in plugins calling commands they may be implemented in a customized way (generally intercepting PlayerCommandPreProcessEvent and ServerCommandEvent to process commands before they are actually sent, canceling them so that they don't get sent twice.)

      The easiest way to fix this would be to check to see who the sender is in the arguments for the method, and if it is the ConsoleSender, launch a ServerCommandEvent. If the event is canceled, then the lookup in the commandMap to dispatch should not be necessary.
      The same goes for if the sender passed in is a player - launch a PlayerCommandPreProcessEvent and if it isn't cancelled, do the commandmap lookup.

      Doing this will fix this corner-case bug that can cause unintended consequences when a plugin calls Bukkit.dispatchCommand().

            Unassigned Unassigned
            VoidWhisperer Void Whisperer
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: