Can I have two plugins execute the same command?

Discussion in 'Plugin Development' started by bmckalip, Dec 16, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    I've been working on a plugin, and part of it's functionality is to update a config file when a certain command is performed. However, I want this action to be a sort of "hidden" action. I use groupmanager for permissions. When a staff member types ./manpromote <name> <group>, I want it to execute groupmanager's command, but ALSO execute the command with the same exact name and arguments in the plugin I'm developing. It seems that currently, my plugin's command gets cancelled, and groupmanager executes it's command (assuming it has a higher priority). Is this functionality possible within bukkit?

  2. Offline


    @bmckalip A PluginCommand is bound to a single plugin and executor. You can't really override that behaviour. There are two options :
    1. Find a way to get a reference to the PluginCommand (bukkit's CommandMap should do it), and use PluginCommand#setExecutor to bind it to your own executor which would spread the command to your own plugin and the original plugin (example GroupManager). But that means having a dependency and having to rely on the scope of classes of said plugin to call back the original executor.
    2. Listen for PlayerCommandPreprocessEvent, which is not really designed to perform command logic and gives you no control over the output of the command from the original plugin, but should work. Also only triggers for players.
  3. Offline


    @Avygeil Thanks for the help. I'll give it a show with option #2 first, as it sounds easier and I don't need the output from the original plugin. If that fails, I'll attempt #1. Dependencies don't matter as it's a private plugin for my server only.

    Will report back soon. Thanks.

    @Avygeil Successfully implemented option #2. thanks again.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 29, 2016
Thread Status:
Not open for further replies.

Share This Page