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().
- is duplicated by
-
SPIGOT-3980 ServerCommandEvent does not fire when another plugin uses the command
- Resolved