Overriding Commands

Discussion in 'Plugin Development' started by DiddiZ, Apr 17, 2011.

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

    DiddiZ

    Is there a way to override commands of an other plugins?
    Removing the commands from the other plugin.yml doesn't work, since it sets an executor.
     
  2. Offline

    nickguletskii

    What? I remove 3 commands from Essentials in my plugin by removing them from plugin.yml... And if I am correct, Essentials uses executors...
     
  3. Offline

    cjc343

    I haven't actually tried this, but you could try using onCommandPreprocess to check for the command, and cancel the event if the command is used. I'd assume that would work, but I've only used Preprocess for commands not registered in another plugin's yml...

    E:

    I could have sworn removing commands from yml when executors (as opposed to just onCommand) are used causes NPEs, but I may be wrong...
     
  4. Offline

    DiddiZ

    Don't know, I'm tryin to override the WorldEdit superpickaxe commands.
    Removed them from the plugin.yml and saw no effect.

    But to listen for the commands with the preprocessor, cancle them and call my ommands sound like a good idea by now.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  5. Offline

    Plague

    Yeah that's how my plugin disables them, but some people report it not working, not everyone though, so I do not know what to think.
     
  6. Offline

    DiddiZ

    Found a solution:
    Since WorldEdit doesn't care about a cancelled event, I set the command to "dummy":
    Code:
    public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
        if (!event.isCancelled()) {
            String msg = event.getMessage().toLowerCase();
            if (msg.equals("//") || msg.equals("/,")) {
                event.setMessage("dummy");
                event.setCancelled(true);
                getServer().dispatchCommand(event.getPlayer(), "spa");
            }
        }
    }
    EDIT: Thanks for the hint with the command preprocessor :D
     
  7. Offline

    Plague

    Oh, so THAT's why some plugins still do the command, they use preprocess too and do not care about cancelled :)
     
Thread Status:
Not open for further replies.

Share This Page