Overwrite a colliding command

Discussion in 'Spigot Plugin Help' started by Wilsoon, Feb 9, 2020.

  1. So the title may not make sense, but I'll come up with an example:
    I have two plugins with the same command: "/lift"
    Plugin A is named: Lift for example and
    Plugin B is named: Example1

    I want the /lift command from plugin B to be able to be ran with /lift instead of /Example1:lift
    and I want plugin A to be able to be ran only with /lift:lift.

    Is there a way to make this happen?
     
  2. You can setup aliases.
    In commands.yml
     
    #2 ExtremeSpirit, Feb 9, 2020
    Last edited: Feb 9, 2020
    • Funny Funny x 1
  3. You just basically repeated the same thing I said.
     
    • Agree Agree x 1
  4. I started this post before you edited your.
     
  5. Don't need to fight pls.
    So one of the plugins is coded by me, is there a way to do it from my plugin's code or plugin.yml so I don't have to set up for every single server I have? I know I could use another command name, but I find /lift the easiest way to interpret to any player that this is what my command's purpose is.
     
  6. You can try to do it like Essentials does - use PlayerCommandPreprocessEvent.
     
    • Like Like x 2
  7. drives_a_ford

    Moderator

    If you look at what Plugin#getCommand does, then perhaps you could get away with simply having one plugin (soft) depend on the other to make sure you know which one's loaded first. By the look of the method, the plugin that is initialized first gets the "regular" command and the one after gets the <pluginname>:<command> version.

    So if you in your example you'd want to have plugin A depend on plugin B so plugin B gets loaded first.

    It doesn't hurt to test at least.

    EDIT:
    bobcat had pretty much the same idea. The loadbefore option might be better because that better describes the situation. A doesn't really depend on B, B just needs to be loaded before A.
     
  8. Yes, but loadbefore might fail if the referenced plugin doesn't exist. I'm not sure.
     
    #10 Bobcat00, Feb 10, 2020
    Last edited: Feb 10, 2020
  9. Thanks. I'll try this out.
     
  10. The plugin.yml documentation says that the referenced plugin is optional, so this is safe to use. "Treated as if the listed plugin soft depends on the specifying plugin."