1.12.2 How can I add features to commands from other plugins?

Discussion in 'Spigot Plugin Development' started by xUltraGaming, Jan 29, 2020.

  1. I'm trying to add some custom features to the standard Factions plugin. I want to do this in the form of command arguments (eg. /f members <faction>)

    How could I add arguments like this to the command /factions, while still keeping all exisitng features of that command?

    Any help is appreciated, thanks :)
  2. If im correct, if the faction is open sourced, you'll be able to just create your own things within that plugin. iirc that is the only way to do it, unless you message the developer to see if they can add your features.
  3. You could also check for a PlayerCommandPreprocessEvent through your own plugin so you're not overriding the current factions command, then check for the command /f members <faction>, if so, cancel the event and replace your own text version using the Factions API to grab those specific values if they're stored already. Otherwise, you'd have to add the features to the Factions Plugin anyway. There are others way you could do it, but this is the first I thought of, and figured that it'd be the easiest way to implement something simple like this.
  4. completely forgot that playercommandpreprocessevent even existed, Rivzz's way would benefit you the most
  5. I thought this was possible somehow :unsure:

    Would the event look something like this? (Never used this event before)

    Code (Java):
        public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
            Player p = e.getPlayer();
            if (e.getMessage().startsWith("f members")) {
                // run code?
  6. Similar, try something like this
    Code (Java):
        public void playerCommand(PlayerCommandPreprocessEvent event)
            Player player = event.getPlayer();

            if (event.getMessage().equalsIgnoreCase("/f members"))
                // code
  7. Though it may depend on the factions plugin you use, is there not a "/f show <faction>" command that should do what you're asking?
    PlayerCommandPreprocessEvent should not be used to handle command logic. OP would probably need to modify the source code of the plugin to add the subcommand.
  8. I got it to work. Thanks!
    • Like Like x 1